[Gambas-user] Re: casting or changing datatype.

ron ronstk at ...239...
Sat Jan 14 18:27:50 CET 2006


On Saturday 14 January 2006 17:37, johnf wrote:
> All I'm attempting to do is write a class that can accept a string which will 
> create a "result" datatype with a name matching the string.  I can do this in 
> Visual Foxpro very easily:
> mydata = "anyname"
> Select * from arcust into &mydata.

Here mydata is the records collection / RecordSet in MS terms (Access and VB)
When you have a function that returns the Result you should get the records

For gambas:

Function GetRecords(query) as Result
  Dim rs As Result
  ...
  rs=DB.Execute(query) ' use the right code !
  ...
  Return rs
End

useage:
  Dim anyname as Result (gambas) ' RecordSet (MS
  anyname = getrecords(query)

In the Foxpro code you can dynamic say into witch recordset the result must go.
That is not posible in Gambas or MS Access and VB, as far I know. 

In VB you can do getrecords(query,rs) as Recordset
The code can set the rs variable to the recordset and return it too

dim rs as recordset
dim tr as recordset
  tm = getrecords(query,rs)

or
 with getrecords(query,rs) ' here the reason for return of Recordset
   if .RecordCount>0 then
      ...
   endif
   rs.close ' or .close, they are the same
 end with 

Function (query a string, putrs as recordset) as recordset
 set putrs = hconn.execute(query)
 return putrs
end

> I can do this in RealBasic (I think I can)
> dim mydata as variant
> result(mydata) = hconn.exec("select * from arcust;) 

Basicly the same in GB, ecept 'variant' must be 'Result' 
and 'result(mydata)' = .... must be 'mydata'

> Actually the sql statement is very different but I want it to simple.
> The "realbasic" example is called "casting" I believe. 
> 

The only casting I know is in C as: (result)mydata

>I'm a newbie to gambas and basic in general. 
> Which means I'm trying to use old thinking with a new langauge.
I'm not a newby in same sence but the gambas basic language has
some differences to other and puzzle me also many times.
Old thinking is for me the VB/Access way. Stupid me.

Your intention can be good but to make the framework you need to be
experienced for the basic parts.
I think you are to quick to do it now, try first to learn the basic stuff
dispite you have more work, you understanding of gambas improves with it.

I made some tools in PHP to create complete PHP/HTML pages to work 
on mysql tables.
Now I have to build another project and have lost the close contact 
to the code to write the basics because I did not do it enouhg but 
using the tools and they are not usable in this project.
Learning again.
If you are good in big projects/programs/codeblocks already, switching
an programming environment needs slowing down some steps to learn the new things.
I made the mistake also by trying to make something big as newbie in the past.


Ron




More information about the User mailing list