Global variabels

Started by Stephane Fonteyne, October 19, 2011, 06:50:55 PM

Previous topic - Next topic

Stephane Fonteyne

Hi paul,

1.) Where do I place the GLOBAL variabels in my project?
It give me the next error if I placed this globals in the form code.



Global g_Address  As Integer : g_Address = &HFEE8
Global g_Baudrate As Integer
Global g_Init     As Long : g_Init = %FALSE

Function FORM1_BTNCONNECT_BN_CLICKED ( _
                                     ControlIndex     As Long,  _  ' index in Control Array
                                     hWndForm         As Dword, _  ' handle of Form
                                     hWndControl      As Dword, _  ' handle of Control
                                     idButtonControl  As Long   _  ' identifier of button
                                     ) As Long
.......



Error: Error 484



Uploaded with ImageShack.us

Best regards
Stephane Fonteyne
Ba. Elektronica - ICT
GSM : +32-xxxxxxxxxx
PowerBasic Developer & Hardware Support

Paul Squires

You obviously cannot initialize a variable outside of a sub/function.

Your "Global g_Address As Integer" is correct where it is.

You need to move the "g_Address = &HFEE8" to a place inside a sub or function.

Paul Squires
PlanetSquires Software

Marc van Cauwenberghe

#2
Hi Stephane,

Here is what I usualy do:

1) add a new module to your project named 'globals.bas' or 'main.bas' ...

2) Add all globals to the top of the module

3) add a sub named 'InitApp'

4) declare your values in the sub.

You should have something like this:


Global g_Address   As Integer
Global g_Baudrate  As Integer
Global g_Init         As Long

sub InitApp
   g_Address = &HFEE8
   g_Init = %FALSE
end sub


5) Go to the FF_WINMAIN function of your project and add 'call InitApp'


Function FF_WINMAIN( ByVal hInstance     As Dword, _
                     ByVal hPrevInstance As Dword, _
                     ByVal lpCmdLine     As Asciiz Ptr, _
                     ByVal iCmdShow      As Long ) As Long


   ' If this function returns TRUE (non-zero) then the actual WinMain will exit
   ' thus ending the program. You can do program initialization in this function.

   call InitApp

   Function = %FALSE    'return %TRUE if you want the program to end.

End Function