[Solved] How to Declared a Array in Gambas

Post your Gambas programming questions here.
Post Reply
AndyGable
Posts: 359
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

[Solved] How to Declared a Array in Gambas

Post 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?)
Last edited by AndyGable on Monday 14th June 2021 9:33pm, edited 3 times in total.
User avatar
PJBlack
Posts: 184
Joined: Tuesday 9th June 2020 10:26pm
Location: Florstadt, Hessen, Germany

Re: How to Declared a Array in Gambas

Post 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
vuott
Posts: 262
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: How to Declared a Array in Gambas

Post 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...

Last edited by vuott on Monday 14th June 2021 8:58pm, edited 1 time in total.
Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: How to Declared a Array in Gambas

Post 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.
AndyGable
Posts: 359
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: [Solved] How to Declared a Array in Gambas

Post 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)
Post Reply