Hi,
I come form a c/c++ background but have always loved tinkering in basic.
Firstly when I define an array:
Dim MyArray.i(10)
does the array follow C - 0-9 or like VB6 1-10. i.e
MyArray(0) = 100 or MyArray(1) = 100
Also my first attempt was to create an array of gadgets like so:
Dim Canvas_Gadgets.i(10)
For i = 1 To 10
Canvas_Gadgets(i) = CanvasGadget(#PB_Any, i*220, ImageHeight(0)/2, 320, 200, #PB_Canvas_Container)
Next i
BindEvent(#PB_Event_SizeWindow, @OnWindowResize(), 0)
....
; here's where I get the error -Line 19: Canvas_Gadgets() is not a function, array, list, map or macro. (line 19 is ResizeGadget)
Procedure OnWindowResize()
For i = 1 To 10
;line 19
ResizeGadget(Canvas_Gadgets(i), #PB_Ignore, WindowHeight(0)/2, #PB_Ignore, #PB_Ignore)
Next i
EndProcedure
PB Beginner - a few questions
Re: PB Beginner - a few questions
Neither.scanfff wrote:Dim MyArray.i(10)
does the array follow C - 0-9 or like VB6 1-10.
It's 0 - 10 so the array has 11 elements.
https://www.purebasic.com/documentation ... e/dim.html
If you want to use the array inside a procedure, I think you need
Global Dim
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
Re: PB Beginner - a few questions
Thanks, the Global fixed it!wilbert wrote:Neither.scanfff wrote:Dim MyArray.i(10)
does the array follow C - 0-9 or like VB6 1-10.
It's 0 - 10 so the array has 11 elements.
https://www.purebasic.com/documentation ... e/dim.html
If you want to use the array inside a procedure, I think you need
Global Dim
Re: PB Beginner - a few questions
VB6 only uses 1 if you set Option Base 1.
PB starts from 0 and goes to the number in the index.
0-10 in your example.
This is not true with structured arrays.
MyStructArr.i[10] = 0-9.
PB starts from 0 and goes to the number in the index.
0-10 in your example.
This is not true with structured arrays.
MyStructArr.i[10] = 0-9.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: PB Beginner - a few questions
Slightly off topic. Here is a nice program I got from the forum that may be useful to you. It generates an assembly listing of your program so you can see how PB generates assembly code.
Code: Select all
;Generates and lists assembly code for file in line 2
file$="timeloop1.pb"
dir$ = GetPathPart(file$)
If file$ And FileSize(file$)>0
Compiler = RunProgram(#PB_Compiler_Home+"\Compilers\pbcompiler", Chr(34)+dir$+file$+Chr(34)+" /COMMENTED ", dir$,#PB_Program_Hide|#PB_Program_Wait)
dir$+"PureBasic.asm"
If Compiler And FileSize(dir$)>0
RunProgram("notepad.exe", dir$,"")
Else
MessageRequester("Error!", "There was an error creating the assembly code file.")
EndIf
Else
MessageRequester("Error!", "Bad input file")
EndIf