PDA

View Full Version : A simple database and printing??



patrick6
03-10-2004, 05:03 PM
I was wandering if there is a way to save a simple letter and have someone enter their info on one screen then print that info on the letter. I.E - %FirstName%, %Address%, etc.
Then is it possible to save this info into some sort of simple database?

I tried downloading the simple print example zip file but it will not compile for me in 5.0

I would even be glad to pay someone if they could do this, or get me going on doing this, fairly quickly.

Patrick

Agent Jones
03-11-2004, 09:16 AM
Why don't you save it into the Registry?

You can always read it...

patrick6
03-11-2004, 07:54 PM
I think that would be the best way but I am not sure how to go about this....
Can someone show me how to do this?
I would be glad to pay someone if they could show me in detail...

I called IndigoRose and they said someone there could tell me if this could be done. I was told to post it on this board and they would answer.

Patrick

Corey
03-11-2004, 08:12 PM
Hi, I'm not sure about saving letters but these are great actions for saving and retrieving small amounts of data too:

http://www.indigorose.com/webhelp/ams50/Program_Reference/Actions/Application.SaveValue.htm

http://www.indigorose.com/webhelp/ams50/Program_Reference/Actions/Application.LoadValue.htm

Perhaps if you could explain what you are trying to do in detail, I could offer something more.

