51Testing软件测试论坛

标题: 赋值语句和条件语句 [打印本页]

作者: urral    时间: 2006-8-3 09:25
标题: 赋值语句和条件语句
For i=0 to 3
        If dData(i)=IP(i) And Mask(i) =dMask(i) Then
                result=1
             else  result=0
                      Exit for
           End If
Next
如上语句我希望实现当dData中值与IP中值相等,而且Mask中值与dMask中值相等时result为1。
但运行时我发现,当dData(i)=0,IP(i)=0,Mask(i)=0,dMask(i)=0,就是当4个值取值均为0时,result返回的值为0,如果我的语句是正确的话,这种情况下result应该为1啊?
各位大侠,应该怎么实现呢?
作者: claude    时间: 2006-8-3 09:47
标题: 能不能把代码弄全一点?
这段我在自己机器上跑了一下。个人认为没有问题。
作者: xiaonan    时间: 2006-8-3 09:48
首先vbscript是不定义数据类型的,它只有一种变体型.所以很有可能因为两个值的数据类型不匹配,导致比较下来不相等.所以在比较之前都强制转化一下相同的数据类型.比如:可能都用 cint 来强制成整型比较.看你的语法没什么问题,那很有可能这个原因
作者: claude    时间: 2006-8-3 09:51
标题: 你看看数组下标有没有问题?
你数组是怎么定义的,把代码发上来看看。
作者: urral    时间: 2006-8-3 11:28
Dim row,IP(4),Mask(4),dMask(4),dData(4)
JavaWindow("Configuration Management").JavaTree("JTree").Select "#0;Object Manager;Address Objects"
   row=JavaWindow("Configuration Management").JavaTable("JXTreeTable").GetROProperty("rows")
   row=row-1
   'msgbox row
JavaWindow("Configuration Management").JavaTable("JXTreeTable").SelectRow "#"&row&""
JavaWindow("Configuration Management").JavaButton("edit").Click
JavaWindow("Configuration Management").JavaDialog("Edit Address:address_1").JavaEdit("IP:").Set DataTable("IP_1", dtLocalSheet)
JavaWindow("Configuration Management").JavaDialog("Edit Address:address_1").JavaEdit(".").Set DataTable("IP_2", dtLocalSheet)
JavaWindow("Configuration Management").JavaDialog("Edit Address:address_1").JavaEdit("._2").Set DataTable("IP_3", dtLocalSheet)
JavaWindow("Configuration Management").JavaDialog("Edit Address:address_1").JavaEdit("._3").Set DataTable("IP_4", dtLocalSheet)
JavaWindow("Configuration Management").JavaDialog("Edit Address:address_1").JavaEdit("Netmask:").Set DataTable("Mask_1", dtLocalSheet)
JavaWindow("Configuration Management").JavaDialog("Edit Address:address_1").JavaEdit("._4").Set DataTable("Mask_2", dtLocalSheet)
JavaWindow("Configuration Management").JavaDialog("Edit Address:address_1").JavaEdit("._5").Set DataTable("Mask_3", dtLocalSheet)
JavaWindow("Configuration Management").JavaDialog("Edit Address:address_1").JavaEdit("._6").Set DataTable("Mask_4", dtLocalSheet)
JavaWindow("Configuration Management").JavaDialog("Edit Address:address_1").JavaButton("ok").Click
'JavaWindow("Configuration Management").JavaDialog("Edit Address:QQQQ").JavaEdit("IP:").Set "11"
JavaWindow("Configuration Management").JavaTable("JXTreeTable").SelectRow "#"&row&""
JavaWindow("Configuration Management").JavaButton("edit").Click
   IP(0)=JavaWindow("Configuration Management").JavaDialog("Edit Address:address_1").JavaEdit("IP:").GetROProperty("value")
   IP(1)=JavaWindow("Configuration Management").JavaDialog("Edit Address:address_1").JavaEdit(".").GetROProperty("value")
   IP(2)=JavaWindow("Configuration Management").JavaDialog("Edit Address:address_1").JavaEdit("._2").GetROProperty("value")
   IP(3)=JavaWindow("Configuration Management").JavaDialog("Edit Address:address_1").JavaEdit("._3").GetROProperty("value")
   Mask(0)=JavaWindow("Configuration Management").JavaDialog("Edit Address:address_1").JavaEdit("Netmask:").GetROProperty("value")
   Mask(1)=JavaWindow("Configuration Management").JavaDialog("Edit Address:address_1").JavaEdit("._4").GetROProperty("value")
   Mask(2)=JavaWindow("Configuration Management").JavaDialog("Edit Address:address_1").JavaEdit("._5").GetROProperty("value")
   Mask(3)=JavaWindow("Configuration Management").JavaDialog("Edit Address:address_1").JavaEdit("._6").GetROProperty("value")
   JavaWindow("Configuration Management").JavaDialog("Edit Address:address_1").JavaButton("ok").Click
   dMask(0)=DataTable("Mask_1", dtLocalSheet)
   dMask(1)=DataTable("Mask_2", dtLocalSheet)
   dMask(2)=DataTable("Mask_3", dtLocalSheet)
   dMask(3)=DataTable("Mask_4", dtLocalSheet)
For i=0 to 3
        j=i+1
        If dMask(i)=255 Then
                dData(i)=DataTable("IP_"&j&"", dtLocalSheet)
           ' msgbox dData(i)
                else  dData(i)=0
                'msgbox dData(i)
        End If
Next

For i=0 to 3
        If dData(i) < IP(i) And Mask(i) <dMask(i) Then
                         result=0
                         Exit for
        elseif dData(i) > IP(i) And Mask(i) >dMask(i) then
                    result=0
                                Exit for
        else  result=1
        End If
Next
'msgbox result
If result=0 Then
         Reporter.ReportEvent micFail,"edit address", "failed,please check"
         else
         Reporter.ReportEvent micDone,"edit address", "successfully"
End If
JavaWindow("Configuration Management").JavaTree("JTree").Select "#0;Object Manager;Address Objects"
全部代码如上:
我现在将上面部分改为

For i=0 to 3
        If dData(i) < IP(i) And Mask(i) <dMask(i) Then
                         result=0
                         Exit for
        elseif dData(i) > IP(i) And Mask(i) >dMask(i) then
                    result=0
                                Exit for
        else  result=1
        End If
Next
就可以运行成功了




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2