Visual FoxPro表单按钮命令问题:按文本框值替换字段内容
问题分析与正确代码实现
原代码存在的错误
else后不能直接追加条件判断,需改用elseif- 拼写错误:
thisform.text.2value应为thisform.text2.value;list 2应为list2 - 文本框
text2默认值类型为字符型,判断时需将数字用引号包裹(如"7009"),否则会因类型不匹配导致判断失效 - 需求中是输入7004替换为beta,原代码误写为7005
正确代码实现
假设text2为默认的字符型文本框,代码如下:
replace list1 with thisform.text2.value do case case thisform.text2.value = "7009" replace list2 with "alpha" case thisform.text2.value = "7004" replace list2 with "beta" && 可添加其他情况或默认处理 endcase
也可以用if-elseif结构:
replace list1 with thisform.text2.value if thisform.text2.value = "7009" replace list2 with "alpha" elseif thisform.text2.value = "7004" replace list2 with "beta" endif
如果text2设置为数值型(需在控件属性中修改Value类型为数值),则判断时不用加引号:
replace list1 with thisform.text2.value if thisform.text2.value = 7009 replace list2 with "alpha" elseif thisform.text2.value = 7004 replace list2 with "beta" endif
内容的提问来源于stack exchange,提问作者Arty Artanis
相关产品推荐
相关产品推荐