Corey Milner
Creative Director, Indigo Rose Software (http://www.indigorose.com)

patrick6
03-12-2004, 04:11 AM
What I am trying to accomplish iis the ability to input a small amount of data on the main screen. i.e -name, address, etc.
Then print that data on a saved letter so it looks like you wrote the letter to somneone perosnally.

I would also like to be able to save that custom fields (name, address etc) to retrieve it later.
A simple database connecton would work fine for that I think.

From what I have seen, it should be able to be done in autoplay but I am just not sure how to go about it.

The sample print program zip file you have posted on the forum is pretty close to what I am looking to do (or at least a step in that direction) but I could not get it to comple in 5.0 for me...

I guess all in all it would take:
a simple database or way to save info
The ability to print a 1 page simple letter with 4 or so custom fields.

Corey
03-12-2004, 04:46 AM
Hi. Your best bet is to create an HTML page on the fly and print that. As for storing your data there are a variety of choices, a good place to start would be to check out the actions listed above.

Corey Milner
Creative Director, Indigo Rose Software (http://www.indigorose.com)

Worm
03-12-2004, 06:52 AM
Here's a small sample that replaces elements in an HTML file, and shows the letter. I didn't do anything with the database side of this that you're wanting, but it should give you a good start.

kpsmith
03-12-2004, 08:00 AM
I'd store the data in a lua file...

Basically create a .txt file that has the actions to create an AMS table.
Load that file at program start
Then modify the AMS table as you add/change the data
At program close, save the data back out to the lua table

The letter itself I'd build dynamically in HTML. Simply build the HTML file with variables for the objects that you want to change.

When you go to print you write that out to a temp location replacing the variables with the current values and excecute a wweb object print action.

kpsmith
03-12-2004, 09:08 AM
Couldn't resist...

Here's worms app modified to load in a table from a text file at start and to save new names/address back to the text file and table every time you Show the letter.

Click the up arrow and select a name to populate the name and address from the database (table)

Worm
03-12-2004, 09:12 AM
Neat Concept KP.

Deep Thinker, you are!

Worm
03-12-2004, 09:47 AM
This will format your Address with the carriage return and line feeds.

Replace the last bit of code in the button with this:


strHTML = TextFile.ReadToString("Autoplay\\docs\\template.html")
strHTML = String.Replace(strHTML, "~NAME~", strName, false);
strAddress = String.Replace(strAddress,"\r\n","<BR>",false);
strHTML = String.Replace(strHTML, "~ADDRESS~", strAddress, false);
strHTML = String.Replace(strHTML, "~AK_EDIT~", String.Replace(_SourceFolder .."\\autoplay\\docs\\","\\","/",false), false);
TextFile.WriteFromString(_TempFolder .. "\\letter.html", strHTML, false);
Page.Jump("page2");

kpsmith
03-12-2004, 11:21 AM
Worm,

I figured you'd catch that ... I was being lazy.

Of course just that code doesn't fix the database actions...

Here's the whole project again with both Worms carriage return fix and a database substitution to handle the carriage returns.

I also commented all the code as it is getting a bit messy to follow

Worm
03-12-2004, 11:26 AM
Geez, I didn't even see that the database wasn't grabbing the line breaks. I never put more than one line of text in the multi line text box when I built the example, so I never thought about the address not showing properly until I looked at it with your DB add-on. Sorry, had I seen it, I'd have added it to your code too.

And how dare you say that our code is messy. :D

Worm
03-12-2004, 11:39 AM
BTW Patrick6, if you do end up using the little RTF Text Editor, please be sure to read the license.txt or visit AKwebtools (http://www.akwebtools.com) and read throught their licence agreement.

kpsmith
03-12-2004, 11:51 AM
Just my part is messsy...

In fact on line 16 of the button code I goofed... it should be:

CurrentCount = ListBox.GetCount("Name ListBox");

Worm
03-12-2004, 11:55 AM
I'm thinking mine not so "clean" either. It took me 3 tries to get that last String.Replace in the right spot. :)

patrick6
03-12-2004, 08:40 PM
I downloaded the sample program. That is pretty much what I am trying to do.

I want to have 10 letters total. You can pick which letter you want to print from a drop down box.

I need two screens / tabs.
One to enter your info. (Once entered this won't change.)
Company name, address, phone, webpage, etc.

Second screen to enter customer info. This will be saved to databse. Could be up to 100-200 people eventaully.

Is there any way to print a certain letter for everyone in the database / table?

You guys are way too nice and helpful. Without a doubt. Autoplay is the best money I have ever spent on a software program.
Thank you.

As I menitoned before... If someone can help me finish this I will be glad to make it well worth their while.
I can do a complete mockup of what I want the interface to look like. I just need someone to add the code to complete the actions.

Patrick

TJ_Tigger
03-12-2004, 09:54 PM
Originally posted by patrick6

Is there any way to print a certain letter for everyone in the database / table?
Patrick

There are a couple of ways you could do this. First you would have to write the files, either html or rtf to a temp directory. Have a letter template read the letter into a string and replace the name as is appropriate for each person in the database. Then you could build a table with all of these files and print them one by one.



for index, dbname in NamesTable do
-- Read your template into a string
sLetter = TextFile.ReadToString(_SourceFolder.."\\AutoPlay\\Docs\\templateletter1.htm);
--replace the instance of _NAME with the name from your database as captured above
sLetter = String.Replace(sLetter, "_NAME", dbname, true);
--write a new html file into a temporary directory
TextFile.WriteFromString(_TempFolder.."\\dbtempfolder\\letter"..index..".html", sLetter, false);
end

--using File.Find add all the letters to a table for printing
tLetters = File.Find(_TempFolder.."\\dbtempfolder\\", "*.html", false, true, nil);

for tlindex, letter in tLetters do
File.Print(letter);
end


AMS 5 is very quick about running through the code so I don't know if the File.Print action will "jam" the printerport on the PC or not. But it might be worth a try. An alternative to creating multiple files would be to create one large file with page breaks between the letters. Then you could print one document rather than multiple little ones.

HTH
Tigg

Corey
03-12-2004, 10:05 PM
CurrentDonut = BoxOnTable.GetCrueller("Consume");

Corey Milner
Creative Director, Indigo Rose Software (http://www.indigorose.com)

Worm
03-12-2004, 10:07 PM
Corey, I truly appreciate your sense of humor. You make me laugh!

TJ_Tigger
03-12-2004, 10:15 PM
for sip,wine in glass do
Table.Remove(sip, glass, top)
if glass == empty then
Application.Exit()
end
Application.Sleep(6000)
end

Bruce
03-13-2004, 01:08 AM
for sip,wine in glass do
Table.Remove(sip, glass, top)
if glass == empty then
Application.Exit()
end
Application.Sleep(6000)
end

LOL!!

Corey
03-13-2004, 01:57 AM
I fought hard for Application.Yawn(); during beta but Brett wouldn't budge on that one. Maybe for 6.0...

Corey Milner
Creative Director, Indigo Rose Software (http://www.indigorose.com)

patrick6
03-13-2004, 10:33 AM
I followed the code (best I coudl) Most of it makes sense to me.

How do you make the letter already on the editor when it opens?
i.e.- where you put "This could be the body of the letter, yada, yada, yada"

Patrick

Worm
03-13-2004, 10:48 AM
What I did was typed it in the editor, putting the substitute fields where I wanted them (i.e. ~ADDRESS~).

Once I had it the way I wanted it, I clicked on the 3rd button from the left in the bottom row which shows the HTML. I copied that and pasted it into the template.html

patrick6
03-13-2004, 11:28 AM
I guess I was thinking you were openeing the editor like you would open a word document from vb / C, etc.
I have seen that done and then use word automation for the fields you want to customize...

I have all of the add ins for AP 5.0
Should I try to use the SQLite for the data (customers names, etc)?
If not how can I add columns to the data in the example you made?
I could not figure out how to add to it? Does that make sense?

Are you the same guy who sells the pop up for AP 5.0?
I am just about through with the shell of the program I want to create. I will post it when I am done.

Thanks again,

Patrick

patrick6
03-13-2004, 12:55 PM
I am just about to be able to do what I was trying to (I think so anyway...)

The only problem I am running into is I can't edit the "template" file that goes with the WYSIWYG editor.
It tells me the file exists do I want to replace it. I click yes but when I go to re-open it it is the same template I started with....

What am I doing wrong?

kpsmith
03-13-2004, 04:51 PM
Personally I'd stick with the table to store the data. I've had more than 5000 records stored in a table no problem. Of course you could certainly use the SQLite plugin as well

Storing data in columns like a spreadsheet is pretty easy

Name | Address | Letter

each row would look something like this...

Table[1] = {Name="John", Address="101 howard drive", Letter="blah blah blah"}

As far as the changing the template... are you modifying it within the project or just trying to set it up to work with your project?

the template file can be edited in any HTML editor.

In fact you could do away with the template and just use a text file write command to dynamically creat the template. You could even then store all the different letters in another table and select them from a list box as in the example.

Let me know when you get stuck... I'm sure Worm or I woudl be happy to look through it as long as we can find the time ;)

patrick6
03-14-2004, 07:06 AM
I like the idea of dynamically creating the info.
Since I am grasping at straws at this point I might had better wait on that until a later version when and if I get a grasp on this...

Attached is a shell of what I am after. I worked on several versions yesterday trying different things.

I am still having trouble updating any of the HTML files. I can edit them but when I go to save, I can't just "save", I have to "save as" if I choose the same name as the existing file it asks me if I want to replace it. I click yes but it does not update... I reopen to the same ol templates.

Patrick

patrick6
03-14-2004, 04:24 PM
I am now able to edit the template and insert fields where I need them.
Now my trouble is getting additional fields into the database / table.


I tend to make things harder than they have to be.

I guess nobody needs the money, but I would sure be glad to pay someone if they could build this project for me so I could go back and see how it is all done....

Name a price... I'm begging.

;)

Worm
03-14-2004, 04:50 PM
Open the file NameTable.lua that is in the same folder as the autorun.exe for the project with Notepad. You will see some lines like this:


NameTable = {};
NameTable[1] = {Name=[[Joe Smith]], Address=[[11 Wonderland way<BR>New York, NY]]};
NameTable[2] = {Name=[[IndigoRose]], Address=[[#1 Autoplay Avenue<BR>Freezing Cold, Canada]]};
NameTable[3] = {Name=[[Worm<BR>Writer of fine code]], Address=[[La La Land<BR>Wish I was there, CA]]};
NameTable[4] = {Name=[[Return Fixer]], Address=[[1 Fixing Lane<BR>Repair Us, OH 11136]]};
NameTable[5] = {Name=[[1]], Address=[[La La Land<BR>Wish I was there, CA]]};
NameTable[6] = {Name=[[2]], Address=[[La La Land<BR>Wish I was there, CA]]};
NameTable[7] = {Name=[[3]], Address=[[La La Land<BR>Wish I was there, CA]]};


The Key to adding fields would be to add them to each line in the table, here I'm adding the City field.


NameTable = {};
NameTable[1] = {Name=[[Joe Smith]], Address=[[11 Wonderland way]], City=[[New York]]};
NameTable[2] = {Name=[[IndigoRose]], Address=[[#1 Autoplay Avenue]], City=[[Freezing Cold]]};
NameTable[3] = {Name=[[Worm<BR>Writer of fine code]], Address=[[La La Land]], City=[[Los Angelos]]};
NameTable[4] = {Name=[[Return Fixer]], Address=[[1 Fixing Lane]], City=[[Cleveland]]};
NameTable[5] = {Name=[[1]], Address=[[La La Land]], City=[[Los Angelos]]};
NameTable[6] = {Name=[[2]], Address=[[La La Land]], City=[[Hereville]]};
NameTable[7] = {Name=[[3]], Address=[[La La Land]], City=[[Thereville]]};


Instead of using the address as the Itemdata, you'll want to use the position of the record in the table. That way you can jump to that record when its selected, and pull the correct field information.

Here's the bigger question. Are you under a deadline and need to get this done? Or, are you wanting to learn AMS, and simply want an example or your excited about the product? If its the second question, then keep plugging away and asking questions, I'll help as much as I can, as I'm sure KP will. Its truly a great way to learn.

If you are under the gun, let me know.

patrick6
03-14-2004, 05:27 PM
Thank you for taking time to help.
It needs to be done soon but I have until next Monday.

I edited the lua file with the code example you provided . (Thank you !)
No problems.

I see only a couple of problems to deal with I think....

1. Once someone has a person pulled up from the table, then they need to select one of the 10 letters from the drop down box.
How can I make the selected letter the one that is populated with the info? I know I have to make 10 diffenent templates so can I just name them template 1, template 2, etc?



2. Three lines up from the bottom of this code is giving me problems. Can I not use the word "state"?

For some reason I get an error when I use this:
--Get Selcted index
SelectedNameIndex = ListBox.GetSelected("Name ListBox");
--Get Name for that index
SelectedName = ListBox.GetItemText("Name ListBox", SelectedNameIndex[1]);
--Get Address for that index...Address is stored in Data for the index
SelectedAddress = ListBox.GetItemData("Name ListBox", SelectedNameIndex[1]);
SelectedCity = ListBox.GetItemText("Name ListBox", SelectedNameIndex[1]);
--Hide the listbox
ListBox.SetVisible("Name ListBox", false);
--Set the Name in the Name Field
Input.SetText("txtName", SelectedName);
--Set the Address in the Address Field
Input.SetText("txtAddress", SelectedAddress);
--Set the City in the city Field
Input.SetText("txtCity", SelectedCity);
--Set the State in the State Field
Input.SetText("txtState", SelectedState);
--Set the zip in the zip Field
Input.SetText("txtZip", SelectedZip);

Worm
03-14-2004, 05:43 PM
Yes, create a template for each letter as you said. Set the ItemData for each letter to the name of the template file. Once they choose a letter, grab the ItemData of the selected item and use that file.

As for the SelectedState, it appears that you aren't setting its value as you have say, SelectedCity. Unless you're setting its value somewhere else, I suspect you simply missed that line of code.

BTW the same will apply for SelectedZip

patrick6
03-14-2004, 06:00 PM
I did just miss that code. Got it now..

Now it puts info from the name field into the City, State and Zip
Boxes?

Worm
03-14-2004, 06:17 PM
I'm better off if you post code, or the app. If you don't want to post it publicly, then feel free to email me.

brad at warmuskerken dot com