learner
9th January 2003, 09:54
For Loop basic question

I have about 20 item fields on form, the name of the form fields are
mitm.1
mitm.2
mitm.3
mitm.4
..........
.......
......
....
...
mitm.20

having domain as tcitem

now i want to clear all the fields using a for loop

so i wrote

field.mitm.2:
before.input:
if isspace(mitm.1) then
cle(2)
attr.input = false
endif

|********************* function section ****************

functions:
function cle(long a)
{
for tm = a to 4
mitm.tm = ""
endfor
}

It gives me the followng error Unresol;ved reference to function mitm

the error i undertood since mitm.tm is not an array, but how do i clear all these fields with a for loop, rather than clearing fields individually ...........????

Please not that i would not like to declared mitm field as array, since i am customizing a session which is already very complicated and it has used these variables .

Natasha
9th January 2003, 10:13
You should use array

domain tcitem mitm(20)

field.mitm:
before.input:
if isspace(mitm(1,attr.element)) then
cle(attr.element)
attr.input = false
endif

|********************* function section ****************

functions:
function cle(long a)
{
for tm = a to 4
mitm(1,tm) = ""
endfor
}

learner
9th January 2003, 10:56
can it be done without usng arrays ?

if not then how can i achieve the result withot using arrays ???

Natasha
9th January 2003, 11:15
Why are you trying avoid using arrays?

Paul P
9th January 2003, 12:30
Dear learner,

Since mitm.1 ... mitm.20 are already used in the complicated script, you would rather use them than use new array. Of course people like to use loop so they can write less code. But in your case, with those limitations, it is so much easier if you put something like this
field.mitm.1:
when.field.changes:
if isspace(mitm.1) then
mitm.2=""
display("mitm.2")
...
mitm.20=""
display("mitm.20")
endif
Beside, you can use cut and paste to make this job easier

Rgds,
Paul

jaapzwaan
9th January 2003, 13:20
Although i think that the best solution is to use arrays, there is an alternative:


function cle(long a)
{
long tm
for tm = a to 20
put.var(pid, "mitm." & edit$(tm, "Z9"), "")
endfor
}


Note: this is not as fast as an array assignment, but given the circumstances it is the best possible solution.

Regards,
Jaap Zwaan

mark_h
9th January 2003, 14:08
You could also use set.mem (http://www.baanboard.com/programmers_manual_baanerp_help_functions_memory_operations_set_mem) if you changed it to an array. This will set all elements of an array - of course you would also need to do a display.all.

Mark