PDA

View Full Version : help with save as



Dangerscott2020
06-27-2007, 02:42 AM
Hello im quite new to AMS. Im in progress of making a simple program and iv got to the point where I would like to make a "Save as" button. So far iv been experimenting with a blank project. I have created a button which creates a table, I then created a button that displays the first value (255) from the table in a dilog box (just to make sure it works). Then iv got a "save as" button and a "open" button. ANYWAY! When i preview the program i insert the table, click the "save as" and call it something like test and the file test appers! yay but when i open it back up again the table value has changed from 255 to the location i saved the file to? eg C:\test.dat

Make table button:
myArray = {255,0,255};

Get first value button:
Dialog.Message("First number", myArray[1], MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);

Save As button:
myArray = Dialog.FileBrowse(false, "Save As", "C:\\", "All Files (*.*)|*.*|", "", "dat", false, true);
TextFile.WriteFromTable(myArray[1], myArray, false);

open button:
myArray = Dialog.FileBrowse(true, "Locate File", "c:\\", "All Files (*.*)|*.*|", "", "", false, true);

Thanks

Dangerscott2020
06-27-2007, 10:27 AM
Nobody wants to help me? :huh

Lorne
06-27-2007, 10:40 AM
You're putting the value returned from Dialog.FileBrowse into myArray, which doesn't make sense.

Desrat
06-27-2007, 10:56 AM
The file browse also returns a table as its result so you have to specify you want the first entry in that table.

Either try this code or have a look at the example I've posted..

--Make Table
myArray = {255,0,255};

--Get first value button:
Value = myArray[1];
Dialog.Message("First number", Value, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);

--Save As button:
SaveAs = Dialog.FileBrowse(false, "SaveAs", "C:\\", "All Files (*.*)|*.*|", "", "dat", false, true);
TextFile.WriteFromString(SaveAs[1], Value, false);

--open button:
Open = Dialog.FileBrowse(true, "Locate File", "c:\\", "All Files (*.*)|*.*|", "", "", false, true);
File.Open(Open[1], "", SW_SHOWNORMAL);

just remember when you declare a variable then it is declared "GLOBALLY" so dont use the same variable names over and over :)

Dangerscott2020
06-29-2007, 09:19 AM
Thankyou for your replys. Sorry for my stupidity. Iv got it so save what i want now! the only thing is im a little unsure how im going to do the next thing i want to do!

If i was to save a file with the text: all = {1,2,3};
Would it be possible to open and insert the table into some script?

RizlaUK
06-30-2007, 06:48 AM
Would it be possible to open and insert the table into some script?

you would need to format your text file like, eg:

1
2
3

with each new item on a new line, and use Text.ReadToTable

Dangerscott2020
06-30-2007, 12:54 PM
Cool thanks! I tried that before but didnt work now it does though!
ok iv got one more question I hope! Is it possible to set text in a paragraph but no over write existing text instead start a new line?

example:

first set.text command "hello"

will diplay:
hello

second set.text command "how are you?"

will display:
hello
how are you?

yosik
06-30-2007, 04:29 PM
Simple enough:
yourText = Paragraph.GetText("yourParagraph");
newText = "/r/nwhatever you want to add";
--new text begining on a new line
yourText = yourText..newText;
Paragraph.SetText("yourParagraph", yourText);

Good luck
Yossi

Dangerscott2020
07-01-2007, 04:28 AM
ah i c thanks
ok got another one for you chaps! Sorry!
Is it possible to declare a variable to a element in a table?

example: all = {1,2,3};

all[1] = hello

i tried this but didnt seem to work

RizlaUK
07-01-2007, 08:01 AM
nearly right, but in this case you would need to declare a empty table and add the values, the way you have it "1" would already be assigned to "all[1]" and "2" to all[2] and so forth, also, you have to wrap all text in double quotes ("")

try it like this
all = {}
all[1] = "hello"
all[2] = "good bye"
all[3] = "hello again"

you can of course assign anything you like to a already existing table element, the way you have it should work as its just changing the table element contents, but if you dident quote the text it would not work

hope that helps

Dangerscott2020
07-05-2007, 01:38 AM
chears mate, got it to work.
got some more thinking to do now!:cool