problems with variables in subs
problems with variables in subs
I have a problem with variables in subs.
I dont know whats wrong here.
The following program should write a binary number in a label by clicking on button "1" or "2"
to get a binary number e.g. 1001101.
But it doesn`t work correctly!
Why ?
`=======================
`Begin Code
DIM myvalue as string
Myvalue = " "
object myform as form
Caption = "myprogram "
Width = 400
Height = 225
`Color = &h4F9D00
object label1 as label
Caption = "label1"
Left = 57
Top = 24
Width = 112
Transparent = 1
end object
object button1 as button
Caption = "0"
Left = 56
Top = 100
Width = 49
TabOrder = 4
onclick=add0
end object
object button2 as button
Caption = "1"
Left = 136
Top = 100
Width = 49
TabOrder = 4
onclick=add1
end object
end object
myform.showmodal
`===========================
`[Subprograms]
`===========================
Sub add0(myvalue as string)
myvalue = myvalue + "0"
label1.Caption = myvalue
end sub
Sub add1(myvalue as string)
myvalue = myvalue + "1"
label1.Caption = myvalue
end sub
`End Code
`==========================
I dont know whats wrong here.
The following program should write a binary number in a label by clicking on button "1" or "2"
to get a binary number e.g. 1001101.
But it doesn`t work correctly!
Why ?
`=======================
`Begin Code
DIM myvalue as string
Myvalue = " "
object myform as form
Caption = "myprogram "
Width = 400
Height = 225
`Color = &h4F9D00
object label1 as label
Caption = "label1"
Left = 57
Top = 24
Width = 112
Transparent = 1
end object
object button1 as button
Caption = "0"
Left = 56
Top = 100
Width = 49
TabOrder = 4
onclick=add0
end object
object button2 as button
Caption = "1"
Left = 136
Top = 100
Width = 49
TabOrder = 4
onclick=add1
end object
end object
myform.showmodal
`===========================
`[Subprograms]
`===========================
Sub add0(myvalue as string)
myvalue = myvalue + "0"
label1.Caption = myvalue
end sub
Sub add1(myvalue as string)
myvalue = myvalue + "1"
label1.Caption = myvalue
end sub
`End Code
`==========================
problems with variables in subs
The Myvalue is a "global" variable, not a "parameter" of subroutine, because you can`t put a variable simultaneously global and local variable.
So the subroutines correctly:
Sub add0()
Myvalue=Myvalue+"0"
label1.Caption=Myvalue
end sub
Sub add1()
Myvalue=Myvalue+"1"
label1.Caption=Myvalue
end sub
Note:
Myvalue isn`t binary number, rather a string which "face" of a binary number, you know, aren`t you?
PaPi
So the subroutines correctly:
Sub add0()
Myvalue=Myvalue+"0"
label1.Caption=Myvalue
end sub
Sub add1()
Myvalue=Myvalue+"1"
label1.Caption=Myvalue
end sub
Note:
Myvalue isn`t binary number, rather a string which "face" of a binary number, you know, aren`t you?
PaPi
problems with variables in subs
[quote author=PaPi link=1210613239/0#1 date=1210619536]The Myvalue is a "global" variable, not a "parameter" of subroutine, because you can`t ?put a variable simultaneously global and local variable.
So the subroutines correctly:
Sub add0()
Myvalue=Myvalue+"0"
label1.Caption=Myvalue
end sub
Sub add1() ?
Myvalue=Myvalue+"1"
label1.Caption=Myvalue
end sub
Note:
Myvalue isn`t binary number, rather a string which "face" of a binary number, you know, aren`t you?
PaPi[/quote]
Thats all right, I`ve also tried the subroutines above before I explained my problem here in my post.
But this gives an error message:
"error:41 line: 39 object myvalue not declared".
The subroutines doesnt accept the global variable "myvalue"!
But if the variables are declared in the subroutines, they will be local and I will never get my string, which represents a binary number (it could also be a text "abaabab").
But I think there is something wrong with FNXBasic !?
So the subroutines correctly:
Sub add0()
Myvalue=Myvalue+"0"
label1.Caption=Myvalue
end sub
Sub add1() ?
Myvalue=Myvalue+"1"
label1.Caption=Myvalue
end sub
Note:
Myvalue isn`t binary number, rather a string which "face" of a binary number, you know, aren`t you?
PaPi[/quote]
Thats all right, I`ve also tried the subroutines above before I explained my problem here in my post.
But this gives an error message:
"error:41 line: 39 object myvalue not declared".
The subroutines doesnt accept the global variable "myvalue"!
But if the variables are declared in the subroutines, they will be local and I will never get my string, which represents a binary number (it could also be a text "abaabab").
But I think there is something wrong with FNXBasic !?
problems with variables in subs
Yes, I have tried it first too. With same error. But: I`ve make some more other steps:
1. rename all myvalue to mylabel
2. exit from fnxbasic gui (save program in the course of this)
3. start gui: it has compiled and run without error
4. Re(rename) the variable name... ;-)
And so.
It is as much as saying that the compiler (os the GUI?) has some trouble, really.
Bat the code so can run...
PaPi
1. rename all myvalue to mylabel
2. exit from fnxbasic gui (save program in the course of this)
3. start gui: it has compiled and run without error
4. Re(rename) the variable name... ;-)
And so.
It is as much as saying that the compiler (os the GUI?) has some trouble, really.
Bat the code so can run...
PaPi
problems with variables in subs
Many thanks for your help!
But this is very strange and enormous complicated! ? :-?
But I will test it!
But this is very strange and enormous complicated! ? :-?
But I will test it!
problems with variables in subs
Hi, it is a `space` bug.
remove the space before the = sign.
and remove the parameters myvalue from the subs, then it works.
best regards
remove the space before the = sign.
and remove the parameters myvalue from the subs, then it works.
best regards
problems with variables in subs
[quote author=YaBB Administrator link=1210613239/0#5 date=1210693779]Hi, it is a `space` bug.
remove the space before the = sign.
and remove the parameters myvalue from the subs, then it works.
best regards[/quote]
This solves all my problems! Many thanks! I`m happy now!
remove the space before the = sign.
and remove the parameters myvalue from the subs, then it works.
best regards[/quote]
This solves all my problems! Many thanks! I`m happy now!