Restored from previous forum. Originally posted by talun.
Dear all,
I need a little help. I'm not able to use arrays in procedure arguments.
Can anyone help me?
Thankyou
Sergio
Procedure arguments
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Pupil.
In Purebasic all arrays that's declared using 'Dim' are global. An array can't be passed as an argument to a procedure, but you can always access them from inside a procedure because, as i said earlier, they are global.
Just keep in mind that PureBasic is a one-pass compiler and as such have a few restrictions concerning in which order (line-wise) you Dim your vars and insert your Procedures.
In Purebasic all arrays that's declared using 'Dim' are global. An array can't be passed as an argument to a procedure, but you can always access them from inside a procedure because, as i said earlier, they are global.
Just keep in mind that PureBasic is a one-pass compiler and as such have a few restrictions concerning in which order (line-wise) you Dim your vars and insert your Procedures.
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Danilo.
You pass arrays as a pointer by using ArrayName().
cya,
...Danilo
(registered PureBasic user)
You pass arrays as a pointer by using ArrayName().
Code: Select all
Dim Array1.l(10)
For a = 1 To 10 : Array1(a) = a : Next a
Dim Array2.l(20)
For a = 1 To 20 : Array2(a) = Random($FFFFFF) : Next a
Dim Array3.s(30)
For a = 1 To 30 : Array3(a) = "Entry "+Str(a) : Next a
Structure LONG
Long.l
EndStructure
Procedure ShowNumberArray(*Array.LONG,ArraySize)
If ArraySize = 0: ProcedureReturn : EndIf
For a = 1 To ArraySize
*Array + 4
A$ + Hex(*Array\Long)+Chr(13)
Next a
MessageRequester("Array numbers",A$,0)
EndProcedure
Procedure ShowStringArray(*Array.LONG,ArraySize)
If ArraySize = 0: ProcedureReturn : EndIf
For a = 1 To ArraySize
*Array + 4
A$ + PeekS(*Array\Long) + Chr(13)
Next a
MessageRequester("Array strings",A$,0)
EndProcedure
ShowNumberArray(Array1(),10) ; pass Array1
ShowNumberArray(Array2(),20) ; pass Array2
ShowStringArray(Array3(),20) ; pass Array3
...Danilo
(registered PureBasic user)
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by tinman.
Some changes that perhaps make it a bit nicer to work with
--
It's not minimalist - I'm increasing efficiency by reducing input effort.
(Win98first ed. + SP1, PB3.40)
Some changes that perhaps make it a bit nicer to work with
Originally posted by DaniloCode: Select all
Dim Array1.l(10) For a = 1 To 10 : Array1(a) = a : Next a Dim Array2.l(20) For a = 1 To 20 : Array2(a) = Random($FFFFFF) : Next a Dim Array3.s(30) For a = 1 To 30 : Array3(a) = "Entry "+Str(a) : Next a Structure LONG Long.l[0] EndStructure Procedure ShowNumberArray(*Array.LONG,ArraySize) If ArraySize = 0: ProcedureReturn : EndIf For a = 1 To ArraySize A$ + Hex(*Array\Long[i])+Chr(13) Next a MessageRequester("Array numbers",A$,0) EndProcedure Procedure ShowStringArray(*Array.LONG,ArraySize) If ArraySize = 0: ProcedureReturn : EndIf For a = 1 To ArraySize A$ + PeekS(*Array\Long[i]) + Chr(13) Next a MessageRequester("Array strings",A$,0) EndProcedure ShowNumberArray(Array1(),10) ; pass Array1 ShowNumberArray(Array2(),20) ; pass Array2 ShowStringArray(Array3(),20) ; pass Array3
--
It's not minimalist - I'm increasing efficiency by reducing input effort.
(Win98first ed. + SP1, PB3.40)
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm