I feel like a fool...
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
I feel like a fool...
I'm an old time programmer. I started with the dBase world in the 1980s. I stopped programming on a daily basis in the mid 1990s (they pushed me into management). I'm now working as a mortgage broker and I'm trying to build what I think is a straightforward application. I want to input about 5 or 6 items and have the system determine the available mortgage products for the potential borrower. Pretty straightforward.
I've created a stack with the data entry items. I've used labels and text entry fields. For some reason I can't enter anything into the text entry fields. They just beep at me. Any ideas? Do I need to create a card for each one of them and use the "put it in" command inside an on MouseUp and end MouseUp commands? I've seen other code where the "ask" and "put it in" commands are used in code. Which type of coding is preferred? Which gives you better control? While I've seen some examples using the ask and put it in commands I can't get it to work in a card.
How can I format my data entry items? Two will be numeric - specifically dollars. I also need to run a test on them. The purchase price of the property must be greater than the amount being financed.
To create my tables do I just open up a card and and go from there? I guess the next question has to do with the insert statement. Same thing? I will need to update some values in the tables. What's the easiest way to do this?
The last thing that I want to do is send the potential borrower an email with the mortgage information that the system has chosen (I also want to cc: myself). What's the best and easiest way to do this?
It really is a simple idea. I can see the way that I would have done this in Foxpro, but I can't translate it to LiveCode. There have been a lot of changes in syntax and concept.
Thanks in advance,
Peter
I've created a stack with the data entry items. I've used labels and text entry fields. For some reason I can't enter anything into the text entry fields. They just beep at me. Any ideas? Do I need to create a card for each one of them and use the "put it in" command inside an on MouseUp and end MouseUp commands? I've seen other code where the "ask" and "put it in" commands are used in code. Which type of coding is preferred? Which gives you better control? While I've seen some examples using the ask and put it in commands I can't get it to work in a card.
How can I format my data entry items? Two will be numeric - specifically dollars. I also need to run a test on them. The purchase price of the property must be greater than the amount being financed.
To create my tables do I just open up a card and and go from there? I guess the next question has to do with the insert statement. Same thing? I will need to update some values in the tables. What's the easiest way to do this?
The last thing that I want to do is send the potential borrower an email with the mortgage information that the system has chosen (I also want to cc: myself). What's the best and easiest way to do this?
It really is a simple idea. I can see the way that I would have done this in Foxpro, but I can't translate it to LiveCode. There have been a lot of changes in syntax and concept.
Thanks in advance,
Peter
Re: I feel like a fool...
Wow it sounds as if you'd need to read a tutorial or two 
http://lessons.runrev.com
http://runrev.com/developers/lessons-an ... tutorials/
There is also the PDF, built into the IDE (see the help menu).
Until then, here some general hints:
Fields don't need any code at all to accept data input by the user. However the Browse (or "run") tool needs to be enabled. You can't enter text while in edit mode. When in a standalone the Browse tool is enabled. In the IDE you need to switch fore and back, to create stuff, and then test how they react to actions.
An "on" always needs an "end" otherwise it won't work. This is a very simple example of a script in a button:
To put stuff into a field by code (meaning not by hand) you can do something like this:
Note that "ask" has not directly to do with "put". Ask file pops up a dialog for the user to select a file, and the command then puts the path to that file into the 'it' variable. after that one can use the contents of 'it' to access the contents of the file. A simple example:
To find out if a number is bigger then another number, you use the greater then sign, for example:

