Welcome to the idea2app forum!

Moderators: LCNeil, heatherlaine, kevinmiller, elanorb

LCNeil
Livecode Staff Member
Livecode Staff Member
Posts: 1223
Joined: Wed Oct 03, 2012 4:07 pm

Welcome to the idea2app forum!

Post by LCNeil » Thu Oct 03, 2013 11:00 am

We look forward to answering any of your idea2app questions!

john50
Posts: 9
Joined: Sun Nov 10, 2013 4:50 am

Saving data on "Desktop" ?

Post by john50 » Thu Dec 05, 2013 4:16 am

I am building a Window's App and need to expand the following code to save Input data from a "Windows standalone application".

I am trying to create a folder on the "Desktop" from a standalone windows application and then add text files in this folder so I don't clutter up the desktop with a ton of text files.

1. How do I create a folder on the "Desktop" or in "MyDocuments" to add the text files
2. What is the path coding for accessing this folder once created?
3.There is a lot of data to save --- is there a loop that can be run to save and place input data.
4. Is there a better way of doing this that is still simple and easy to do? I have limited knowledge of coding.

This is the code I currently have: which creates a text file on the "Desktop" saves the data to this file on close of the card and then retrieves the data from "Desktop" file and puts back into the standalone application on opening card.

on openCard

open file specialFolderPath("desktop") & "/test1.txt" for read -- opens the text file created on Desktop
read from file specialFolderPath("desktop") & "/test1.txt" until EOF -- reads the contents of the file
put it into fld "test1" -- puts the contents of that file into the text field
close file specialFolderPath("desktop") & "/test1.txt" -- closes the file

end openCard

on closeCard
open file specialFolderPath("desktop") & "/test1.txt" for write -- creates a file for LiveCode to write to
put field "test1" into test1 -- places the text from the field into a local variable
write test1 to file specialFolderPath("desktop") & "/test1.txt" -- writes the text placed in the local variable into the open text file
close file specialFolderPath("desktop") & "/test1.txt" -- closes/saves the text file containing the text form the field/local variable into a text file on the desktop
end closeCard

Thanks Bill (New to idea2app) and LiveCode

LCNeil
Livecode Staff Member
Livecode Staff Member
Posts: 1223
Joined: Wed Oct 03, 2012 4:07 pm

Re: Welcome to the idea2app forum!

Post by LCNeil » Thu Dec 05, 2013 6:40 pm

Hi Bill,

Thank you for your question and I will try my best to help.

1) You can use the "Create Folder" command to create a folder in a specified directory. If you wish to create a folder on the Desktop you would use

Code: Select all

create folder (specialFolderPath ("Desktop")&"/name of folder here")
and for the documents directory it would be

Code: Select all

create folder (specialFolderPath ("Documents")&"/name of folder here")
2) It would be the same as what you created so either of the above paths. An example of opening a text file from a directory on the desktop and placing its contents in a field would be-

Code: Select all

put url ("file:"& specialFolderPath ("Desktop") &"/test/test.txt") into field "name"
3) Yes it should be possible to loop through all of the data in your application. If you are looking to retrieve all of the data from fields in your card you could use something like-

Code: Select all

repeat with x = 1 to the number of fields in card 1
      put field x & cr after tTemp
   end repeat
This will return separate the content of each field in the text file.

4) What you are doing seems fine and it is really whatever method is most comfortable for you that counts :). The other method of writing to a text file is by directly writing to the file e.g.

Code: Select all

put specialFolderPath ("desktop") & "/Data.txt" into tLocation
   
   put field "name" && cr into tTemp
   put field "email" && cr after tTemp
   put field "phone" after tTemp
   
   put tTemp into url("file:" & tLocation)
I hope the above helps

Kind Regards

Neil Roger
--
RunRev Support Team ~ http://www.runrev.com
LiveCode – Realize fast, compile-free coding


john50
Posts: 9
Joined: Sun Nov 10, 2013 4:50 am

Thanks for the information - Which leads to another question

Post by john50 » Fri Dec 06, 2013 11:17 pm

Neil
I was able to setup and use the code you supplied -- Thank You

With the following code which builds a file on my desktop with various fields listed one after the other (I like it) -- but I was not able to reverse the process. I like this process better than the one I am currently using so would like to pursue it.

How would you sturcture the code to replace the text into the proper fields in the app.

Code: Select all

put specialFolderPath ("desktop") & "/Data.txt" into tLocation
   
   put field "name" && cr into tTemp
   put field "email" && cr after tTemp
   put field "phone" after tTemp
   
   put tTemp into url("file:" & tLocation)

