Page 1 of 1
Dipol Calc
Posted: Wed May 07, 2008 7:33 pm
by aurelW
Hi all...
Here is my first example written in FNX Basic.
code:
`/dipol length/by aurelW
dim cap$ as string
dim freq as integer
dim length as single
`dim btn(1) as button
cap$="Dipol by Aurel"
`/open window form
OBJECT WIN as FORM
caption=cap$
Object but as button
left=10
top=10
caption="Calc"
onclick=clicked
End Object
END OBJECT
`/domodal or show.window
WIN.ShowModal
SUB clicked()
`frequency(MHz)
freq=62
`dipol length (m)
length=142.5/freq
Showmessage "Dipol length: "+str$(length)+" m"
END SUB
Dipol Calc
Posted: Thu May 08, 2008 6:23 am
by Fazer
Nice program!
It would be perfect if you add some editfields, so that the user can input his data ( frequency etc.), and also some labels, which describe the input values!
Dipol Calc
Posted: Thu May 08, 2008 11:32 am
by aurelW
Thanks Fazer!
I dont know command for editbox and for labels
it is same like for button ?
Dipol Calc
Posted: Thu May 08, 2008 1:15 pm
by aurelW
I`m think that is better now.
code:
`dipol length/by aurelW
dim cap$ as string
dim freq as integer
dim length as single
dim freq$ as string
`---------------------------------
cap$="Dipol by Aurel"
`----------------------------------
`open window form
OBJECT WIN as FORM
caption=cap$
Object but as Button
left=200
top=10
caption="Calc"
onclick=clicked
End Object
Object Label1 As Label
Caption = "Enter frequency"
left = 20
top=10
End Object
Object Edit1 AS Edit
Text = "MHz"
Left = 20
Top = 40
End Object
END OBJECT
`show window
WIN.ShowModal
SUB clicked()
getstring()
freq=VAL(freq$)
`dipol length (m)
length=142.5/freq
Showmessage "Dipol length: "+str$(length)+" m"
END SUB
SUB getstring()
freq$= Edit1.text
END SUB
Dipol Calc
Posted: Thu May 08, 2008 1:20 pm
by aurelW
I mess up Edit1,refresh:
`dipol length/by aurelW
dim cap$ as string
dim freq as integer
dim length as single
dim freq$ as string
`---------------------------------
cap$="Dipol by Aurel"
`----------------------------------
`open window form
OBJECT WIN as FORM
caption=cap$
Object but as Button
left=200
top=10
caption="Calc"
onclick=clicked
End Object
Object Label1 As Label
Caption = "Enter frequency ( MHz )"
left = 20
top=10
End Object
Object Edit1 AS Edit
Text = ""
Left = 20
Top = 40
End Object
END OBJECT
`show window
WIN.ShowModal
SUB clicked()
getstring()
freq=VAL(freq$)
`dipol length (m)
length=142.5/freq
Showmessage "Dipol length: "+str$(length)+" m"
END SUB
SUB getstring()
freq$= Edit1.text
END SUB
Dipol Calc
Posted: Thu May 08, 2008 1:38 pm
by Fazer
[quote author=aurelW link=1210188785/0#2 date=1210246349]Thanks Fazer!
I dont know command for editbox and for labels
it is same like for button ?
[/quote]
I have made some additions:
`---------------------------------------------
` begin of code
`/dipol length/by aurelW
dim cap$ as string
dim freq as double
dim length as double
`dim btn(1) as button
cap$="Dipol by Aurel"
`/open window form
OBJECT WIN as FORM
caption=cap$
Object lblfreq as Label
left=10 : top=13: width= 40
caption="frequency [MHz]:"
End Object
Object editFreq as edit
left=95 : top=10 : width= 40
End Object
Object lbllen as Label
left=10 : top=33: width= 40
caption="length [1/ freq]:"
End Object
Object editlen as edit
left=95 : top=30 : width= 40
End Object
Object but as button
left=10
top=85
caption="Calc"
onclick=clicked
End Object
END OBJECT
`/domodal or show.window
WIN.ShowModal
SUB clicked()
`frequency(MHz)
freq= val( editFreq.Text)
`dipol length (m)
length= val(editlen.Text)/freq
Showmessage "Dipol length: "+str$(length)+" m"
END SUB
`end of code
`-------------------------------------------------------------
Now this is a rough (quick and dirty) version. You can make now a little bit of fine tuning, if you have understood my additions.
Good luck !
Fazer
Dipol Calc
Posted: Thu May 08, 2008 1:41 pm
by Fazer
you were faster than me !
Nice! You have now a better structure in your code !
Dipol Calc
Posted: Thu May 08, 2008 1:57 pm
by aurelW
Thanks again.
I love structured becose is much easier to understand
for beginers.
Dipol Calc
Posted: Thu May 08, 2008 1:59 pm
by aurelW
By the way...FNX basic code look
like Media basic code.
Dipol Calc
Posted: Thu May 08, 2008 2:32 pm
by aurelW
Final version of example with check error is:
code:
`dipol length/by aurelW
dim cap$ as string
dim freq as integer
dim length as single
dim freq$ as string
`---------------------------------
cap$="Dipol by Aurel"
`----------------------------------
`open window form
OBJECT WIN as FORM
caption=cap$
Object but as Button
left=200
top=10
caption="Calc"
onclick=clicked
End Object
Object Label1 As Label
Caption = "Enter frequency ( MHz )"
left = 20
top=10
End Object
Object Edit1 AS Edit
Text = ""
Left = 20
Top = 40
End Object
END OBJECT
`show window
WIN.ShowModal
SUB clicked()
getstring()
freq=VAL(freq$)
If freq=0 then Showmessage "Division by Zero!"
If freq=0 then exit sub
`dipol length (m)
length=142.5/freq
Showmessage "Dipol length: "+str$(length)+" m"
END SUB
SUB getstring()
freq$= Edit1.text
If freq$="" then Showmessage "You enter nothig!Try again!"
END SUB