Re: [U2] [UV] reference a variable indirectly?

2005-04-13 Thread Mats Carlid
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.NAMES2 equal to 'it works'.
(VAR.NAMES2) = '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 VARS1 SETTING II THEN
VALSII = 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/


RE: [U2] [UV] reference a variable indirectly?

2005-04-13 Thread Tim Franklin
Try this for size


0001:   EQUATE PART.NO LIT 'REC1'
0002:   REC1 = 'IT WORKS'
0003:   PRINT PART.NO
0004:END


Regards,
Tim Franklin

-Original Message-
From: Mats Carlid [mailto:[EMAIL PROTECTED] 
Sent: 13 April 2005 09: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.NAMES2 equal to 'it works'.
(VAR.NAMES2) = '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 VARS1 SETTING II THEN
 VALSII = 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/
---
u2-users mailing list
u2-users@listserver.u2ug.org
To unsubscribe please visit http://listserver.u2ug.org/


RE: [U2] [UV] reference a variable indirectly?

2005-04-13 Thread Bob Witney
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.

ARRAY1,-1 = PARTNO 
ARRAY1,-1 = LOTNO 
ARRAY1,-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 ARRAY1 to find the field name and does what it likes to 
ARRAY2,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.NAMES2 equal to 'it works'.
(VAR.NAMES2) = '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 VARS1 SETTING II THEN
 VALSII = 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/