vb中实时错误13是什么意思
Dim a() As Integer
Private Sub Text1_click()
Dim i As Integer
Dim n As Integer
n = Text1.Text
ReDim a(n) As Integer
For i = 1 To n
'for循环i从1变化到n'
a(i) = Int(20 * Rnd)
'INT为返回不大于给定数的最大整数见46页'
'rnd为产生随机数
labe12.Caption = labe12.Caption & a(i) & ","
Next i
End Sub
Private Sub Text1_Change()
labe12.Caption = "随机数是:"
End Sub
启动后填写数据提示 实时错误13,请问什么意思
Option Base 1
Dim a() As Integer
Private Sub Text1_click()
Dim i ,n As Integer
n = Text1.Text
ReDim a(n) As Integer
For i = 1 To n 展开
根据你的需求;我将程序改成了如下:
Option Base 1
Dim a() As Integer
Private Sub Text1_click()
Call Text1_Change
Dim i As Integer
Dim n As Integer
n = Val(Text1.Text)
If n < 1 Then Exit Sub
ReDim a(n) As Integer
For i = 1 To n
'for循环i从1变化到n'
a(i) = Int(20 * Rnd)
'INT为返回不大于给定数的最大整数见46页'
'rnd为产生随机数
Label2.Caption = Label2.Caption & a(i) & ","
Next i
End Sub
Private Sub Text1_Change()
Label2.Caption = "随机数是:"
End Sub
【另:类型不匹配错误详细解释,来自MSDN】
解决办法:用Val()函数将字符串型强制转换成整型。
以下介绍来自VB对象浏览器
Function Val(String As String) As Double
VBA.Conversion 的成员
返回在一个字符串中包含的数值
2024-09-04 广告
n = Text1.Text
你定义的n 是整型,而text1.text不是整数字,就出现此错误
你在
n = Text1.Text
之前加上句赋值语句,如Text1.Text = 5就可以了
还是不行,做的是:由一个输入n值后,自动产生n个20以内的随机数,输出这些数,麻烦你了,
Option Base 1
Option Base 1
Dim a() As Integer
Private Sub Form_Load()
Text1.Text = 10
End Sub
Private Sub Text1_Change()
aa
End Sub
Private Sub Text1_click()
aa
End Sub
Private Sub aa()
Label2.Caption = "随机数是:"
Dim i As Integer
Dim n As Integer
n = val(Text1.Text)
ReDim a(n) As Integer
For i = 1 To n
'for循环i从1变化到n'
a(i) = Int(20 * Rnd)
'INT为返回不大于给定数的最大整数见46页'
'rnd为产生随机数
Label2.Caption = Label2.Caption & a(i) & ","
Next i
End Sub