最近写vb程序
使用if条件语句
结果发现如果使用
if a<2 then 
....
end if
当a>=2的时候就不再执行中间的语句
但是一旦改为
temp=2
if a<temp then 
...
end if
后,判断条件就失效了,即使a>=2了也还是继续执行中间的语句
(所有变量都声明了的)请高手帮我看看这到底是为什么?

解决方案 »

  1.   

    绝对没有可能的事情~~是不是中途temp值被改了?
      

  2.   

    定义的变量类型是不是有问题,是不是同一种类型的(a 与 temp)
      

  3.   

    肯定是你的temp值发生了变化,否则不可能出现这样的情况的,要是真的出现这样的情况,那你的编译器可能出问题了,重装系统吧
      

  4.   

    可能的原因:
    1、使用了On error Resume next
    2、temp的数据类型有问题
      

  5.   

    多数情况下不是VB的Bug而是代码的Bug.但不少人还是怀疑VB的Bug.人总是自信的。唉------
      

  6.   

    我怀疑你是少了exit sub, end sub之类的,退出
      

  7.   

    应该是代码的问题,估计原因是temp和a的变量类型有问题。
      

  8.   

    可能是:
    1、TEMP变化了;
    2、用了on error resume next并且判断语句有错误;
    3、可能a或者TEMP的类型有问题(如String型);
    4、你在耍大家玩。
      

  9.   

    1。也許a、temp定義為全局變量,在其它過程中有賦值產生
    2。查查數據類型
      

  10.   

    为了让大家更好分析这个问题
    我贴出源代码
    (与之无关部分和控件部分省略)
    本人刚接触vb
    这是一个课程设计中发现的问题
    如果问题真的很低级
    请大家口下留情Dim group(2, 5, 10) As Integer
    Dim all As Integer
    Public choice, error, delay, flag1, flag2 As Integer
    Public dtime, send As Integer
    Private Sub Command1_Click()
    choice = 1
    End SubPrivate Sub Command3_Click()
    Picture1.Cls
    all = 1
    send = InputBox("发送时间")
    dtime = InputBox("超时时间")
    error = InputBox("错误帧")
    choice = 2
    End Sub
    Private Sub Form_Load()
    all = 1
    choice = 0
    error = 3
    delay = 0
    For i = 1 To 20
    Label1(i).Caption = ""
    Next
    Picture1.Scale (0, 0)-(100, 50)
    For i = 1 To 10
     group(1, 1, i) = 3 + 10 * (i - 1)
     group(2, 1, i) = 8 + (i - 1) * 10
    NextEnd Sub
    Private Sub Timer1_Timer()
    Select Case choice
    Case 2
     If all <= error Then
     Picture1.Line (group(1, 1, all), 15)-(group(2, 1, all), 30)
     Label1(all).Caption = all
     End If
     
    If all < (error + send) And all >= send + 1 Then
    Picture1.Line (group(2, 1, all - send), 30)-(group(1, 1, all), 15)
    Label1(10 + all - send).Caption = all - send
     End IfIf delay = dtime  Then
     Picture1.Line (group(1, 1, (all - dtime - 1)), 15)-(group(2, 1, (all - dtime - 1)), 30), RGB(255, 0, 0)
     Label1(all - dtime - 1).Caption = all - dtime - 1If (all - dtime - send - 1) >= error Then
    Picture1.Line (group(2, 1, (all - dtime - send - 1)), 30)-(group(1, 1, (all - dtime - 1)), 15), RGB(255, 0, 255)
    Label1(10 + all - dtime - send - 1).Caption = (all - dtime - send - 1)
     End If
    End IfIf all > error And delay < dtime Then
     Picture1.Line (group(1, 1, all), 15)-(group(2, 1, all), 30)
     Label1(all).Caption = all
    delay = delay + 1
    End If
    all = all + 1End Select End Sub
      

  11.   

    运行的时候经过监控就是
    If delay = dtime  Then

    If all > error And delay < dtime Then中的delay 与dtime的比较失效了
      

  12.   

    Public choice, error, delay, flag1, flag2 As Integer
    Public dtime, send As Integer
    这种定义变量的方式就有问题
    VB6没这么好,你要具体定义Public choice As Integer, error As Integer, delay As Integer, flag1 As Integer, flag2 As Integer
    Public dtime As Integer, send As Integer
      

  13.   

    就如laisiwei所说,C++定义变量的语法在VB中是不行的
      

  14.   

    多谢laisiwei和gamestory
    按照你们说的
    问题解决了