Yes you can: You get a pr-program to read the file with your actual programs source code open
The pre-program inserts the values as values in an array into the source of the actual program i.e. ARRAY<1,-1> = "PARTNO" ARRAY<1,-1> = "LOTNO" ARRAY<1,-1> = "PARTNAME" When all have been inserted it writes the actual program away with a new name Compiles it Executes it The actual program reads the file Does a locate on the ARRAY<1> to find the field name and does what it likes to ARRAY<2,X> (allocates values etc) after that Sounds like fun doesn't it Bob -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Mats Carlid Sent: 13 April 2005 08:36 To: u2-users@listserver.u2ug.org Subject: Re: [U2] [UV] reference a variable indirectly? Barry Brevik wrote: >UV 9.6.1.3 on Windows. > >For the longest time this has been bugging me, but right now I could really >use this capability. > >Does anyone know if it is possible to reference a variable indirectly? IOW, >I want to be able to store variable names in a file (for example), and then >assign values to those variables as the program encounters them. > >For example, something like this: > >PARTNO = ''; LOTNO = ''; PARTNAME = '' >VAR.NAMES = 'PARTNO':@FM:'LOTNO':@FM:'PARTNAME' >* >* Next, a magic command that makes the variable >* refered to by VAR.NAMES<2> equal to 'it works'. >(VAR.NAMES<2>) = 'it works'; * I know this does not work, just example. >PRINT LOTNO >* >* Variable LOTNO is now eq 'it works'. > >Possible?? > >Barry > > No there is no way to do that. You'd need an 'eval' function/statement. But You can do something similar with a subroutine and a function. Subroutine SET( variable name, value ) Function VAL( variable name ) They need to share a common ( or a file ) where variable-value pairs are stored. A straight forward implementation would be to search for the variable name in an mv-string and use the index to look up the value from another mv string. If you know the number of entries you can use arrays. Even if you don't you can still use arrays by running imformation style allowing them to be redimensioned. Then Your program would look like: DEFFUN VAL( var ) CALLING "VAL" CALL SET( 'LOTNO', 'it works' ) PRINT VAL( 'LOTNO' ) ---------------------------- Naive untested implementation. If heavily used you'd need to hash e.g. as MOD( SEQ(VAR[1,1])*LEN(VAR), N )+1 where N is the number of hash points and the dimension of VARS and VALS. SUBROUTINE SET( VAR, VAL) COMMON /..SET/ VARS, VALS LOCATE VAR IN VARS<1> SETTING II THEN VALS<II> = VAL END ELSE VARS<-1> = VAR VALS<-1> = VAL END RETURN END FUNCTION VAL( VAR ) !! Hashed version COMMON /..SET/ VARS(N), VALS(N) HASH = MOD( SEQ(VAR[1,1])*LEN(VAR), N )+1 RES = "" LOCATE VAR IN VARS(HASH)<1> SETTING II THEN RES = VALS(HASH)<II> END RETURN (RES) END -- mats ------- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/ ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ ------- u2-users mailing list u2-users@listserver.u2ug.org To unsubscribe please visit http://listserver.u2ug.org/