VB:缺少子程序、函数或属性是怎么回事?
OptionExplicitPrivateTypezgzghAsString*3xmAsString*3gzAsString*3EndTypeDima(0To4)Aszg...
Option Explicit
Private Type zg
zgh As String * 3
xm As String * 3
gz As String * 3
End Type
Dim a(0 To 4) As zg, i%
Dim N%
Private Sub command1_click()
i = i + 1
If i > 4 Then MsgBox "最多可存放5人的数据": Exit Sub
With a(i)
.zgh = Val(Text1)
.xm = Text2
.gz = Val(Text3)
End With
Text1 = "": Text2 = "": Text3 = ""
End Sub
Private Sub Command2_Click()
Dim i%, j%, t As zg
For i = 0 To 3
For j = i + 1 To 4
If a(i).gz > a(j).gz Then t = a(i): a(i) = a(j): a(j) = t
Next j
Next i
For j = 0 To 4
Picture1.Print a(j).zgh; a(j).xm: a(j).gz
Next j
End Sub 展开
Private Type zg
zgh As String * 3
xm As String * 3
gz As String * 3
End Type
Dim a(0 To 4) As zg, i%
Dim N%
Private Sub command1_click()
i = i + 1
If i > 4 Then MsgBox "最多可存放5人的数据": Exit Sub
With a(i)
.zgh = Val(Text1)
.xm = Text2
.gz = Val(Text3)
End With
Text1 = "": Text2 = "": Text3 = ""
End Sub
Private Sub Command2_Click()
Dim i%, j%, t As zg
For i = 0 To 3
For j = i + 1 To 4
If a(i).gz > a(j).gz Then t = a(i): a(i) = a(j): a(j) = t
Next j
Next i
For j = 0 To 4
Picture1.Print a(j).zgh; a(j).xm: a(j).gz
Next j
End Sub 展开
3个回答
展开全部
Option Explicit
'定义修改下类型更好
Private Type zg
zgh As Integer
xm As String * 3
gz As Integer
End Type
Dim a(0 To 4) As zg, i%
Private Sub command1_click()
i = i + 1
If i > 4 Then MsgBox "最多可存放5人的数据": Exit Sub
With a(i)
.zgh = Val(Text1)
.xm = Text2
.gz = Val(Text3)
End With
Text1 = "": Text2 = "": Text3 = ""
End Sub
Private Sub Command2_Click()
Dim i%, j%, t As zg
Picture1.Cls
For i = 0 To 3
For j = i + 1 To 4
If a(i).gz > a(j).gz Then t = a(i): a(i) = a(j): a(j) = t
Next j
Next i
For j = 0 To 4
Picture1.Print a(j).zgh; a(j).xm; a(j).gz '这里“:”改成“;”
Next j
End Sub
'复制下
'可以执行了。。。
'定义修改下类型更好
Private Type zg
zgh As Integer
xm As String * 3
gz As Integer
End Type
Dim a(0 To 4) As zg, i%
Private Sub command1_click()
i = i + 1
If i > 4 Then MsgBox "最多可存放5人的数据": Exit Sub
With a(i)
.zgh = Val(Text1)
.xm = Text2
.gz = Val(Text3)
End With
Text1 = "": Text2 = "": Text3 = ""
End Sub
Private Sub Command2_Click()
Dim i%, j%, t As zg
Picture1.Cls
For i = 0 To 3
For j = i + 1 To 4
If a(i).gz > a(j).gz Then t = a(i): a(i) = a(j): a(j) = t
Next j
Next i
For j = 0 To 4
Picture1.Print a(j).zgh; a(j).xm; a(j).gz '这里“:”改成“;”
Next j
End Sub
'复制下
'可以执行了。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个源代码有2个地方错误:
1、经调试,Picture1.Print a(j).zgh; a(j).xm: a(j).gz错把;打错为:。
2、最多可存放5人的数据,经调试,这个程序只能存储4个数据,打印出来也是4个数据。
经修改后的代码为:
Option Explicit
Private Type zg
zgh As String * 3
xm As String * 3
gz As String * 3
End Type
Dim a(5) As zg, i%
Dim N%
Private Sub command1_click()
i = i + 1
If i > 5 Then MsgBox "最多可存放5人的数据": Exit Sub
With a(i)
.zgh = Val(Text1)
.xm = Text2
.gz = Val(Text3)
End With
Text1 = "": Text2 = "": Text3 = ""
End Sub
Private Sub Command2_Click()
Dim i%, j%, t As zg
For i = 1 To 4
For j = i + 1 To 5
If a(i).gz > a(j).gz Then t = a(i): a(i) = a(j): a(j) = t
Next j
Next i
For j = 1 To 5
Picture1.Print a(j).zgh; a(j).xm; a(j).gz
Next j
End Sub
1、经调试,Picture1.Print a(j).zgh; a(j).xm: a(j).gz错把;打错为:。
2、最多可存放5人的数据,经调试,这个程序只能存储4个数据,打印出来也是4个数据。
经修改后的代码为:
Option Explicit
Private Type zg
zgh As String * 3
xm As String * 3
gz As String * 3
End Type
Dim a(5) As zg, i%
Dim N%
Private Sub command1_click()
i = i + 1
If i > 5 Then MsgBox "最多可存放5人的数据": Exit Sub
With a(i)
.zgh = Val(Text1)
.xm = Text2
.gz = Val(Text3)
End With
Text1 = "": Text2 = "": Text3 = ""
End Sub
Private Sub Command2_Click()
Dim i%, j%, t As zg
For i = 1 To 4
For j = i + 1 To 5
If a(i).gz > a(j).gz Then t = a(i): a(i) = a(j): a(j) = t
Next j
Next i
For j = 1 To 5
Picture1.Print a(j).zgh; a(j).xm; a(j).gz
Next j
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Print a(j).zgh; a(j).xm: a(j).gz
此句之所以出错是因为a(j).gz前面的冒号!
VB中冒号代表着前面的语句结束,其后将开始新的语句
但是在冒号后面是a(j).gz,这并不能算是一个语句或者函数的调用,所以出错,更改时只要将冒号换为Print语句中常用的分号“;”即可:
Print a(j).zgh; a(j).xm; a(j).gz
此句之所以出错是因为a(j).gz前面的冒号!
VB中冒号代表着前面的语句结束,其后将开始新的语句
但是在冒号后面是a(j).gz,这并不能算是一个语句或者函数的调用,所以出错,更改时只要将冒号换为Print语句中常用的分号“;”即可:
Print a(j).zgh; a(j).xm; a(j).gz
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询