You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 01:17:04