http://lessons.runrev.com
http://runrev.com/developers/lessons-an ... tutorials/
There is also the PDF, built into the IDE (see the help menu).
Until then, here some general hints:
Fields don't need any code at all to accept data input by the user. However the Browse (or "run") tool needs to be enabled. You can't enter text while in edit mode. When in a standalone the Browse tool is enabled. In the IDE you need to switch fore and back, to create stuff, and then test how they react to actions.
An "on" always needs an "end" otherwise it won't work. This is a very simple example of a script in a button:
Code: Select all
on mouseUp
answer "hello world!"
end mouseUp
Code: Select all
on mouseUp
put "some text" into field "TheNameOfYourField"
end mouseUp
Code: Select all
on mouseUp
ask file "some text file"
if it is not empty then
put it into field "PathField"
put url ("file:" & it) into field "ContentsOfFile"
end if
end mouseUp
Code: Select all
on mouseUp
put 12 into bigNumber
if bigNumber > 4 then
put "it's a great one!" into msg
end if
end mouseUp
Various teststacks and stuff:
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
Re: I feel like a fool...
I've looked at the tutorials, but something just isn't clicking. If I have a label called Name and a field called m_name I just want someone to be able to type their name in it. I know that this can't be done in edit mode. When I check tools, browse tools is enabled. Do I have to make sure that some option is checked in the box that has the basic properties, etc. in it?
What do you mean by IDE?
I know that as soon as something works I'm going to have one of those "Duh" moments.
To create a database and tables, can I just open up the code box and create a script?
Thanks in advance,
What do you mean by IDE?
I know that as soon as something works I'm going to have one of those "Duh" moments.
To create a database and tables, can I just open up the code box and create a script?
Thanks in advance,
Re: I feel like a fool...
I've looked at the tutorials, but something just isn't clicking. If I have a label called Name and a field called m_name I just want someone to be able to type their name in it. I know that this can't be done in edit mode. When I check tools, browse tools is enabled. Do I have to make sure that some option is checked in the box that has the basic properties, etc. in it?
What do you mean by IDE?
I know that as soon as something works I'm going to have one of those "Duh" moments.
To create a database and tables, can I just open up the code box and create a script?
Thanks in advance,
What do you mean by IDE?
I know that as soon as something works I'm going to have one of those "Duh" moments.
To create a database and tables, can I just open up the code box and create a script?
Thanks in advance,
-
- Posts: 101
- Joined: Wed Dec 22, 2010 8:17 pm
Re: I feel like a fool...
Hi Peter, double-click on your field (pointer tool). You'll see a dialogue box with all the field's properties. Make sure 'lock text' isn't checked.
Then with tools-> browse tool you should be able to type in that field. If not there's something wrong
Steve
Then with tools-> browse tool you should be able to type in that field. If not there's something wrong

