Option Menu ot Combo box

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Subas
Posts: 32
Joined: Mon May 20, 2013 5:15 am

Option Menu ot Combo box

Post by Subas » Sun Jun 23, 2013 9:01 am

Dear Friends.

Requires some help on Option Menu or Combo Box. When a user select the drop down list to select the following option:

1) Mr
2) MRS
3) SIR

I want the system to move the user selection to a text file. I tried using a field in the text file but it gives me an error. I know I am not address the Option Menu or Combo Box as it does not behave like a field. I managed to get the selection right by placing the items "Mr" , "MRS" and "SIR" into the selection but not able to move the select option to a text file.

Please help. Thank you

Regards
Subas

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Option Menu ot Combo box

Post by Klaus » Sun Jun 23, 2013 11:23 am

Hi Subas,

let me see, you want to save the menuitem that your user selected from a combo box
or option menu to a text file on the users hard disk. Is that correct?

Here you want to access -> the LABEL of btn "your option menu or combobox here..."

WHEN do you want to do this?
Right after the user has selected an item from the menu, or after that with a button click?

Any idea WHERE you want to save it?

Please also check these stacks to get accustomed to the Livecode basics:
http://www.hyperactivesw.com/revscriptc ... ences.html


Best

Klaus

Subas
Posts: 32
Joined: Mon May 20, 2013 5:15 am

Re: Option Menu ot Combo box

Post by Subas » Mon Jun 24, 2013 2:42 am

hi Klaus.

I am sorry maybe I was not clear in my email. after writing the previous post I manage to get it working but I know this is not the way to go about it but it seems to work. I am very very new to programming and have never program before so I am trying to do my the best.

below are my codes. basically I took the selection made by the user "pItemsName and put into a field called "vComplete" on the stack. Now the field "vComplete" I hide the field from the user by ticking the Hide option on the properties. From here I move the content of "vComplete" into a text file on the users folder.

Code: Select all

on menuPick pItemName
   switch pItemName
      case "Mr"
         put pItemName into field "vComplete"
      case "SIR"
         put pItemName into field "vComplete"
       break
   end switch
end menuPick
 
it seems to work but I don't think it the best way to do it. if you can explain in a much better way will be greate.

Also thanks for the Livecode basics url. I went thru some of it as I will be using some of it like dates/time.

I also notice there was an error on 1 of the example on the "chunkexpressions" may be you could inform the author. the error is on the topic "Character Chunk". The author say the following:

put "try doing that" into myVariable
get char 7 of myVariable

The answer shown on that example is an "a" but shouldn't it be a "I"

Best Reagrds
Subas

Brahmanathaswami
Posts: 52
Joined: Mon Jun 24, 2013 4:10 am
Contact:

Re: Option Menu ot Combo box

Post by Brahmanathaswami » Mon Jun 24, 2013 4:37 am

Namaste, Subas:

Since you are new, then we may need to discuss your "functional specification" a bit more... that is fancy term for "the plan for your app, how it works without a lot of technical details." Then it will be easier to help you.

1) What are you trying to accomplish by saving the text file on the user's hard drive?
2) Typically to write to a file you would ask the user to supply you with a file name. Do you want to do that?
3) Assuming you don't need to do this then you will need to supply a path to the file. Will this app be running on different machines with different users?
4) if this is for one user (yourself for example or a staff person doing data entry) and the path doesn't change and you may need to write to that file from other contexts, then a good way is to save it to a custom property.

e.g go to the card properties and choose custom properties and add a property and put in there something like:

/users/subas/documents/input-data.txt

# or whatever you want to name it.
# I don't know what system you are one, but the Tile
name the custom property with something memorable and us a "u" in front of it to help remind you that this is a custom property later on so you might name it

uSaveInputDataPath

You don't need to use Switch to save the input... this will work:

Code: Select all

on menuPick pItemName
       put the uSaveInputDataPath into tLocalDataFile
       put pItemName after url ("file:" & tLocalDataFile)  # "after" assumes you may want to keep adding to that file later
end menuPick
If you need to write to the user's hard drive, but you don't know who it is. then you need to query the $HOME variable when the application starts.

try this in the message box "put $HOME" and you will see what you get...

in the card script.. you can do something like this:

Code: Select all

on preopencard
    put $HOME into tUserSavedData  #  you get something like "/users/subas" or something different on Windows.
    put "documents/input-data.txt" after tUserSavedData  # now you have a full path: /users/subas/documents/input-data.txt     
    set the uSaveInputDataPath of this card to tUserSavedData  # you could use a global variable, but I prefer custom props for things like this.
end preopenCard
So, when you app runs, the path is set up as soon as the card opens.. the the above script can write to it

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Option Menu ot Combo box

Post by Simon » Mon Jun 24, 2013 6:10 am

Hi Brahmanathaswami,
Good to see you here in the forums.
Saw your presentation at the BALUG meeting.
Hope you'll be here often.

Simon

EDIT:
Oh, and Subas,
What Klaus and Brahmanathaswami says is good stuff. :)
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Subas
Posts: 32
Joined: Mon May 20, 2013 5:15 am

Re: Option Menu ot Combo box

Post by Subas » Mon Jun 24, 2013 1:57 pm

Namaste Brahmanathaswami.

Nice to meet you on this forum. Basically to answer your questions below are the following.

1. Basically my project is to capture my home aqurium water parameters like temp, nitrate level, ph level etc. Every Friday morNing I carry out these testing and wrie them down on a pieces oF paper and I keep loosing them. I don't want to have a database created on my home pc as the capturing of data is only less the 15 fields with some option menu and date time.

