Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Best Way to Loop through List of Values
#1
Hi -

I'm new to QM, but not new to programming.

I have a simple macro that is automating some data entry. I need the macro to loop through a list of values (value a, value b, value c) and execute once for each value. The list could be quite long and will change each time I need to execute it.

If I was doing this in VBA, I would create a recordset, go to the first record and incrementally get the values as I need them.

Is there a trick in QM that makes this easy (i.e., use a simple list of values in a txt file, .csv?, Excel?, Access?)

Any ideas?

Jason
#2
Macro Macro21
Code:
Copy      Help
str valueList=
;value1
;value2
;value3
;value4
;value5
out
str value
foreach value valueList
,sub.FillDataForm value

#sub FillDataForm
function str&value
out F"Fill form with '{value}'"
#3
Awesome. I got this to work.

One more question. What is the best way if I need to pass two variables in each line?

Like this:

Var A Var B
123 ABC
124 CDE
125 XYZ

Is there a simple trick for this using a simple list collection?
#4
Macro Macro12
Code:
Copy      Help
str valueList=
;123 ABC
;124 DEF
;125 UVW
;126 XYZ
out
ARRAY(str) a
str line
foreach line valueList
,tok(line a)
,;out F"{a[0]} {a[1]}"
,sub.FillDataForm val(a[0]) a[1]

#sub FillDataForm
function number str&value
out F"Fill form with '{number}' '{value}'"


Forum Jump:


Users browsing this thread: 1 Guest(s)