vb随机文件的问题

来源:百度知道 编辑:UC知道 时间:2024/05/11 01:14:47
Private Type dater
name As String
edg As Integer
sex As String
End Type

Private Sub Command1_Click()
Dim pt As dater
Dim record_no As Integer

pt.name = Text1.Text
pt.edg = Val(Text2.Text)
If Option1.Value = 1 Then
pt.sex = "1"
Else
pt.sex = "0"
End If

Open App.Path & "\date.txt" For Random As #1
record_no = Val(Text3.Text)
Put #1, record_no, pt
Close #1

End Sub

Private Sub Command2_Click()
Dim pt As dater
Dim record_no As Integer
Open App.Path & "\date.txt" For Random As #1
record_no = Val(Text3.Text)
Get #1, record_no, pt
Text1.Text = pt.name
Text2.Text = Str(pt.edg)

Close #1
If pt.sex = "1" Then Option1.Value = 1

Else
Option2.Value = 1
End If
End Sub

提示错误是
编译错误
else 没有 if
那位能解决的,麻烦出来解答.谢谢!

主要是下面这段有错
If pt.sex = "1" Then Option1.Value = 1

Else
Option2.Value = 1
End If

这样改就对了

Private Type dater
name As String
edg As Integer
sex As String
End Type

Private Sub Command1_Click()
Dim pt As dater
Dim record_no As Integer

pt.name = Text1.Text
pt.edg = Val(Text2.Text)
If Option1.Value = 1 Then
pt.sex = "1"
Else
pt.sex = "0"
End If

Open App.Path & "\date.txt" For Random As #1
record_no = Val(Text3.Text)
Put #1, record_no, pt
Close #1

End Sub

Private Sub Command2_Click()
Dim pt As dater
Dim record_no As Integer
Open App.Path & "\date.txt" For Random As #1
record_no = Val(Text3.Text)
Get #1, record_no, pt
Text1.Text = pt.name
Text2.Text = Str(pt.edg)

Close #1
If pt.s