Reputation: 15
I have a form and a button and a table with two lists (list1 , list2)
in the form I have text box named text2
when pressing the command button it replaces list1 with text2 value using (replace list1 with thisform.text2.value)
but for list2 I want it to be "alpha" if I wrote number 7009 in text2 and "beta" if I wrote number 7004 in text2
what is the correct way to write the command in the button?
I tried
if thisform.text2.value=7009
replace list2 with "alpha"
else thisform.text.2value=7005
replace list 2 with "beta"
endif
I even tried rewriting the code with and without the "" and it seemed to have bunch of errors without writing it
and when I do write them it just ignores the command and decides to replace list2 with "beta" regardless of the number I wrote
Upvotes: 0
Views: 52
Reputation: 15
I fixed the issue and what needed to be happen is the folllowing:
APPEND blank
Do CASE
case thisform.text2.value="7009"
replace list2 with "alpha"
case thisform.text2.value="7004"
replace list2 with "beta"
OTHERWISE
ENDCASE
replace list1 with thisform.text2.value
thisform.text2.value=SPACE(4)
thus doing case and adding ("") for all values since it's not numerical based, and adding otherwise at the end then endcase, after the button is clicked it should move on in the form and replace text2 with spaces so we can write again without erasing what's already there.
Upvotes: 0
Reputation: 23837
(You started describing your problem with saying list objects on form and then doing replacement on a field called list2. So I would assume your question was not stated correctly and you meant to replace list2 field)
If you want to use if ... endif:
if thisform.text2.value=7009
replace list2 with "alpha"
endif
if thisform.text2.value=7005
replace list2 with "beta"
endif
Or you can use DO case...endcase:
Do case
case thisform.text2.value=7009
replace list2 with "alpha"
case thisform.text2.value=7005
replace list2 with "beta"
endcase
Or you could use iCase():
replace list2 with iCase(;
thisform.text2.value=7009, "alpha",;
thisform.text2.value=7005, "beta")
Note that iCase() version, unlike others, would attempt to do a replace if the value is not 7009 nor 7005. And it would attempt to replace with a NULL. That might cause error if your field is not accepting nulls. It is better to include an "otherwise" value:
replace list2 with iCase(;
thisform.text2.value=7009, "alpha",;
thisform.text2.value=7005, "beta",;
"")
Upvotes: 0