2. What I plan to do is to capture these parameters on m iPad or my Samsung windows tablet and once capture send these parameter via email to my mailbox. In my mailbox I have created the filter to filter incomming email. If he body of the email starts with aquirium then move that email to the specific folder.

3. As of now thanks to those who helped me I am 1/4 way thru the coding. I just have now to test the date/time function and also testing of moving these parameter fields to the message body of the default email on my iPad or tablet and sending it.

4. As for the location of the text file it can be on any default folder for the iPad to tablet.

5. My the text file is important is it will be like my backup incase he iPad or tablet suddenly fails I will still have the last data keyed into the text file andi can then read that into all the necessary field and resend the email. Once the email is sent the text file will be deleted from the system. Every time I start the application the system will create a new blank file.

Also thank you for your advice on the menu or combo box issued I had. I will try it out today. Thanks again

Best regards

Subas

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Option Menu ot Combo box

Post by Simon » Mon Jun 24, 2013 5:49 pm

Great project Subas,
There are many posts in the forums about something mostly called a Preference file. This can be a text file that is read and written to. It's used to hold onto a users preferences (e.g. background color = blue, text size = 14...) which are implemented on preOpenCard/Stack. Exactly the sort of thing you need.

The next step is emailing it. Again there are many posts here about that but also look in the Release Notes under the Help menu, they've practically written it for you.

Check out these:
http://lessons.runrev.com/
http://www.hyperactivesw.com/revscriptc ... ences.html

Simon
(ps I just got a 1200 gal pond and am getting into water quality long before I add any fish) :)
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Brahmanathaswami
Posts: 52
Joined: Mon Jun 24, 2013 4:10 am
Contact:

Re: Option Menu ot Combo box

Post by Brahmanathaswami » Mon Jun 24, 2013 9:20 pm

Aum Subas:

OK... I think we may want pursue your overall specification first. The pros always say "the client does not know what he wants." So, today they accept this and build into the software development contract the "discovery phase."' I think that is where we are... coding comes later.

1) Agreed: you probably don't need a database: options are:
-- tab, comma or pipe ( | ) delimited data. one record per line, fixed fields so that you have fifteen aquarium data in each line even if some are empty: write this to a text file... later you can open in Excel, Number, Open office as a spreadsheet... whatever.
-- save the above to a field/card, then save the stack... call it your "report card" with the date and data on each line and a header.. you can simply create the headerline and set the tab stops in a native field and set both vertical and horizontal scrolling or use one of the more fancy plugins for a grid object... (can be more complicated than you need to get what you want...) then you can view your aggregated data on your tablet. Just have your app copy the data out of the field and email to you, since back up is what you want.
-- Save the data as an array in a custom property.This has some advantages that you can then, by script, view the data dynamically as a report, or examine date ranges etc... (assumes some competency in arrays, but well worth the learning curve... see below.)

2) Do you need to see your aggregated data? Or do you want to send one reading to the email each time.
3) If you save the aggregated data as tab delimited text, even if you have a years worth, it would only be 365 lines and you could email this to your PC.


Methods for use a custom property and the "target" function to make a single scrip to the work for *all* your input buttons.

Disclaimer: untested... might need a few tweaks.



# assume you are smart about this and name each of the input items with the exact name you would want to use for the field or column header of your data, If you need the GUI label be different then give the name as the correct name for the data field and use the label for what you want the user to see..

this one script(s) will do everything for you

Code: Select all

  

# this goes into each button:

on menupick pItem
   PostInput(the short name of the target, pItem)
end menupick
   
# in your card or stack script

on PostInput tField, pItem
    put pItem into MyAquariumData[tField] # add your data to the array

   # you get value  like this  myAquariumData["ph"]  might = 7; myAquariumData["temperature"] 80F (needs to be warm for Discus!)
  
 set the  uAquarumData  of this stack to MyAquariumData   # Set a custom prop with your data as container to save it in.

# Or you could pass the data to another card/field, or a text file here...
   save this stack   
# assumes you build your engine into a splash screen 
# and call this "main stack" separately... very important
# because you cannot save data to the executable itself.

end PostInput

# later you can query the data like this

 put the uAquariumData of this stack into MyAquariumData

 # get the temperature; assume the input button was named "Temperature"

 put MyAquariumData["temperature"]

OK so with your aggregated data saved to an array in a custom property... you can then do anything you want to display it, ship it off to your PC, analyze it whatever.

It takes a bit of time for a newbie to "grok" LC arrays... especially if you are new to programming. But you can save umpteen lines of future code by learning to save all kind of things into a single variable.

Brahmanathaswami
Posts: 52
Joined: Mon Jun 24, 2013 4:10 am
Contact:

Re: Option Menu ot Combo box

Post by Brahmanathaswami » Mon Jun 24, 2013 10:44 pm

Small tweak to my script: I always mess up on this, when passing params to a handler, you don't use parentheses, if you want to process the parameters directly. Just separate them from the call with a space:

PostInput the short name of the target, pItem

Use parentheses for functions or if you want to get all the params as a single string (which may have a use case for some contexts)

the "params" in the dictionary for details. (The dictionary is your friend)

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Option Menu ot Combo box

Post by Klaus » Tue Jun 25, 2013 12:10 pm

Hi friends,

here a little trick that makes debugging a bit easier! :-)

Put everything into a variable first, so you can check its value in the debugger, which is not possible otherwise:
...
put the short name of the target into tTargetShortName
## NOW you can see whats in the target in the debugger!
PostInput tTargetShortName, pItem
...

Best

Klaus

Post Reply