【问题标题】:Understanding Foxpro IF Statement了解 Foxpro IF 语句
【发布时间】:2019-01-02 01:24:53
【问题描述】:

我不确定我的标题应该是什么,如果你能想出更好的东西,请随时编辑我的帖子并更改它。

关于 Foxpro 使用的可用资源并不多,我想做的是了解发生了什么。

lldisdead=.t.

Select .f. as chkbox, * from a_counties ;
    order by cn_area, cn_desc ;
    into dbf (StrTmpFile1)


scan while !EOF()
     IF ChkBox
          selected_some_cnty = .t
     endif
endscan

这是我的理解:

  • 只要您不在最后一条记录中,请执行以下操作 表:
  • 如果检查框
  • 设置 selected_some_cnty 等于 .t
  • 停止检查下一条记录
  • 继续这样做,直到您的记录用完为止。

IF CHKBOX 是什么意思?

如果 CHKBOX 列不为空,是否表示,请执行以下操作, 否则,什么都不做。

编辑:添加附加代码

【问题讨论】:

  • IF 测试一个逻辑(布尔)表达式,因此该表达式等于IF ChkBox = .T.。根据您发布的内容,我们无法知道 ChkBox 是什么 - 您必须阅读其余代码才能找到答案。 EOF()End Of File,所以!EOF() 表示不是文件结尾(IOW,在最后一条记录之后)。
  • 编辑了我的帖子。

标签: visual-foxpro


【解决方案1】:
If chkBox

在 VFP 中,表示:

if (chkBox)

也适用于所有其他知名语言,如 C、C++、C#、Java、Go、Dart、Ruby ……您可以命名它 - 有些语言的括号是强制性的,有些则不是。它只是表示“如果 chkBox 为真”。有时你会看到它写成:

If chkBox = .T.

喜欢:

If chkBox == true

和其他语言一样,但它比需要的更冗长,而且经验丰富的开发人员不会那样写(毕竟像“if true is true”这样的写法很尴尬,只是“如果为真”很好)。

这用代码中的 cmets 来解释:

* Initialize a memory variable named lldisdead as .t. (true)

lldisdead=.t.

* Select some fields into a table named m.StrTmpFile1
* StrTmpFile1 is a variable holding a string name of the table
* selecting all fields of a_counties table
* plus a boolean field named "chkBox" which is initially
* filled with .F. (false) value
Select .f. as chkbox, * from a_counties ;
    order by cn_area, cn_desc ;
    into dbf (StrTmpFile1)

* select's result table is table open in the current 
* work area and by default located on first record.
* scanning the whole table
* with an unnecessary "while !EOF()" addition
* Default scope of scan is until EOF 
scan while !EOF()
     * Checking if chkBox field has a value of true
     IF ChkBox 
          * if it has, than set "selected_some_cnty" memory variable to true
          selected_some_cnty = .t 
     endif
endscan

话虽如此,这部分:

scan while !EOF()
     IF ChkBox 
          selected_some_cnty = .t. 
     endif
endscan

可以写成:

scan
     IF ChkBox 
          selected_some_cnty = .t 
     endif
endscan

进一步:

LOCATE FOR ChkBox 
selected_some_cnty = !EOF() 

但是,由于我们知道所有 chkBox 的值都是 .F.,那段代码完全没有用,可以一起删除。

【讨论】:

    【解决方案2】:

    从 SQL 查询中,数据将根据名称“StrTmpFile1”变量指向的任何内容进入物理表。另请注意,此选择语句中的第一列是“.f. as ChkBox”。因此,这是在查询中使用始终为 False 的前导列准备每条记录(因此 .f.)

    Select .f. as chkbox, * from a_counties ;
        order by cn_area, cn_desc ;
        into dbf (StrTmpFile1)
    

    现在,我怀疑还有其他一些用户界面操作正在使用此结果表,例如在表格中的网格中显示并允许列上的复选框让用户选择一个或多个条目以做进一步的事情.

    在所述选择之后(再次推测意图),它通过循环仅查找那些“ChkBox”列在表中已设置为 true 并将标志设置为 .t 的记录。选择了某样东西。

    总的来说,这是一种非常新手的方法,但这是一个不同的问题。如果标记为记录,则获得答案的捷径是

    select (the table)
    Locate for ChkBox
    selected_some_cnty = found()
    

    希望这会有所帮助,如果您需要进一步说明,请发表评论。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-22
      相关资源
      最近更新 更多