[Solved] How to Declared a Array in Gambas

Post

Posted
Rating:
#1 (In Topic #683)
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
Hi Everyone

I was wondering if someone could advice me on the following issues

I have declared

Code

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?)
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Enthusiast
PJBlack is in the usergroup ‘Enthusiast’

Code (gambas)

  1. Public QuickTenderName[7] As String
  2. Public QuickTenderValue[7] As String
  3.  

should work … maybe better:

Code (gambas)

  1. Public QuickTenderName as String[]
  2. Public QuickTenderValue as String[]
  3.  
  4. public/privat sub/function()
  5. dim QuickTenderName as New string[]
  6. dim QuickTenderValue as New string[]
  7. ...
  8. ...
  9. QuickTenderName.add("stringname")
  10. QuickTendervalue.add("stringvalue")
  11. ...
  12. ...
  13.  
Online now: No Back to the top

Post

Posted
Rating:
#3
Regular
vuott is in the usergroup ‘Regular’
If you want a mono-dimensional array with defined number of elements, you can also use (and is considered preferable) a non-nested array:

Code (gambas)

  1. Private [or Public] QuickTenderName As New String[7]
  2.  
  3. Public Sub Main()
  4.  
  5.   QuickTenderName[0] = "abcde"
  6.   ...and so on...
  7.  
  8.  

Similarly with a local variable:

Code (gambas)

  1. Public Sub Main()
  2.  
  3.   Dim QuickTenderName As New String[7]
  4.  
  5.   QuickTenderName[0] = "abcde"
  6.    ...and so on...
  7.  
  8.  

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Guru
cogier is in the usergroup ‘Guru’
It has been a long time since I used an array using a number as in: -

Code (gambas)

  1. 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: -

Code (gambas)

  1. Public QuickTenderName As New String[]

or for arrays declared at inception: -

Code (gambas)

  1.  sDir As String[] = Dir(User.Home)
  2.  sNames As String[] = ["Alan","Sally","John","Ann"]
  3.  

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.
Online now: No Back to the top

Post

Posted
Rating:
#5
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
 Thank everyone for the advice I was using () and not [] (still use to VB.net code need to get use to Gambas coding)
Online now: No Back to the top
1 guest and 0 members have just viewed this.