了解 Foxpro IF 语句

Understanding Foxpro IF Statement

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

没有太多关于 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

这是我的理解:

IF CHKBOX 是什么意思?

Is it saying if the column CHKBOX is not null, do the following, otherwise, do nothing.

编辑:添加了附加代码

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

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

现在,我怀疑还有一些其他用户界面操作正在使用此结果 table,例如以表格形式呈现在网格中并允许在列上使用复选框让用户选择一个或更多条目可以做更多事情。

在说 selection 之后(再次推测意图),它将通过循环仅查找 TABLE 中的 "ChkBox" 列已设置为的那些记录true 并将标志设置为 .t。 selected.

总的来说,这是一个非常新手的方法,但这是一个不同的问题。如果标记的记录是

,则获取答案的捷径
select (the table)
Locate for ChkBox
selected_some_cnty = found()

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

If chkBox

在 VFP 中,表示:

if (chkBox)

还有所有其他众所周知的语言,如 C、C++、C#、Java、Go、Dart、Ruby、...你能想到的 - 有些语言括号是强制性的,有些不是。它只是表示“如果 chkBox 为真”。有时你会看到它写成:

If chkBox = .T.

喜欢:

If chkBox == true

与其他语言一样,但它比需要的更冗长,经验丰富的开发人员不会那样写(毕竟像“if true is true”这样的写法很尴尬, 只需“if true”即可。

这用代码中的注释进行了解释:

* 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.,那段代码完全没有用,可以一起删除。