RE: Converting a string to a variable name

new topic     » goto parent     » topic index » view thread      » older message » newer message

Hi all !
Thanks all for the "lessons" :>)
As i'm starting in Euphoria, i'm always learning with this forum. The best 
manual for Euphoria is here. :>)

Now I will explain why I cannot use arrays in my program :

This is my program: (Win32)
------------------------------------------------------------------------------------------------------------------------------------------
include Win32lib.ew
--------------------------------------------------------------------------------
--  Window Window1
constant Window1 = createEx( Window, "", 0, Default, Default, 602, 338, 0, 0 )

object etext1,etext2,etext3...

constant EditText1 = createEx( EditText, "100", Window1, 8, 32, 70, 20, 0, 0 )
constant EditText2 = createEx( EditText, "100", Window1, 8, 56, 70, 20, 0, 0 )
constant EditText3 = createEx( EditText, "100", Window1, 8, 80, 70, 20, 0, 0 )
                         .
                         .
                         .and so on... a lot.

I have to change the value "100"  in the EditText1, EditText2... and so 
on... to values from etext1, etext2 and so...

The only way i find to do this is:

etext1=gets(arquivo)                             --------some txt archive
etext1=etext1[1..length(etext1)-1]
setText(EditText1,etext1)
etext2=gets(arquivo)
etext2=etext2[1..length(etext2)-1]
setText(EditText2,etext2)
etext3=gets(arquivo)
etext3=etext3[1..length(etext3)-1]
.
.
.one by one.... and a ugly code.

This is what will be nice to do...

for x=1 to .. do ----   until the end of the file
etext&x=gets(arquivo)
setText(EditText&x,etext&x) ------------------------ set EditText1 to value 
etext1
end if

nice code... but does not work.

I didn't try using arrays still now, but ...does this work ?

for x=1 to 10 do
etext[x]=gets(arquivo)
setText(EditText[x],etext[x]) ------------------------ set EditText1 to 
value etext1
end if



By
Rubens

At 15:17 29/7/2002, you wrote:
>
> > It wasn't me who asked for a way to make var names *recently*, i have a
> > workaround, which i posted here. But i still say it should be in native
> > Euphoria.
> >
> > Kat
>
>Yeah I know Kat... there are probably 10 different ways to implement
>this.  It >would< be nice if this was native Euphoria, and it would also
>be nice if Euphoria would at least handle structures like all the other
>languages I have seen.  Sequences are nice, but not when working with
>the API.  Oh well, heres a couple of routines you can use to emulate
>dynamic variables through strings.
>
>Note: The HashWin (window) I created is technically not needed.  The
>routines will attach a string variable to any window.  I placed it in
>the code to simplify the calling procedures/ functions.
>
>===============
>
>include Win32Lib.ew
>
>constant
>setProp = registerw32Procedure( user32, "SetPropA",
>{C_POINTER,C_POINTER,C_LONG} ),
>getProp = registerw32Function( user32, "GetPropA",
>{C_POINTER,C_POINTER}, C_LONG ),
>removeProp = registerw32Procedure( user32, "removePropA",
>{C_POINTER,C_POINTER} )
>
>constant
>HashWin = create( Window, "", NULL, 0, 0, 1, 1, {0} ),
>hWndHash = getHandle( HashWin )
>
>procedure SetStrVar( sequence StrVar, atom Value )
>         atom hStrVar
>         hStrVar = allocate_string( StrVar )
>         w32Proc( setProp, {hWndHash,hStrVar,Value} )
>         free( hStrVar )
>end procedure
>
>function GetStrVar( sequence StrVar )
>         atom hStrVar
>         atom RetVal
>         hStrVar = allocate_string( StrVar )
>         RetVal = w32Func( getProp, {hWndHash,hStrVar} )
>         free( hStrVar )
>         return( RetVal )
>end function
>
>procedure RemoveVar( sequence StrVar )
>         atom hStrVar
>         hStrVar = allocate_string( StrVar )
>         w32Proc( removeProp, {hWndHash,hStrVar} )
>         free( hStrVar )
>end procedure
>
>-- usage
>--
>-- to set: SetStrVar( "VarName", Value )
>-- to get: GetStrVar( "VarName" )
>-- (optional)to remove: RemoveVar( "VarName" )
>--
>
>===============
>
>Don Phillips
>
>
>

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu