[Gambas-user] casting, macro change from str to resultfield?
Muriel Bodard
abidoo.too at ...11...
Tue Jan 3 13:15:10 CET 2006
Le Mardi 03 Janvier 2006 10:29, johnf a écrit :
> On Tuesday 03 January 2006 01:10, ron wrote:
> > On Tuesday 03 January 2006 08:34, johnf wrote:
> > > On Monday 02 January 2006 23:30, johnf wrote:
> > > > On Monday 02 January 2006 23:18, ron wrote:
> > > > > oopfield = hfield.Value
> > > >
> > > > Thanks that should work.
> > > >
> > > > But I also realized that Gambas is a compiled lang - therefore there
> > > > is nothing like macro substitution....
> > > >
> > > > Thanks again
> > > > John
> > >
> > > Dam I thought you had the answer. But hfield does not have "Value".
> > >
> > > But I wonder if something else does? I'll continue to check.
> > > BTW I'm using 1.9.23
> > > Thanks
> > > John
> >
> > Did a look in the help
> > gb.db.result:
> >
> >
> > DIM hResult AS Result
> > DIM aVariant AS Variant
> >
> > aVariant = hResult [ Field AS String ]
> >
> >
> > Returns the value of a field in the current record of the Result object.
> >
> > should be then:
> >
> > FOR EACH hfield IN contactdata.Fields
> > INC i
> > loopfield = contactdata[hfield.Name]
> > contacts[c, i].Text = loopfield
> > NEXT
> >
> > contactdata = result
> > contacts = gridview
> >
> > I hoop this wil do the job.
> >
> > Ron
>
> This works thank you very much. It's 1:am here and I'm very tired so I'm
> going to bed. But I want to understand your process of determining the
> correct way to get to the field. I need to be able to do the same thing.
> But when I read the help file I did not understand the notation. But you
> did! So if you can take some more time could you explain it. If this like
> trying to explain OOP then don't of course. But maybe there is some link
> or text in the help file that will explain the notation?
>
> Again thanks
>
>
>
> PS I think have a little understanding as I re-read the message. Is
> aVariant one of my controls (or any data type?).
>
> John
What is this code ...; ?
i understand that you can't understand that !
The code can work but is not writing on a good way to be use at a sample:
First :
What a Result :
A result is a buffer that store a query result. (i think you have understand
that.
When you send a query like Myconnection.exec("Select id, user from mytable" )
You obtain a result with n records on 2 fields
Result is a class too so:
you can access to the current record by :
- hResult!Field
- hResult["field"]
But you can access to the other result info like
- record count
- connection parent
- Index of current record
- Record walking functions
- ResultFields (collection of the fields used in the result)
ResultField
- name
- Length (max length)
- Result (parent)
- Type (type of data)
this Fill a tableview with a gived result
You need a form with a Tableview named TableView1 and a textBox named textbox1
' Gambas class file
PRIVATE hResult AS Result
PRIVATE hCon AS NEW Connection
PUBLIC SUB _New()
DIM hrField AS ResultField
hCon.Type = "sqlite"
hCon.Login = ""
hCon.PassWord = ""
hCon.Host = "/home/fabien/.Gestion"
hCon.Name = "Dossieryzf"
hCon.Open
hResult = hCon.Exec("SELECT * FROM Ecritures")
'Fill the columns headers of the Tableview an set number of columns
FOR EACH hrField IN hResult.Fields
INC TableView1.Columns.Count
TableView1.Columns[TableView1.Columns.Count - 1].Text = hrField.Name
NEXT
'Set The table view Number of Rows
TableView1.Rows.Count = hResult.Count
END
PUBLIC SUB TableView1_Data(Row AS Integer, Column AS Integer)
'Move to the Queried Row value
hResult.MoveTo(Row)
'Set The Current Cell Value With the current column header text for the
'fieldname
TableView1.Data.Text = hResult[TableView1.Columns[Column].Text]
'Toggle Row Color 1 on 2 (more pretty)
TableView1.Data.Background = IIf(row MOD 2 > 0, color.TextBackground,
&HF0EEFF&)
END
PUBLIC SUB Form_Close()
hResult = NULL
hCon.Close
END
I hope it help you...
Gambas is a powerfull tool to manage databases... Not so complete as a dedied
tool but mabe one of the better db layer i know.
The next Lesson ..; on how to add datas... and i'm going to try data
management on big tables...
Regards,
Fabien Bodard
More information about the User
mailing list