Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get value from array using field value

Status
Not open for further replies.

wmbb

Technical User
Jul 17, 2005
320
NL
I'm using an array like the one below
Code:
NumberVar tar := 0;

NumberVar array AQTCO1 := [180,188,189,222,236];
NumberVar array AQTCO2 := [133,153,139,151,166];
NumberVar array AQTSV1 := [254,268,291,316,344];

In the database is a field called "code" and this can be the value AQTCO1, AQTCO2, AQTSV1

Now I want to get the value depending on the field-value.
Something like
Code:
tar:={TABLE1.CODE}[3]
to get the third value from the linked array

What is the code I have to use ?
Now I'm getting an error "a number is required here
 
I am not sure which 'value' you want to get. But one way I think you can achieve your goal is code like this:

If {TABLE1.CODE} = "AQTCO1" then tar:= AQTCO1[3]
else
If {TABLE1.CODE} = "AQTCO2" then tar:= AQTCO1[3]
else tar:= AQTSV1[3]
 
Thank you for your response.
Actually that's the way I'm doing it now but my list of codes is a little longer (12).
Doing it this way, I have to create 12 lines of code.
I thought maybe there is someone with a smart solution for this.



 
The possibly smarter way to do it is to use a switch statement: Switch( {TABLE1.CODE} = "AQTCO1", AQTCO1[3], {TABLE1.CODE} = "AQTCO2", AQTCO1[3]) and so forth. There may be another way that is better, but still need to do a comparison of the database value to your various codes.
 
I'm thinking you should be able to write a function to do it. I'll have to play with it and see if that will work.
 
Is a two-dimensional array an option to look at ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top