PLUA programming tutorial


here is the commented version of the PLUA program I posted yesterday
ptitle(“simple calc”)
will display the label of the current form as simple calc
pmoveto(10,55)
move to position 10(x),55(y)
text1=pfield(1,7,20)
store the Id of the text filed in variable text1,the text filed will have be of one line having 7 columns and a maximum of 20 characters
print(“+”)
print “+”
pmoveto(105,55)
move to position 105(x),55(y)
text2=pfield(1,7,20)
store the Id of the text filed in variable text2,the text filed will have be of one line having 7 columns and a maximum of 20 characters
print(“=”)
print “=”
pmoveto(195,55)
move to position 195(x),55(y)
text3=pfield(1,7,20,””,1,1)
store the Id of the text filed in variable text3,the text filed will have be of one line having 7 columns and a maximum of 20 characters,initialize the field with an empty string(“”) and make the filed non editable(1) and not underlined(1)
pmoveto(50,100)
move to position 50(x),100(y)
addButton=pbutton(“add”)
store the ID of the button with label add in a variable called addButton
clrButton=pbutton(“clear”)
store the ID of the button with label clear in a variable called clrButton
exitButton=pbutton(“exit”)
store the ID of the button with label exit in a variable called exitButton
psetfocus(text1)
set focus to textfield1 so that when program runs the filed is already selected
while 1 do
go into an infinite loop until an event occurs I.E. a button is clicked
e,id = pevent()
function pevent() waits for an event and returns the ID and the type of event it encountered which are then stored in variables’ e’ and ‘id’
if e == ctlSelect and id == addButton then
compare to see if the event is the add button is clicked if it is then add the contents of text filed 1 and 2 and display the result in text filed 3
psettext(text3,(pgettext(text1)+pgettext(text2)))
psettext is used to put in text in textfield 3,pgettext returns the contents of the selected object in this case contents of text filed 1 and 2
end
end if loop
if e == ctlSelect and id == exitButton then
compare to see if the event is the exit button is clicked if it is then pop up a confirmation box to determine of user really wants to quit
if(pconfirm(“do you really want to quit?”)) then
the Pconfirm() function pop’s up a dialog with a question and yes and no buttons if yes is selected then 1 is returned else 0 is returned
break
break exits the while loop thus ending the program
end
end of if condition for pop up
end
end of if condition
if e == ctlSelect and id == clrButton then
compare to see if the event is the clear button is clicked if it is then clear all three text fields
psettext(text1,” “)
psettext(text2,” “)
psettext(text3,” “)
psettext sets the content of the ID supplied with a given string in this case with an empty string.
end
end of while
end
end of main function

My first Palm app developed using PLUA


I went ahead and tried creating my own application for the palm using PLUA , Once I went through the documentation it took about 10 minutes to code the application.

its a simple program to add 2 numbers and display the result. it can be extended to do something useful like calculating body mass index, or mortgage payments etc.

heres is the complete listing

ptitle(“simple calc”)
pmoveto(10,55)
text1=pfield(1,7,20)
print(“+”)
pmoveto(105,55)
text2=pfield(1,7,20)
print(“=”)
pmoveto(195,55)
text3=pfield(1,7,20,””,1,1)
pmoveto(50,100)
addButton=pbutton(“add”)
clrButton=pbutton(“clear”)
exitButton=pbutton(“exit”)
psetfocus(text1)
while 1 do
e,id = pevent()
if e == ctlSelect and id == addButton then
psettext(text3,(pgettext(text1)+pgettext(text2)))
end
if e == ctlSelect and id == exitButton then
if(pconfirm(“do you really want to quit?”)) then
break
end
end
if e == ctlSelect and id == clrButton then
psettext(text1,” “)
psettext(text2,” “)
psettext(text3,” “)
end
end

will put in commented version and screenshots on my next post.