Page 1 of 1
[Solved] How to Declared a Array in Gambas
Posted: Sunday 6th June 2021 12:51am
by AndyGable
Hi Everyone
I was wondering if someone could advice me on the following issues
I have declared
Code: Select all
Public QuickTenderName(7) As String = Null
Public QuickTenderValue(7) As String = Null
But when I run the code I get a Error saying Missing As (am I doing something wrong?)
Re: How to Declared a Array in Gambas
Posted: Sunday 6th June 2021 1:36am
by PJBlack
Public QuickTenderName[7] As String
Public QuickTenderValue[7] As String
should work ... maybe better:
Public QuickTenderName as String[]
Public QuickTenderValue as String[]
public/privat sub/function()
dim QuickTenderName as New string[]
dim QuickTenderValue as New string[]
...
...
QuickTenderName.add("stringname")
QuickTendervalue.add("stringvalue")
...
...
end
Re: How to Declared a Array in Gambas
Posted: Sunday 6th June 2021 10:33am
by vuott
If you want a mono-dimensional array with
defined number of elements, you can also use (and is considered
preferable) a
non-nested array:
Private [or Public] QuickTenderName As New String[7]
Public Sub Main()
QuickTenderName[0] = "abcde"
...and so on...
Similarly with a
local variable:
Public Sub Main()
Dim QuickTenderName As New String[7]
QuickTenderName[0] = "abcde"
...and so on...
Re: How to Declared a Array in Gambas
Posted: Sunday 6th June 2021 11:46am
by cogier
It has been a long time since I used an array using a number as in: -
Public QuickTenderName As New String[7] 'Not Public QuickTenderName(7) As String
I use the following so that I can use '.Add()' to fill the array: -
Public QuickTenderName As New String[]
or for arrays declared at inception: -
sDir As String[] = Dir(User.Home)
sNames As String[] = ["Alan","Sally","John","Ann"]
Note that the word
Public is only needed if you intend to call this variable from another class.
Forum tip: - When adding code use the
gb button as it will format the Gambas code as above.
Re: [Solved] How to Declared a Array in Gambas
Posted: Monday 14th June 2021 9:34pm
by AndyGable
Thank everyone for the advice I was using () and not [] (still use to VB.net code need to get use to Gambas coding)