[Gambas-user] POSSIBLE! bug in while loop

Stephen sbungay at ...3301...
Tue Dec 29 14:37:14 CET 2015


Reading this, in addition to seeing the need for a "Wait", I thought the 
following;

   Does putting the desired global variable in a class mean the class 
needs to be instantiated within the scope of the code example given? i.e.

PUBLIC GlobalVar as globalVars ' Change the name of the class to keep 
the var name within the example unchanged.

within the code of the form which contains the GObtn and exitBtn objects?

The above would make GlobalVars.iexit visible to all classes outside of 
the scope of where it was instantiated, so all forms in the project 
could then see it.

However this can be avoided if the variable "iexit" is declared in a 
"module" as opposed to a "class". Doing this it instantly becomes global 
within the scope of the project, requiring only the addition of the 
"Wait" to process the exitBtn_Click() event and exit the loop.

The change to the code is minimal;

' Gambas class file

' Static Private iexit As Integer = 0
Public Sub _new()
End

Public Sub Form_Open()
  GlobalVars.iexit = 0
End

Public Sub GObtn_Click()
  Dim n As Integer

  n = 0

  While n < 100000
        Print n
        n = n + 1
        Wait ' This is new
        If GlobalVars.iexit > 0 Then Break
  Wend
End

Public Sub exitBtn_Click()
   GlobalVars.iexit = 10
End

   This works, tested under GAMBAS 3 on Fedora 14.


On 12/28/2015 09:55 PM, Robert Boykin wrote:
> Test Program code is:
> ' Gambas class file
>
> ' Static Private iexit As Integer = 0
> Public Sub _new()
> End
>
> Public Sub Form_Open()
>   GlobalVar.iexit = 0
> End
>
> Public Sub GObtn_Click()
>   Dim n As Integer
>   n = 0
>   While n<  100000
>   Print n
>   n = n + 1
>   If GlobalVar.iexit>  0 Then Break
>   Wend
> End
> Public Sub exitBtn_Click()
>   GlobalVar.iexit = 10
> End
>
> This is gambas3 on linux mint 17.3 using gb.qt4
> running on a generic desktop PC
>
> The simple form has two buttons,
> one to start a while loop
> that prints numbers to the console, and
> one to set a global variable to a value which
> should cause a break in the while loop.
>
> The global variable is defined in the class GlobalVar
> ' Gambas class file
>
> Static Public iexit As Integer = 0
>
> The program begins printing numbers upon clicking the Gobtn
> but will not stop printing when the exitBtn is cliked.
>
> It appears that the exitBtn _Click() event is not recognized
>   during execution of the while loop.
>
> I am just learning gambas on my own using
>   what examples and tutorials I can find on the internet
> and believe I may have left something out.
>
> Robert S. Boykin
> ------------------------------------------------------------------------------
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>


-- 
Kindest Regards
Stephen A. Bungay, Prop.
Smarts On Site Information Systems





More information about the User mailing list