[Gambas-user] Re: casting or changing datatype.
johnf
jfabiani at ...1109...
Sat Jan 14 17:37:28 CET 2006
On Saturday 14 January 2006 06:57, ron wrote:
> On Saturday 14 January 2006 11:36, Rohnny Stormo wrote:
> > Hi.
> >
> > Think scripting or javascript has a variant of this if 'm not wrong.
> > Looks like he is thinking of something like this.
> >
> > Public Sub SomeSub(ItemsToUse as string)
> > [ItemsToUse].Text ="Hello"
> > end sub
> >
> > SomeSub("TextBox1")
> > SomeSub("TextBox2")
> >
> > This is a small example, but in larger scale it could be usefull,
> > special when makeing classes.
> >
> > Would be nice thow if it could be done.
> >
> > Regards Rohnny
>
> You are simply setting a global variable named by content of ItemsToUse in
> the Sub. SomeSub creates here 2 variables "Textbox#" and set value them to
> "Hello"
>
> Global variables is not posible in gambas with good reason by Benoit, but
> can be emulated to java/vb behaviour by prefix them with a module name.
> Use i.e. a module named 'Global' for Global.MyGlobalVBvariable :)
>
> But that is not the real question.
>
> What he is doing in his example looks more as he want to
> Dim variables with a name passed by string.
>
> He is doing with 'dim thestr as Result' is setting a dynamic name for a
> variable in a Dim, what makes nosense because that variable lives only in
> runtime inside the Sub code.
>
> Or he wants to give a name to the Result, and can not be done for Result
> here. Or he want a variable with the name passed as string and returning
> that variable so he can refer to that variable??
>
> myResult("TheNameForTheVariable")
> print TheNameForTheVariable
>
> The Result is a wrong datatype/object here as example.
> Result is more acting as a Object with a contruction of a DataType.
>
> I belive he used the 'Result' as an textual example and not as the real
> thing and must be seen as <datatype>, take the one you want.
>
>
> Public Sub myResult(thestr as string) as <xxxx> ' i.e. <object>
> dim MyXXXX as <xxxx>
> MyXXXX = new <xxxx>
> MyXXXX.Name = thestr 'it should have the property Name of course :)
> Return MyCtrl
> End
>
> This could be more the way, but the 'Name' propertie in gambas is not
> available as in VB for controls or most other objects.
>
>
> Or returning the datatype of a variable where the name is passed by a
> string TheDataType = VarTypeOf("TheVarName")
> instaed of
> TheDataType = VarTypeOf(TheVarName)
>
> BTW
> public sub myResult( thestr as String) as Result
> is not posible, only functions return somthing.
>
> Subs can only set global available variables for a return value and not
> as in VB, change the the content of the variable passed By Ref(erence)
>
> Gambas passes for 'not object' variable always by (copy of the) value.
> Code can can change the passed value but orginal stay the same.
>
>
> public sub myResult( thestr as String) as Result
> dim thestr as Result
>
> See for _Dim_ the help again.
> You should give a name (without quotes) for the variable and
> <type>/<object> Here _thestr_ IS the name of the variable.
> How do you want use the content of a string as i.e. "myName" as unqouted
> name?
>
> Dim "thestr" as Result
> Dim "myName" as String
>
> Print thestr
> Print myName
>
> In fact _this_ can be done, no problem if there are quotes around the
> variable name to interpret it as the variable name without quotes in the
> rest of the code. But what should do _Print thestr_ if you call the sub
> with a different name by sting i.e. "NotMyBike" ?
> Of course then we should/must use: Print "thestr" :)
>
> So you did give at least two point you should analize more.
> Sub returning a value and the way you want to implement the Dim you
> suggest.
>
>
> You should give a more complete example what you wants with a piece of code
> that uses it. Special the _Result_ word you use make it more complex,
> the real _Result_ or a _word-for-something_ and make here more sence.
>
> ---
> My 2 cents
>
> Ron
I'm sorry my example was not better written. You are right the example is
using a sub to return some variable and should have been a function. My only
excuse is I program in Foxpro and there is not real difference between a
function and a method both can return a variable.
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.
I can do this in RealBasic (I think I can)
dim mydata as variant
result(mydata) = hconn.exec("select * from arcust;)
Actually the sql statement is very different but I want it to simple.
The "realbasic" example is called "casting" I believe.
So I thought there has to be a way I can pass a string to a class and create a
"result" datatype variable for use later in the program. I want to create
(what in other languages is called) a framework. I will use the framework to
create programs. I will have my data access classes, my business rule
classes and my UI classes. The problem of course is I will need tools that
will accept strings for naming objects (like a result datatype). Of course
if it can't be done then I'll have to find a different way.
I'm a newbie to gambas and basic in general. Which means I'm trying to use
old thinking with a new langauge. So I'm very open to suggestions on how to
create a framework. Actually I open to anything with respect to Gambas.
John
More information about the User
mailing list