Thanks
Bill

LCNeil
Livecode Staff Member
Livecode Staff Member
Posts: 1223
Joined: Wed Oct 03, 2012 4:07 pm

Re: Welcome to the idea2app forum!

Post by LCNeil » Mon Dec 09, 2013 11:24 am

Hi Bill,

In order to retrieve the data from a created text file you have to define the URL to the file along with the file type. As this is a text file we can use the “file:” file type.
e.g.

Code: Select all

put url ("file:"& specialFolderPath ("desktop") & "/Data.txt") into tData
This would place the text file into a variable (tData) which we can then extract the required data from.

As we have return separated line data in this text file, it will simply be the case of placing the line of text from the variable into the relevant field. E.g. if you know line 4 of your data.txt file contains the value to a field called “name” then you would use the following to extract this data and place it into that field-

Code: Select all

put line 4 of tData into field “name”
I hope this is of some assistance.

Kind Regards

Neil Roger
--
RunRev Support Team ~ http://www.runrev.com
LiveCode – Realize fast, compile-free coding

--

john50
Posts: 9
Joined: Sun Nov 10, 2013 4:50 am

Thank You

Post by john50 » Tue Dec 10, 2013 6:58 am

These little code comments have helped a lot.
Thanks
Bill

john50
Posts: 9
Joined: Sun Nov 10, 2013 4:50 am

Saving Check Box or Option Button

Post by john50 » Tue Dec 10, 2013 10:22 pm

I am looking for information on how to save a check box (selection) or an option button (selection) in a windows standalone application. Is this possible?

LCNeil
Livecode Staff Member
Livecode Staff Member
Posts: 1223
Joined: Wed Oct 03, 2012 4:07 pm

Re: Welcome to the idea2app forum!

Post by LCNeil » Wed Dec 11, 2013 2:36 pm

Hi John,

I'm glad I've been of some assistance so far.

If you want to read save the state of a checkbox or option button in a standalone, you will have to use a similar method to reading out the data from a field.

Instead of reading the contents of file object, you will want to retrieve the property of the check/option button that relates to its selected state. In the case of these buttons it is the "hilite" state you want.

When a selection/check is made in these buttons, the "hilite" property will be true. When they are not, then the "hilite" is false. You can then save this data to a text file and set the properties of these buttons when your stack opens.

An example of retrieving this property from a radio button called radio is-

Code: Select all

get the hilite of button "radio"
you can then set this again via something like

Code: Select all

set the hilite of button "radio to line 6 of tData
(asuming that the property is saved to line 6 of that variable)

Kind Regards

Neil Roger
--
RunRev Support Team ~ http://www.runrev.com
LiveCode – Realize fast, compile-free coding


john50
Posts: 9
Joined: Sun Nov 10, 2013 4:50 am

Having problems with the code

Post by john50 » Thu Dec 12, 2013 12:32 am

Code: Select all

on openCard 
   put specialFolderPath ("desktop") & "/Data.txt" into tLocation
   put url ("file:"& tLocation) into tData
   put line 1 of tData into field "name"
   put line 2 of tData into field "email"
   put line 3 of tData into field "phone"   
   set the label of button "comboBox" to line 4 of tData --------------------- works ok.   
   set the hilite of button "v1check1" to line 5 of tData ------------------------ Error at this point -- error is (boolean value not present).
   set the hilite of button "v1check2" to line 6 of tData  -------------------------- No Error with this code if there is only one check box and last in tData file line, works in standalone - but cannot add another check box to code.   
end openCard

on closeCard
   put specialFolderPath ("desktop") & "/Data.txt" into tLocation
   put field "name" && cr into tTemp
   put field "email" && cr after tTemp
   put field "phone" && cr after tTemp  
   put the label  of button "combobox" && cr after tTemp ------------------------ This code puts (contents of combo selection) in to tData file on  desktop -- No problem 
   put the hilite of button "v1check1" && cr after tTemp  --------------------- This code puts the hilite of (true or false) into the tData file in line 5 on desktop
   put the hilite of button "v1check2" after tTemp  ------------------------ This code puts the hilite of (true or false) into the tData file on desktop -- No problem if put last in line in tData file with no other check box code.
   put tTemp into url("file:" & tLocation)
end closeCard
Neil

I am having trouble with the last code you supplied me. This is how I set it up in my test card, Tried several variations with get command as well but no luck.
1. I am getting a boolean error for the check box when trying to replace the hilite with the saved data.

When check box is checked receiving error:
Card “Test Card”: execution error at line n/a (Object: value is not a Boolean (true or false)) near “true”

