You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
You can't use the same name even with different identifiers when declaring them. With no DIM ALL statement you can simply use them and the compiler won't complain.
eg.
Code:
#Compile Exe
Function PBMain
A$ = "Hello"
A% = 5
? A$
End Function
And then there's this data point too. I create a Global variable a% . Then I create a local variable a!.
If I try to use a% in the procedure where a! was defined, the compiler complains.
I guess the moral of the story is don't use variables with the same base name.
Code:
#Compile Exe
#Dim All
#Include "win32api.inc"
Global a%
Function PBMain() As Long
a% = 10
Local hDlg As Dword
Dialog New Pixels, 0, "Button Test",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 50,10,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
If Cb.Msg = %WM_Command And Cb.Ctl = 100 And Cb.CtlMsg = %BN_Clicked Then
Dim a!
a% = 5
MsgBox Str$(a)
'test code
End If
End Functio
Bear in mind that cat?, cat%, cat&, cat&&, cat!, cat#, cat##, [email protected], [email protected]@, and cat$ are ten separate variables. Although using cat over and over again to create different variables like this is legal, good programming practice suggests that you use somewhat different names for different variables.
But when I use
Code:
Dim a$, a%, a!
the compiler complains.
If it didn't, which a$, a%, a! would just plain old "a" be?
There's an inconsistency in here somewhere.
But you're right - with a single a% (or whatever type I give it), using plain old "a" compiles fine with #DIM ALL in it.
That is correct. The $ told the compiler that it is a type of STRING (could also use AS STRING), so you don't need the identifier to refer to it again once it is declared.
I DIM the variable temp$, but use temp in the code - yet the compiler doesn't complain. Is that the way it's supposed to be?
Code:
#Compile Exe
#Dim All
#Include "win32api.inc"
Function PBMain() As Long
Local hDlg As Dword
Dialog New Pixels, 0, "Button Test",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100,"Push", 50,10,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Dim temp$
temp = "s"
If Cb.Msg = %WM_Command And Cb.Ctl = 100 And Cb.CtlMsg = %BN_Clicked Then
'test code
End If
End Function
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Leave a comment: