我正在尝试编写一个带有5个文本框值的基本函数。我想将前两个Box的值加倍,用它们替换它们以前的值,并将其他3个保存在数组中。然后我想要一个for循环来获取数组中的值并将它们的总和放在一个新的变量中,我想在一个单独的TextBox中显示它。
很抱歉提出这样一个奇怪的问题,但在工作中我刚开始学习传统,以解决FoxPro中的一堆问题。
答案 0 :(得分:1)
您可以将以下代码粘贴到新的PRG中,例如在命令窗口中键入Modify Command
,然后将其粘贴到那里。
LOCAL oForm as Form
oForm = CREATEOBJECT("TestForm")
oForm.Show(1)
RETURN
DEFINE CLASS TestForm as Form
AutoCenter = .T.
ADD OBJECT TextBox1 as TextBox WITH Left = 20, Top = 20, Value = 1
ADD OBJECT TextBox2 as TextBox WITH Left = 20, Top = 50, Value = 2
ADD OBJECT TextBox3 as TextBox WITH Left = 20, Top = 80, Value = 3
ADD OBJECT TextBox4 as TextBox WITH Left = 20, Top = 110, Value = 4
ADD OBJECT TextBox5 as TextBox WITH Left = 20, Top = 140, Value = 5
ADD OBJECT theOtherTextBox as TextBox WITH Left = 200, Top = 20
ADD OBJECT cmdTest as CommandButton WITH Left = 200, Top = 80
PROCEDURE cmdTest.Click
Thisform.TextBox1.Value = Thisform.TextBox1.Value * 2
Thisform.TextBox2.Value = Thisform.TextBox2.Value * 2
LOCAL ARRAY laTest[3]
STORE Thisform.TextBox3.Value TO laTest[1]
STORE Thisform.TextBox4.Value TO laTest[2]
STORE Thisform.TextBox5.Value TO laTest[3]
LOCAL lnSum, lnValue
lnSum = 0
FOR lnValue = 1 TO ALEN(laTest)
lnSum = m.lnSum + laTest[m.lnValue]
ENDFOR && or alternatively
lnSum = 0
FOR EACH lnValue IN laTest
lnSum = m.lnSum + m.lnValue
ENDFOR
Thisform.theOtherTextBox.Value = m.lnSum
ENDPROC
ENDDEFINE
FWIW,代码为文本的演示文稿仅适用于浏览器演示 - 在真正的VFP项目中,您可能宁愿在视觉形式或类设计师中设计“视觉”事物,祝你好运John Doe