注册 登录
编程论坛 VB6论坛

改了很久也没改对,大神啊,来看看把,急死了!~!

VB丶小宇 发布于 2013-03-13 11:07, 444 次点击
Private Sub CmdCalculate_Click()
Dim a, b, c, m, n As Integer
a = 1
b = 1
m = 2
n = TxtInput.Text2
Do
c = a + b
m = m + 1
a = b
b = c
Loop While c < n
LblResult.Caption = m
End Sub
Private Sub CmdExit_Click()
End
End Sub
Private Sub Form_Load()
TxtProblem.Text = "  有一对小兔子,长到第3个月时生出一对小兔子,以后每个月都生出一对小兔子,而所有出生的成对小兔子都和第一对兔子的繁殖规律相同。"
TxtProblem.Locked = True
TxtInput.Text2 = ""
LblResult.Caption = ""
End Sub
Private Sub TxtInput_KeyPress(Index As Integer, KeyAscii As Integer)
LblResult.Caption = ""
If KeyAscii < 0 Or KeyAscii > 9 Then KeyAscii = 0
End Sub
一运行就会出现
编译错误:
未找到方法或数据成员
调试,黄色箭头指向Private Sub Form_Load()这一行,请求大神,怎么改!~
5 回复
#2
yz10252013-03-13 11:24
看不懂程式在做啥~但是这样可以运行~
程序代码:

Option Explicit

Private Sub CmdCalculate_Click()
Dim a, b, c, m, n As Integer

    a = 1
    b = 1
    m = 2
    n = Val(TxtInput(0).Text)
    Do
        c = a + b
        m = m + 1
        a = b
        b = c
    Loop While c < n
   
    LblResult.Caption = m
   
End Sub

Private Sub CmdExit_Click()
    End
End Sub

Private Sub Form_Load()
    TxtProblem.Text = "  有一对小兔子,长到第3个月时生出一对小兔子,以后每个月都生出一对小兔子,而所有出生的成对小兔子都和第一对兔子的繁殖规律相同。"
    TxtProblem.Locked = True
    TxtInput(0).Text = ""
    LblResult.Caption = ""
End Sub

Private Sub TxtInput_KeyPress(Index As Integer, KeyAscii As Integer)
    LblResult.Caption = ""
'    If KeyAscii < 0 Or KeyAscii > 9 Then KeyAscii = 0
End Sub
#3
VB丶小宇2013-03-13 11:35
回复 2楼 yz1025
万分感谢,照你做的改了,可以运行了,运行正常。万分感谢。
#4
lowxiong2013-03-13 12:07
1、TxtInput.Text2 = ""   改为TxtInput=""
2、Private Sub TxtInput_KeyPress(Index As Integer, KeyAscii As Integer)去掉index,除非你用了控件数组,如果真用了控件数组,则前面关于TxtInput的用法都需要带上数组编号,即TxtInput(编号)。这一句应改为Private Sub TxtInput_KeyPress(KeyAscii As Integer)
3、If KeyAscii < 0 Or KeyAscii > 9 Then KeyAscii = 0这一句是想让文本框只能输入数字,因此方法错误,应改成对0和9的asc码的判断,这句改为If KeyAscii < Asc("0") Or KeyAscii > Asc("9") Then KeyAscii = 0
4、n = TxtInput.Text2  同样应改为n = TxtInput

附上做好的工程文件,关于小兔子的算法未考虑,你自己看看,希望早日入门
只有本站会员才能查看附件,请 登录
#5
VB丶小宇2013-03-13 12:39
回复 4楼 lowxiong
万分感谢,已经按照您说的分析,问题解决。
#6
zhengang10262013-03-13 15:11
lowxiong是个大好人兼VB高手,让你知其然还让你知其所以然,我就曾得益于他的许多帮助。
1