|
Post by kennn on Dec 21, 2019 6:37:29 GMT -6
Function BoundaryY(A)
If A < 0 Then
B = 544
Elseif A > 544 Then
B = 0
Else
B = A
End If
Return B
End Function
Hi, I don't know why this code has problem. Thanks first...
The error message is:
B was not found in this scope-: main.BoundaryY Could not evaluate expression
|
|
|
Post by johnno56 on Dec 21, 2019 8:36:05 GMT -6
I think I had a problem like this some time ago... The variable 'A' is 'introduced' to the function (ie: within the function name) but 'B' is a 'stranger'. I found by placing a 'B = 0' somewhere near the top of the program or placing a 'Dim B', immediately after the function name, usually does the trick.
eg:
function BoundaryY(A) Dim B If A < 0 then ... etc
I hope this helps...
J
|
|
|
Post by kennn on Dec 21, 2019 9:49:34 GMT -6
I think I had a problem like this some time ago... The variable 'A' is 'introduced' to the function (ie: within the function name) but 'B' is a 'stranger'. I found by placing a 'B = 0' somewhere near the top of the program or placing a 'Dim B', immediately after the function name, usually does the trick. eg: function BoundaryY(A) Dim B If A < 0 then ... etc I hope this helps... J Hi, In the following code, C is a stranger but no problem happens. Is there a bug? Function abc(D,E) G=D+E K = D*G F = D/E C = 0 Return C End Function On the other hand, I don't understand what 'Dim B' means. Why Dim B is required in this situation?
|
|
|
Post by n00b on Dec 21, 2019 9:57:41 GMT -6
In the manual, read the section on scope for a simple explanation. There is a more in depth explanation in the introduction to programming sections.
Basically, variables have a scope that they are created in and they don't exists outside of that scope.
So if you create a variable inside an IF statement, it only exist inside that if statement. This also applies to functions, loops, and select cases.
Also dim b is just another way of creating a variable. You could just do b=0 but b has to be made in the scope you want to use it in.
|
|
|
Post by kennn on Dec 22, 2019 4:30:22 GMT -6
In the manual, read the section on scope for a simple explanation. There is a more in depth explanation in the introduction to programming sections. Basically, variables have a scope that they are created in and they don't exists outside of that scope. So if you create a variable inside an IF statement, it only exist inside that if statement. This also applies to functions, loops, and select cases. Also dim b is just another way of creating a variable. You could just do b=0 but b has to be made in the scope you want to use it in.I s I am stupid. I will pay attention to the manual. Thanks.
|
|
|
Post by n00b on Dec 22, 2019 9:43:11 GMT -6
I was looking through my youtube channel this morning and realized I did a video on scope in RCBasic 3 years ago. Here is the link: Scope VideoIt is not great and I will probably redo it at some point.
|
|
|
Post by kennn on Dec 24, 2019 2:56:33 GMT -6
I was looking through my youtube channel this morning and realized I did a video on scope in RCBasic 3 years ago. Here is the link: Scope VideoIt is not great and I will probably redo it at some point. Thank you!!!!!!!!
|
|
|
Post by tbird on Dec 27, 2019 13:46:58 GMT -6
As a side note, one reason I like declaring variables local or global with DIM is that Geany will then throw it up for auto completion.
|
|
|
Post by kennn on Dec 28, 2019 7:16:40 GMT -6
As a side note, one reason I like declaring variables local or global with DIM is that Geany will then throw it up for auto completion. Ha....yeah!
|
|