When check box is unchecked receiving error:
Card “Test Card”: execution error at line n/a (Object: value is not a Boolean (true or false)) near “false”


2. Using the code you gave me for the above I was able to get the Combo Box to work using "label" to describe the combo information. Included in code above.

LCNeil
Livecode Staff Member
Livecode Staff Member
Posts: 1223
Joined: Wed Oct 03, 2012 4:07 pm

Re: Welcome to the idea2app forum!

Post by LCNeil » Thu Dec 12, 2013 11:12 am

Hi John,

Yes, the label command is what is used for a combo box. The information I provided previously was for radio buttons (option buttons) and check boxes.

The not boolean error should not occur when you are setting the hilite of a checkbox. This could indicate that there is possibly a discrepancy with the button or text file.

Please find attached, a working example of setting the hilite of a check button from a text file. You will need to extract this to your desktop.

If you still experience this issue after looking at my example, please post a sample stack and your text file and I will happily look into it further.

Kind Regards

Neil Roger
--
RunRev Support Team ~ http://www.runrev.com
LiveCode – Realize fast, compile-free coding

--
Attachments
John Test.zip
(1.4 KiB) Downloaded 199 times

john50
Posts: 9
Joined: Sun Nov 10, 2013 4:50 am

Saving Check Box "hilite" {true | false}

Post by john50 » Thu Dec 12, 2013 11:40 pm

Neil

Attached is my live code test for the check box save.

I am still getting an error with the true or false not being a boolean value

Thanks
Bill
Attachments
Data Read_Write Test.7z
(1.71 KiB) Downloaded 219 times

LCNeil
Livecode Staff Member
Livecode Staff Member
Posts: 1223
Joined: Wed Oct 03, 2012 4:07 pm

Re: Welcome to the idea2app forum!

Post by LCNeil » Fri Dec 13, 2013 10:59 am

Hi John,

Thank you for supplying your stack.

I was able to debug this and came across what was causing the issue (This has caught me out once or twice before)

On your closeCard handler, you are inserting a space (&&) after each checkbox hilite entry. This space is read back into LiveCode from the text file and results in "true " <----Notice the space.

As this space is present, it will cause your script to break.

You can resolve this issue by replacing double ampersand with a single ampersand (&). The resulting code is-

Code: Select all

on closeCard
   
   put specialFolderPath ("desktop") & "/Data.txt" into tLocation
   
   put field "name" && cr into tTemp -- Line1
   put field "email" && cr after tTemp -- Line 2
   put field "phone" && cr after tTemp -- Line 3
   put the label  of button "combobox" & cr after tTemp -- Line 4
   put the hilite of button "check1" & cr after tTemp  -- Line 5 
   Put the hilite of button "check2" & cr after tTemp  -- Line 6
   
   
   
   put tTemp into url("file:" & tLocation)
   
   show btn "returnButton"
   
end closeCard
Kind Regards

Neil Roger
--
RunRev Support Team ~ http://www.runrev.com
LiveCode – Realize fast, compile-free coding

--

john50
Posts: 9
Joined: Sun Nov 10, 2013 4:50 am

Thank You!

Post by john50 » Sun Dec 15, 2013 7:18 am

Not something I would have ever found.

john50
Posts: 9
Joined: Sun Nov 10, 2013 4:50 am

Setting up App to send information by email

Post by john50 » Tue Dec 17, 2013 4:32 am

I am looking for the code to send the pdf file that the app creates to our office by email.

The application builds a .pdf file on the "desktop" and I would like to attach it to an email and have it sent (by using the clients email service, Microsoft Office, Thunderbird etc) to our office email address.

Thanks
Bill (John50)

LCNeil
Livecode Staff Member
Livecode Staff Member
Posts: 1223
Joined: Wed Oct 03, 2012 4:07 pm

Re: Welcome to the idea2app forum!

Post by LCNeil » Wed Dec 18, 2013 12:05 pm

Hi Bill,

The following LiveCode lessons should be able to explain the basics on how to call an email client from within LiveCode-

http://lessons.runrev.com/s/lessons/m/4 ... tml-e-mail

http://lessons.runrev.com/s/lessons/m/4 ... -an-e-mail

The above lessons use command line calls to create the emails in the Thunderbird client. If you wish to compose an email in Outlook, then you will need to research the various command line option that are available to you.

The following Google Search should give you so leads on where to start-

https://www.google.co.uk/search?q=outlo ... mmand+line

Kind Regards

Neil Roger
--
RunRev Support Team ~ http://www.runrev.com
LiveCode – Realize fast, compile-free coding


Post Reply

Return to “idea2app and Coding School”