Adding items in a list

Post

Posted
Rating:
#1 (In Topic #1391)
Avatar
Regular
mandarin is in the usergroup ‘Regular’
I tried the following code:

(I want the list-to-be-formed to be used later in another form, so the variable definitions are of type "Public".)

Code (gambas)

  1.  
  2.  
  3. Public Sub Form_Open()
  4.  
  5.   If A1 = True Then
  6.     MyOwnList.Add(A1)
  7.  
  8.   If A2 = True Then
  9.     MyOwnList.Add(A2)
  10.  
  11.   If A3 = True Then
  12.     MyOwnList.Add(A3)
  13.  
  14. Print MyOwnList[1]
  15. Print MyOwnList[2]
  16.  

The program halts here: MyOwnList.Add(A1) , displaying the diagnostic "not enough arguments".

When I change Collection to Collection[], it also halts with: "wanted Collection, got Boolean instead".

What is wrong?

(Of course, after a right execution, I suppose I 'd have two prints with "True".)

Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Guru
cogier is in the usergroup ‘Guru’
Try this: -

Code (gambas)

  1. Public MyOwnList As New Boolean[]
  2.  
  3.  
  4. Public Sub Form_Open()
  5.  
  6.   If A1 = True Then
  7.     MyOwnList.Add(A1)
  8.  
  9.   If A2 = True Then
  10.     MyOwnList.Add(A2)
  11.  
  12.   If A3 = True Then
  13.     MyOwnList.Add(A3)
  14.  
  15.   Print MyOwnList[0] ''Arrays start at 0
  16.   Print MyOwnList[1]
  17.  
  18.  
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Regular
mandarin is in the usergroup ‘Regular’
Thanks! It worked perfectly!

I didn't know that lists can be of type array; thought they are only a collection of constants / variables, even of different types. (Hence, their definition as "Collection".)

Ok, I proceed with my program!  :)

Online now: No Back to the top

Post

Posted
Rating:
#4
Guru
BruceSteers is in the usergroup ‘Guru’
 Pretty sure ANYTHING can be an array[]

A Collection must always be pairs of KeyName and Data
Online now: No Back to the top
1 guest and 0 members have just viewed this.