Database Results

Post

Posted
Rating:
#1 (In Topic #1617)
Trainee
 Hi,

I'm a newcomer to Gambas, having been writing in numerous other languages for years, and I feel I'm doing really well in getting to grips with it.

But I've hit a brick wall with this one.  I'm creating a simple database utility for personal use.  In, for example, XOJO, you can either write rs.field("surname").stringvalue or rs.idxfield(1).stringvalue.  In Gambas it looks at present that you can only use rs!surname.  The stringvalue part isn't needed of course in Gambas.

Question: is there a Gambas equivalent of idxfield(0), eg, rs!(1)?

Help please!

Alan.
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Administrator
gbWilly is in the usergroup ‘unknown’

CallMeAlan said

Hi,

I'm a newcomer to Gambas, having been writing in numerous other languages for years, and I feel I'm doing really well in getting to grips with it.

But I've hit a brick wall with this one.  I'm creating a simple database utility for personal use.  In, for example, XOJO, you can either write rs.field("surname").stringvalue or rs.idxfield(1).stringvalue.  In Gambas it looks at present that you can only use rs!surname.  The stringvalue part isn't needed of course in Gambas.

Question: is there a Gambas equivalent of idxfield(0), eg, rs!(1)?

Help please!

Alan.
You will have to clarify your question as I don't speak XOJO.  ;)
Are you trying to address a field in a record by it's index, or something a like?

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
Trainee
 What I mean is, instead of saying rs!surname, rs!firstname, rs!city, we could say something like rs!1, rs!2, rs!3.  That is, address the columns by their serial number index within the record set instead of by their column name.

In XOJO we would say rsfield("surname").stringvalue, or rs.idxfield(1).stringvalue, which give the same value.  This permits the use of a for loop to address the columns, such  as:
for x=0 to whatever
    listbox1.add(rs!x)
next

I hope this makes sense!

Alan.
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Expert
Poly is in the usergroup ‘Expert’
Hi and welcome the result-class acts like an array
So you simple can do

For example

Code (gambas)

  1. If $con.Opened Then
  2.    rs = $con.Exec("SELECT * FROM Namen Order by Punkte")  
  3.    While (rs.Available)
  4.       Print "Column1:" & rs!Namen & ", Column2:" & rs["Punkte"]
  5.       Print "Hallo" & rs[1]
  6.       rs.MoveNext()
  7.    Wend
  8.  


So you have 3 choices:

1.) rs!Namen
2.)  rs["Namen"]
3.) rs[1]

/comp/gb.db2/result - Gambas Documentation

best regards
Poly
Online now: Yes Back to the top

Post

Posted
Rating:
#5
Avatar
Regular
thatbruce is in the usergroup ‘Regular’

Online now: No Back to the top

Post

Posted
Rating:
#6
Trainee
 Oh dear me!  rs[1] works!  I clearly never thought to use square brackets - I was trying round brackets, eg, rs(0).

Many thanks for solving my problem.

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