|
原帖由 kanebluba 于 2008-1-31 10:10 发表
Dim MyValue As Integer, temp As Integer, temp1 As Integer, toNum As Integer, fromNum As Integer, step As Integer, sign As Integer
Private Sub Form_Activate()
fromNum = InputBox("输入起始数")
...
呵呵,小朱来了我顶你一下
估计你以前是用标准VB或者VBA的吧,QTP用VBS的,所以代码调不通,我改了一下,但是没测试过你的代码,不知道功能是不是实现,以下你的代码可以调的通:
'Dim MyValue As Integer, temp As Integer, temp1 As Integer, toNum As Integer, fromNum As Integer, step As Integer, sign As Integer
Private Sub Form_Activate()
fromNum = InputBox("输入起始数")
toNum = InputBox("输入结束数")
step = InputBox("输入间隔")
If (fromNum < 0 Or toNum < 0) Then
MsgBox ("不能小于0")
sign = 1
Else
temp1 = toNum - fromNum
If (temp1 < 0) Then
MsgBox ("起始数小于结束数")
sign = 1
Else
If (temp1 <= 10) Then
Randomize
MyValue = Int(((toNum - fromNum) * Rnd) + (fromNum))
Print MyValue
sign = 1
Else
If (temp1 >= 10) Then
temp = (toNum - fromNum) / step - 1
End If
End If
End If
End If
For i = 1 To temp
Randomize
MyValue = Int(step * Rnd) + fromNum
fromNum = fromNum + 8
Print MyValue
Next
'补最后一次
If (sign = 0) Then
Randomize
MyValue = Int(((toNum - fromNum) * Rnd) + (fromNum))
Print MyValue
End If
End Sub
另外这样的话会更好:
1.定义变量最好在函数体里面的
2.代码要保持队形(锯齿形结构)
3.多余的空行最好删除,代码要容易阅读,可以参考一下林锐的《高质量C++编程》,我还是很推崇的,是关于代码规范的书,加油
[ 本帖最后由 yuandjing 于 2008-2-1 12:15 编辑 ] |
|