[Solved] How to Declared a Array in Gambas

Post your Gambas programming questions here.
Post Reply
AndyGable
Posts: 83
Joined: Wednesday 02nd December 2020 12:11am
Location: England
Contact:

[Solved] How to Declared a Array in Gambas

Post by AndyGable » Sunday 06th June 2021 12:51am

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: 141
Joined: Tuesday 09th June 2020 10:26pm
Location: Florstadt, Hessen, Germany

Re: How to Declared a Array in Gambas

Post by PJBlack » Sunday 06th June 2021 1:36am

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: 91
Joined: Wednesday 05th April 2017 6:07pm
Location: European Union

Re: How to Declared a Array in Gambas

Post by vuott » Sunday 06th June 2021 10:33am

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.

User avatar
cogier
Site Admin
Posts: 721
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: How to Declared a Array in Gambas

Post by cogier » Sunday 06th June 2021 11:46am

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: 83
Joined: Wednesday 02nd December 2020 12:11am
Location: England
Contact:

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

Post by AndyGable » Monday 14th June 2021 9:34pm

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