I always get the error "sub mytest("hello world")" does not exist. See the code below. What am I doing wrong.
Dim myform as form
myform.left=100
Dim firstbutton as button
Dim secondbutton as button
firstbutton.Caption="OK"
secondbutton.Caption="Test"
secondbutton.top=75
firstbutton.parent=myform
secondbutton.parent=myform
`This line works fine
firstbutton.onclick=buttonclick
`This line is NOT working
secondbutton.onclick=mytest("hello world")
myform.showmodal
Sub buttonclick()
Print "Button clicked"
End sub
Sub mytest(x as string)
Print x
End sub
Sub ... End sub
Sub ... End sub
hi i`m new to fnx basic but i think i found out
why your program was having a problem
i think you were trying to
load "hello world"
in to x
as a string but
i looked at the help file and found out
a string is comprized of a couple of parts
the 1st part is
[Dim x as string] ?
before the declare form in the program
to declare [x] as a string
the 2nd part is
to give the string [x] a value
x=string$("a",1) ? <===example A
in example A
the a is the letter to be printed
and the 1 is how many times it is to be printed
[note each string only holds 1 letter as far as i can tell]
the 3rd part is
to print the contents of [x]
Print x
i fixed your program code by adding
Dim a as string ?
Dim b as string ? ?
Dim c as string ? ?
Dim d as string ? ?
Dim e as string ? ?
Dim f as string ?
Dim g as string ? ?
Dim h as string ? ?
Dim i as string ?
Dim j as string ? ?
before the declare of the form
to declare the strings
and changing the second button click
from ?secondbutton.onclick=mytest("hello world")
to ? ? ?secondbutton.onclick=mytest
and changing the sub menu from
Sub mytest(x as string)
? ? Print x ? ? ? ? ? ? ? ? ? ? ?
End sub ? ? ? ? ? ? ? ? ? ? ? ?
Back to top ? ? ? ? ? ? ? ? ?
to
Sub mytest()
a=string$("h",1)
b=string$("e",1)
c=string$("l",2) ? ?
d=string$("o",1)
e=string$(" ",1)
f=string$("w",1)
g=string$("o",1)
h=string$("r",1)
i=string$("l",1)
j=string$("d",1)
Print a+b+c+d+e+f+g+h+i+j
End sub
and it solved the error
here is a copy of the modified program code
Dim a as string ?
Dim b as string ? ?
Dim c as string ? ?
Dim d as string ? ?
Dim e as string ? ?
Dim f as string ?
Dim g as string ? ?
Dim h as string ? ?
Dim i as string ?
Dim j as string ? ?
Dim myform as form
myform.left=100
Dim firstbutton as button
Dim secondbutton as button
firstbutton.Caption="OK"
secondbutton.Caption="Test"
secondbutton.top=75
firstbutton.parent=myform
secondbutton.parent=myform
firstbutton.onclick=buttonclick ?
secondbutton.onclick=mytest
myform.showmodal
Sub buttonclick()
Print "Button clicked"
End sub
Sub mytest()
a=string$("h",1)
b=string$("e",1)
c=string$("l",2) ? ?
d=string$("o",1)
e=string$(" ",1)
f=string$("w",1)
g=string$("o",1)
h=string$("r",1)
i=string$("l",1)
j=string$("d",1)
Print a+b+c+d+e+f+g+h+i+j
End sub
sorry if i am not 100 percent acurate
dew to the fact i am fairly new to fnx basic
why your program was having a problem
i think you were trying to
load "hello world"
in to x
as a string but
i looked at the help file and found out
a string is comprized of a couple of parts
the 1st part is
[Dim x as string] ?
before the declare form in the program
to declare [x] as a string
the 2nd part is
to give the string [x] a value
x=string$("a",1) ? <===example A
in example A
the a is the letter to be printed
and the 1 is how many times it is to be printed
[note each string only holds 1 letter as far as i can tell]
the 3rd part is
to print the contents of [x]
Print x
i fixed your program code by adding
Dim a as string ?
Dim b as string ? ?
Dim c as string ? ?
Dim d as string ? ?
Dim e as string ? ?
Dim f as string ?
Dim g as string ? ?
Dim h as string ? ?
Dim i as string ?
Dim j as string ? ?
before the declare of the form
to declare the strings
and changing the second button click
from ?secondbutton.onclick=mytest("hello world")
to ? ? ?secondbutton.onclick=mytest
and changing the sub menu from
Sub mytest(x as string)
? ? Print x ? ? ? ? ? ? ? ? ? ? ?
End sub ? ? ? ? ? ? ? ? ? ? ? ?
Back to top ? ? ? ? ? ? ? ? ?
to
Sub mytest()
a=string$("h",1)
b=string$("e",1)
c=string$("l",2) ? ?
d=string$("o",1)
e=string$(" ",1)
f=string$("w",1)
g=string$("o",1)
h=string$("r",1)
i=string$("l",1)
j=string$("d",1)
Print a+b+c+d+e+f+g+h+i+j
End sub
and it solved the error
here is a copy of the modified program code
Dim a as string ?
Dim b as string ? ?
Dim c as string ? ?
Dim d as string ? ?
Dim e as string ? ?
Dim f as string ?
Dim g as string ? ?
Dim h as string ? ?
Dim i as string ?
Dim j as string ? ?
Dim myform as form
myform.left=100
Dim firstbutton as button
Dim secondbutton as button
firstbutton.Caption="OK"
secondbutton.Caption="Test"
secondbutton.top=75
firstbutton.parent=myform
secondbutton.parent=myform
firstbutton.onclick=buttonclick ?
secondbutton.onclick=mytest
myform.showmodal
Sub buttonclick()
Print "Button clicked"
End sub
Sub mytest()
a=string$("h",1)
b=string$("e",1)
c=string$("l",2) ? ?
d=string$("o",1)
e=string$(" ",1)
f=string$("w",1)
g=string$("o",1)
h=string$("r",1)
i=string$("l",1)
j=string$("d",1)
Print a+b+c+d+e+f+g+h+i+j
End sub
sorry if i am not 100 percent acurate
dew to the fact i am fairly new to fnx basic
Sub ... End sub
Thanks, I will try it, but I think it`s strange that I can`t use a string like "hello world" as a passing value to the sub witch holds the variable to work with in the Sub(routine)
Sub ... End sub
To robber:
In FNXBASIC at the assignment of event the name of the subroutine must be therefore only mentioned, WITHOUT BRACKETS (an without parameters...)
Also, you must so:
.
.
dim xx as string
xx="hello world"
secondbutton.onclick=mytest
.
.
and:
.
.
Sub mytest()
mytest2(xx)
End sub
Sub mytest2(x as string)
Print x
End sub
sincerelly
PaPi
In FNXBASIC at the assignment of event the name of the subroutine must be therefore only mentioned, WITHOUT BRACKETS (an without parameters...)
Also, you must so:
.
.
dim xx as string
xx="hello world"
secondbutton.onclick=mytest
.
.
and:
.
.
Sub mytest()
mytest2(xx)
End sub
Sub mytest2(x as string)
Print x
End sub
sincerelly
PaPi
Sub ... End sub
PaPi,
Thanks, it works. Now it`s all clear to me.
Thanks, it works. Now it`s all clear to me.