Steve
-
- Posts: 101
- Joined: Wed Dec 22, 2010 8:17 pm
Re: I feel like a fool...
Forgot to add it's got to be 'focusable' and no 'list behavior' either.
-
- Posts: 101
- Joined: Wed Dec 22, 2010 8:17 pm
Re: I feel like a fool...
But wait, there's more...
Hmmm, I really should be working.
Also autoHile checked, enabled checked.
IDE is integrated development environment -- meaning pre-build.
How you design your app is up to you, you can have a card (cd) for each table or make each table a field (fld) on 1 cd and hide them until you want them shown.
You can make each column a field and synchronise their scrolling & have them all in a table group (grp). Anything you want...
Pretty much any (if not all) objects can have their own scripts. You can reference them by name, number, even (if grouped) number within a group i.e. fld i of grp n.
You can create objects on the fly with scripts, change their attributes (i.e. set the lockText of fld i to false, set the enabled of fld "rowEntry-1" to false).
Clicking in a field or on a button (or any object) makes it the current object and mouseDown, mouseUp, mouseDoubleUp, mouseEnter (and more) messages are sent accordingly.
So you then can add a script to that object and utilise those messages i.e.
on mouseUp
--do something
end mouseUp
You can also write procedures, functions etc, put them higher up the message path -- like in the card or stack script and then call them from an object lower down
i.e. first you write a procedure called say, updateRow, you put it in the card script...
on updateRow thisCol, rownumber
--do a whole bunch of stuff
end updateRow
Now in a fld you can put...
on enterInField
--first you get values for thisCol & rownumber from wherever
updateRow thisCol, rownumber
end enterInField
This will call & run updateRow with the temporary variables provided when the user hits the enterKey in that fld.
or for a button....
on mouseUp
-- do same thing as above
end mouseUp
Livecode is great, really.
hope this is of some use
gotta work now.
Steve
Hmmm, I really should be working.
Also autoHile checked, enabled checked.
IDE is integrated development environment -- meaning pre-build.
How you design your app is up to you, you can have a card (cd) for each table or make each table a field (fld) on 1 cd and hide them until you want them shown.
You can make each column a field and synchronise their scrolling & have them all in a table group (grp). Anything you want...
Pretty much any (if not all) objects can have their own scripts. You can reference them by name, number, even (if grouped) number within a group i.e. fld i of grp n.
You can create objects on the fly with scripts, change their attributes (i.e. set the lockText of fld i to false, set the enabled of fld "rowEntry-1" to false).
Clicking in a field or on a button (or any object) makes it the current object and mouseDown, mouseUp, mouseDoubleUp, mouseEnter (and more) messages are sent accordingly.
So you then can add a script to that object and utilise those messages i.e.
on mouseUp
--do something
end mouseUp
You can also write procedures, functions etc, put them higher up the message path -- like in the card or stack script and then call them from an object lower down
i.e. first you write a procedure called say, updateRow, you put it in the card script...
on updateRow thisCol, rownumber
--do a whole bunch of stuff
end updateRow
Now in a fld you can put...
on enterInField
--first you get values for thisCol & rownumber from wherever
updateRow thisCol, rownumber
end enterInField
This will call & run updateRow with the temporary variables provided when the user hits the enterKey in that fld.
or for a button....
on mouseUp
-- do same thing as above
end mouseUp
Livecode is great, really.
hope this is of some use
gotta work now.
Steve
Re: I feel like a fool...
Thanks for all of the help. I've got my data entry screen working. There is one thing that I'd like to do that I seem to be stuck on. Two of the data entry fields are numeric. I've put some simple code in so that you can't enter alpha keys. I'd like to take this two steps further:
1) As someone is entering the information to automatically format the number as 999,999,999. Just as if I was using an old fashioned picture statement.
2) The first number entered must be greater than that second number. I need to create a test in my code. On the same edit script that I have the code to make sure that the second field must be numeric I created some code to test to this but it doesn't seem to be working. The code is
on mouseUp
if m_second > m_first then
answer "The first number must be greater than the second number"
end if
end mouseUp
The other issue that I seem to be having is with SQLite. It came with LiveCode so I really didn't do anything to get it to work. I was told it just would work. I've got a button with code in it to move all of the data entry information into a table that I've created. The command "revExecuteSQL gConID, tSQL" is giving me the error "execution error at line n/a () near "revdberr, invalid connection id". I've got code before this line that opens up the table: put revOpenDatabase("sqlite", "borrowers.db",,,,,,) into tConID and then I check to see if I can access the database.
Thanks in advance,
1) As someone is entering the information to automatically format the number as 999,999,999. Just as if I was using an old fashioned picture statement.
2) The first number entered must be greater than that second number. I need to create a test in my code. On the same edit script that I have the code to make sure that the second field must be numeric I created some code to test to this but it doesn't seem to be working. The code is
on mouseUp
if m_second > m_first then
answer "The first number must be greater than the second number"
end if
end mouseUp
The other issue that I seem to be having is with SQLite. It came with LiveCode so I really didn't do anything to get it to work. I was told it just would work. I've got a button with code in it to move all of the data entry information into a table that I've created. The command "revExecuteSQL gConID, tSQL" is giving me the error "execution error at line n/a () near "revdberr, invalid connection id". I've got code before this line that opens up the table: put revOpenDatabase("sqlite", "borrowers.db",,,,,,) into tConID and then I check to see if I can access the database.
Thanks in advance,
Re: I feel like a fool...
The trick to checking whether the first field is greater than the second is to know when to actually check. You would not want to compare until the entry was terminated.
So you would not use "keyDown" or "rawKeyDown", for example, but rather "closeField" Read up on these.
Anyway in the script of both fields:
I assume you can fix the alert to do what you want.
When you say format to 999,999,999, do you mean just put the commas in? Try
So you would not use "keyDown" or "rawKeyDown", for example, but rather "closeField" Read up on these.
Anyway in the script of both fields:
Code: Select all
on closefield
if fld 2 >= fld 1 then
beep 2
answer "Uh Oh"
end if
end closefield
When you say format to 999,999,999, do you mean just put the commas in? Try
Code: Select all
on closefield
put me into temp
put 0 into counter
repeat with y = the number of chars of temp down to 1
put char y of temp before accum
add 1 to counter
if counter mod 3 = 0 then put comma before char y of temp
end repeat
if char 1 of temp = comma then delete char 1 of temp
answer temp
end closefield
Re: I feel like a fool...
A few questions with the code that you gave me.
On the if statement where you say if fld 2 >= fld 1 then...
How do I pass the value or the name of the variables that were used in the data entry fields to this code? The variables are actually called purch_price and fin_amt (purch_price must be greater than fin_amt). I seem to be having this problem in other places in my code also. When I open up an edit script (to write code) the variable names and their values from the data entry screen are not recognized in the code that I am writing. I would assume that since the text entry fields have the variable values and the edit scripts are part (or called by) the text entry fields that the variables and their values would be considered, for lack of a better phrase global by the edit scripts (i.e. on mouseUp, on closefield, etc.).
The second question is hopefully easier. It has to do with putting the commas into the number (so the 12345 shows up as 12,345). The code seems to work except the line of code "answer temp" shows the value of the number with the commas in a dialog box instead of the data entry field that it was originally entered into.
Thanks,
On the if statement where you say if fld 2 >= fld 1 then...
How do I pass the value or the name of the variables that were used in the data entry fields to this code? The variables are actually called purch_price and fin_amt (purch_price must be greater than fin_amt). I seem to be having this problem in other places in my code also. When I open up an edit script (to write code) the variable names and their values from the data entry screen are not recognized in the code that I am writing. I would assume that since the text entry fields have the variable values and the edit scripts are part (or called by) the text entry fields that the variables and their values would be considered, for lack of a better phrase global by the edit scripts (i.e. on mouseUp, on closefield, etc.).
The second question is hopefully easier. It has to do with putting the commas into the number (so the 12345 shows up as 12,345). The code seems to work except the line of code "answer temp" shows the value of the number with the commas in a dialog box instead of the data entry field that it was originally entered into.
Thanks,
-
- Posts: 101
- Joined: Wed Dec 22, 2010 8:17 pm
Re: I feel like a fool...
Hi Peter,
"I would assume that since the text entry fields have the variable values and the edit scripts are part (or called by) the text entry fields that the variables and their values would be considered, for lack of a better phrase global by the edit scripts (i.e. on mouseUp, on closefield, etc.)."
Sorry, not the case at all, in fact you will get into trouble calling a fld a variable's name since LC will substitute the variable's value where you're wanting the fld's name (i.e. if the variable purch_price contains the characters 24.99 then LC will interpret any code refering to fld purch_price as refering to fld 24.99). If you must do this then you need fld "purch_price" so LC won't substitute the value.
You're after:
on closeField -- or mouseUp or returnInField or any message sent to fld "purch_price"
global purch_price
put me into purch_price
end closeField
or (actioned by any message):
put fld "purch_price" into purch_price
-- where purch_price is a defined global or about to be passed to a procedure
if you have do a procedure further up the message path, say, you've put one in the card the flds are on called doPricing, then you don't need to use a global var,
i.e.
on doPricing purch_price, fin_amt
--do your comparrison calcs
-- display, print, send to server or whatever
end doPricing
Then you can pass a local variable thus (no definition needed):
on closeField
put fld "purch_price" into purch_price
put fld "fin_amt" into fin_amt
doPricing purch_price, fin_amt
end closeField
Steve
"I would assume that since the text entry fields have the variable values and the edit scripts are part (or called by) the text entry fields that the variables and their values would be considered, for lack of a better phrase global by the edit scripts (i.e. on mouseUp, on closefield, etc.)."
Sorry, not the case at all, in fact you will get into trouble calling a fld a variable's name since LC will substitute the variable's value where you're wanting the fld's name (i.e. if the variable purch_price contains the characters 24.99 then LC will interpret any code refering to fld purch_price as refering to fld 24.99). If you must do this then you need fld "purch_price" so LC won't substitute the value.
You're after:
on closeField -- or mouseUp or returnInField or any message sent to fld "purch_price"
global purch_price
put me into purch_price
end closeField
or (actioned by any message):
put fld "purch_price" into purch_price
-- where purch_price is a defined global or about to be passed to a procedure
if you have do a procedure further up the message path, say, you've put one in the card the flds are on called doPricing, then you don't need to use a global var,
i.e.
on doPricing purch_price, fin_amt
--do your comparrison calcs
-- display, print, send to server or whatever
end doPricing
Then you can pass a local variable thus (no definition needed):
on closeField
put fld "purch_price" into purch_price
put fld "fin_amt" into fin_amt
doPricing purch_price, fin_amt
end closeField
Steve
Re: I feel like a fool...
I feel like I'm getting down to the nitty gritty and I want to thank everyone that's helped me so far. LiveCode is turning out to be a robust language with a lot of different ways to do things. This is where I'm at. Someone enters a number in a text entry field. There's code behind the field that 1) prevents someone from entering a non-numeric key (which works perfectly) and 2) the parses the number that was entered and puts commas into the number so that it can be more easily read. I'm having one issue with the second item. My code is as follows:
on returnInField
global field_name
put fld "m_fld_name" into field_name
put 0 into counter
repeat with y = the number of chars of field_name down to 1
put char y of field_name before accum
add 1 to counter
if counter mod 3 = 0 then put comma before char y of field_name
end repeat
if char 1 of field_name = comma then delete char 1 of field_name
answer field_name
end returnInField
My question is as follows: how do I get the new value field_name (formatted with the commas) into the text entry field that someone had originally typed in the number? The answer statement obviously doesn't do this.
My second question has to do with a function that someone helped me write. I'm comparing two numbers and number_1 must be greater than or equal to number_2
This is the way things look now:
on closeField
global no_1
global no_2
put fld "number_1" into no_1
put fld "number_2" into no_2
doPricing no_1, no_2
end closeField
Function doPricing no_1, no_2
if no_2 >= no_1 then
answe warning "No 1 must be greater than or equal to No 2"
end if
end doPricing
i'm getting an error on the line of code doPricing no_1, no_2. The error is Handler: can't find handler near doPricing char 1.
Thanks for helping me muddle my way through this,
Peter
on returnInField
global field_name
put fld "m_fld_name" into field_name
put 0 into counter
repeat with y = the number of chars of field_name down to 1
put char y of field_name before accum
add 1 to counter
if counter mod 3 = 0 then put comma before char y of field_name
end repeat
if char 1 of field_name = comma then delete char 1 of field_name
answer field_name
end returnInField
My question is as follows: how do I get the new value field_name (formatted with the commas) into the text entry field that someone had originally typed in the number? The answer statement obviously doesn't do this.
My second question has to do with a function that someone helped me write. I'm comparing two numbers and number_1 must be greater than or equal to number_2
This is the way things look now:
on closeField
global no_1
global no_2
put fld "number_1" into no_1
put fld "number_2" into no_2
doPricing no_1, no_2
end closeField
Function doPricing no_1, no_2
if no_2 >= no_1 then
answe warning "No 1 must be greater than or equal to No 2"
end if
end doPricing
i'm getting an error on the line of code doPricing no_1, no_2. The error is Handler: can't find handler near doPricing char 1.
Thanks for helping me muddle my way through this,
Peter
Re: I feel like a fool...
The single most basic command is "put". Read about this, and practice using it.
You are actually ahead of yourself. This may be a good thing. Your script is likely to work fine, but is needlessly involved. The globals are not required, nor are the custom functions. But it is very good that you are writing them, as paring down is very productive in terms of learning. You can do that later.
I left it to you to substitute your own field names. The way I gave examples, as with the "answer" command, was to show certain results. Substitute "put" here and there, and see what happens:
put field_name into fld "yourOutputField"
The whole of your function and handler call can be simply:
If fld "number_2" >= fld "number_1" then answer "Warning: No 1 must be greater than No 2"
You don't need much of anything else. Make sure you have source and result fields for you inputs and outputs. Trim your handler. Really, you are very close to sailing through this.
Craig Newman
You are actually ahead of yourself. This may be a good thing. Your script is likely to work fine, but is needlessly involved. The globals are not required, nor are the custom functions. But it is very good that you are writing them, as paring down is very productive in terms of learning. You can do that later.
I left it to you to substitute your own field names. The way I gave examples, as with the "answer" command, was to show certain results. Substitute "put" here and there, and see what happens:
put field_name into fld "yourOutputField"
The whole of your function and handler call can be simply:
If fld "number_2" >= fld "number_1" then answer "Warning: No 1 must be greater than No 2"
You don't need much of anything else. Make sure you have source and result fields for you inputs and outputs. Trim your handler. Really, you are very close to sailing through this.
Craig Newman
-
- Posts: 101
- Joined: Wed Dec 22, 2010 8:17 pm
Re: I feel like a fool...
Craig's right, just use 'put', works both ways...
put fld "A field's name" into someVariable
put someVariable into fld "A field's name"
I feel you really should change your fld names so they're not the var names to me it's confusing
(BTW I also think using the entry fld as the output fld would confuse me if I was a user, who might not be looking at the screen when it changed, but just my opinion).
As to your error msg, here's a couple of tips:
Use the msg box to help debug i.e. keep track of a variable & know that the script's got that far by inserting...
put "someVariable " & someVariable & return after msg ...(or any revealing code) at some key point in your script.
(Apologies if you're already using the msg box for this sort of thing).
Press ctrl S (apple s) before quitting a script--a save forces a compile--check the traffic light (top left of script screen). Goes yellow when you change a script, if it's green after a compile then no errors were found. If it goes red, then scroll to see if there's a red marker at the offending line. In this specific case (if your script is as presented) there'd be an error for sure at:
answe warning "No 1 must be greater than or equal to No 2"
(where answer's spelt wrong)
Note if you just quit & re-run then LC is very likely not to be so generous when telling you where an error is... you often get rather useless messages (useless because the actual problem may have nothing to do with the handler mentioned).
Steve
put fld "A field's name" into someVariable
put someVariable into fld "A field's name"
I feel you really should change your fld names so they're not the var names to me it's confusing

(BTW I also think using the entry fld as the output fld would confuse me if I was a user, who might not be looking at the screen when it changed, but just my opinion).
As to your error msg, here's a couple of tips:
Use the msg box to help debug i.e. keep track of a variable & know that the script's got that far by inserting...
put "someVariable " & someVariable & return after msg ...(or any revealing code) at some key point in your script.
(Apologies if you're already using the msg box for this sort of thing).
Press ctrl S (apple s) before quitting a script--a save forces a compile--check the traffic light (top left of script screen). Goes yellow when you change a script, if it's green after a compile then no errors were found. If it goes red, then scroll to see if there's a red marker at the offending line. In this specific case (if your script is as presented) there'd be an error for sure at:
answe warning "No 1 must be greater than or equal to No 2"
(where answer's spelt wrong)
Note if you just quit & re-run then LC is very likely not to be so generous when telling you where an error is... you often get rather useless messages (useless because the actual problem may have nothing to do with the handler mentioned).
Steve
Re: I feel like a fool...
I'm starting to understand the power of the put command. There must be a lot of options that go with it (i.e. put fld m_no1 into number1). Do you know a where I can find all of the options that work with the put command? The dictionary doesn't really tell you a lot or give good examples.
I'm also realizing that there are several different ways to start code running (i.e. on keyDown, on returnInField). Is there somewhere that I can find a complete list of these, explanations as to how they are used and examples? Right now I'm using returnInField when I add commas to the numeric fields and the test that no_1 is greater than no_2. As long as I press the enter key after I type in a number the code executes and commas are inserted. The returnInField command then keeps me in the text entry field that I was in. It does not automatically advance to the next data entry field. Logically it should do this. In addition, if I press the tab key instead of the enter key the code does not execute. This leads me to believe that returnInField only executes when the enter (return) key is pressed and does not automatically forward me to the next field. That's why I'm looking for a complete list of commands that will cause code to execute.
Thanks,
Peter
I'm also realizing that there are several different ways to start code running (i.e. on keyDown, on returnInField). Is there somewhere that I can find a complete list of these, explanations as to how they are used and examples? Right now I'm using returnInField when I add commas to the numeric fields and the test that no_1 is greater than no_2. As long as I press the enter key after I type in a number the code executes and commas are inserted. The returnInField command then keeps me in the text entry field that I was in. It does not automatically advance to the next data entry field. Logically it should do this. In addition, if I press the tab key instead of the enter key the code does not execute. This leads me to believe that returnInField only executes when the enter (return) key is pressed and does not automatically forward me to the next field. That's why I'm looking for a complete list of commands that will cause code to execute.
Thanks,
Peter