Character '!'

Post

Posted
Rating:
#1 (In Topic #2024)
Trainee
Zyfriala is in the usergroup ‘Trainee’

Usage of character '!'

Hello, I come back to the Gambas programming after a few years,
I don't remember exactly what the character '!' is used for (i know it's a special character)
for example :

$dev1 = $ResultConsult!arrLabels_h[0]
doesn't seem to work…

Normally i would write something like
$dev1 = $ResultConsult!lignes

with the name of the column, and it works fine,
but i want to use a chosen array.

Can you refresh my memory please ?
Thank you a lot  :thumbs:
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Administrator
gbWilly is in the usergroup ‘unknown’
gbWilly leads the usergroup ‘GambOS Contributor’
gbWilly is in the usergroup ‘Blogger’
You are assuming correctly with the ! (exclamation mark) but make a mistake by adding the index.
As far as I am aware:

  rResult!MyColumnName is valid (Column name = Fieldname of the record)
  rResult!MyColumnName[0] is not

I do not know what you want to achieve, but you can loop the content of one field for all records.
Below an example to read the content of one field for all records into an array, presuming $rResult already holds the data and one of the field is named MyColumnName and holds string data.



Code (gambas)

  1. Dim aFieldContent As String[]
  2.  
  3. aFieldContent = New String[rResult.Count]
  4.  
  5. $rResult.MoveFirst
  6. For iX = 0 To $rResult.Max
  7.    aFieldContent [iX]= $rResult!MyColumnName
  8.    $rResult.MoveNext
  9.  

This will result in an array containing the content of all records with filedname MyColumnName.
If you want to read it into a GridView or TableView, you use the Data event of said GridView or Tableview.

I hope this helps..:thumbs:




 

Last edit: by gbWilly


gbWilly
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories


… there is always a Catch if things go wrong!
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Enthusiast
Gianluigi is in the usergroup ‘Enthusiast’
Gianluigi is in the usergroup ‘GambOS Contributor’
Hi Zyfriala

Or you can also write it like this:

Code

Public Sub Main()

  Dim aText As String[] = ["Pippo", "Pluto", "Topolino"]
  Print aText!"1" ' ---< Pluto

End

 :goodbye:
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Administrator
gbWilly is in the usergroup ‘unknown’
gbWilly leads the usergroup ‘GambOS Contributor’
gbWilly is in the usergroup ‘Blogger’

Gianluigi said

Or you can also write it like this:
The question was on a database result set to my understanding and not an array.  ;)
 

gbWilly
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories


… there is always a Catch if things go wrong!
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Expert
Quincunxian is in the usergroup ‘Expert’
Quincunxian is in the usergroup ‘Blogger’

gbWilly said

Gianluigi said

Or you can also write it like this:
The question was on a database result set to my understanding and not an array.  ;)
 

That raises an interesting point - What is a Result?
I know how it works with a database SELECT but not exactly what it is.
The documentations says: "This class acts like a read / write array."

At face value, it acts very much like a variant array even to the point that it is zero based..

These are the three methods I know of to identified data returned in a Result

If you have a data table with 'Id' as the first column name of the record.

Code

Result!Id
Result[0]
Result["Id"]

Will all return the value stored in 'Id'
 

Cheers - Quin.
I code therefore I am
Online now: No Back to the top

Post

Posted
Rating:
#6
Avatar
Enthusiast
Gianluigi is in the usergroup ‘Enthusiast’
Gianluigi is in the usergroup ‘GambOS Contributor’

gbWilly said

The question was on a database result set to my understanding and not an array.  ;)
Reading this:

Zyfriala said

i want to use a chosen array.
Instead, I understood that he wanted to know how to use the exclamation mark with an array.

Quincunxian said

That raises an interesting point - What is a Result?
I think Gambas uses a collection, but I'm not sure.

 :goodbye:
Online now: No Back to the top

Post

Posted
Rating:
#7
Trainee
Zyfriala is in the usergroup ‘Trainee’
Hi guys, thanks for all your help and your attention,

asking AI (Simplexity)  i had this (one) explanation

" The operator ! expects a fixed identifier (a literal name like Result!Name), not a dynamic variable. "

so an array cannot be used.

But i'm pretty sure i solved this problem many years ago…i just don't remember how :P

Anyway, i wrote a little more code and stayed with

Result!ColumnName

If i ever find the solution i will post it here.

Many thanks :)

NB : i will open a new post because i have a problem with my gridview…
 
Online now: No Back to the top

Post

Posted
Rating:
#8
Avatar
Administrator
gbWilly is in the usergroup ‘unknown’
gbWilly leads the usergroup ‘GambOS Contributor’
gbWilly is in the usergroup ‘Blogger’

Gianluigi said

Quincunxian said

That raises an interesting point - What is a Result?
I think Gambas uses a collection, but I'm not sure.
I was thinking the same because of rResult["FieldName"] being possible, but I should look under the hood in source code to be sure

gbWilly
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories


… there is always a Catch if things go wrong!
Online now: No Back to the top

Post

Posted
Rating:
#9
Trainee
Zyfriala is in the usergroup ‘Trainee’
Hello again,

i was looking in your examples, I did some tests and found it…

i don't have to write this, with the name of the column

$dev1 = ResultConsult_h!lignes

i just have to write this

$dev1 = ResultConsult_h[0]

and i'm not even obliged to use $dev1, i can write in my gridview using

my function directly with

fo_GridView_Write(row,column, ResultConsult_h[0])

I just save a lot of code…

thanks for your help  :thumbs:

Online now: No Back to the top
1 guest and 0 members have just viewed this.