Declaring Arrays

Post

Posted
Rating:
#1 (In Topic #253)
Regular
Doctor Watson is in the usergroup ‘Regular’
Some beginners enigma  :?
I can’t find how and where to declare Arrays.
I think this should be done in the Project’s first form : Fmain
When I try to run for example in Fmain.Class :

Public Sub Form_Open()
Dim A[50] AS String
End

I get : “Embedded arrays are forbidden here in Fmain.Class”
And I get the same notification wherever I try.
In the Beginners Guide I read “Arrays are always initialized as void at startup”
So, where is ‘Startup’ ?

 Old african saying:
You eat an elephant one small bite at a time.
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Guru
cogier is in the usergroup ‘Guru’
Hi Doctor!
Here is a start for you. This small program will run, it will find all the 'hidden' files in your Home folder: -

Code (gambas)

  1. ' Gambas class file
  2.  
  3. iGlobalArray As New Integer[]                   'Global array
  4.  
  5. Public Sub Form_Open()
  6. Dim sZ As New String[50, 2]                     'Creates a multi dimensional array
  7. Dim sB As New String[50]                        'Creates an empty array of 50
  8. Dim sD As New String[]                          'Creates an array that can be added to with .Add (see below)
  9.  
  10. Dim sA As String[] = ["A", "B", "C"]            'Creates a simple Array  
  11. Dim sC As String[] = Dir(User.Home)             'Creates a new array with all the file names in you Home folder
  12.  
  13. Dim sTemp As String                             'Temp string
  14.  
  15. For Each sTemp In sC                            'For each file name in sC
  16.   If sTemp Begins "." Then sD.Add(sTemp)        'If the file begins with "." then add it to sD
  17.  
  18. Print sD.Join(" - ")                            'Print the array joined with " - "
  19.  

The iGlobalArray can be used anywhere in this class. If you want to use it in another class add 'Public' to the beginning of the line.

The arrays in Public Sub Form_Open() can only be used in this procedure.

In the Beginners Guide I read “Arrays are always initialized as void at startup”
So, where is ‘Startup’ ?

This says that when you startup your program all arrays will be empty.
Online now: Yes Back to the top

Post

Posted
Rating:
#3
Regular
Doctor Watson is in the usergroup ‘Regular’
I think I'm getting there … ;)
It will take some time as I did some programming - many years ago - in RealBasic. Gambas feels like it, but it's obviously not quite the same.
Old African proverb says: "One eats an elephant one little bit at a time"
Thanks

 Old african saying:
You eat an elephant one small bite at a time.
Online now: No Back to the top
1 guest and 0 members have just viewed this.