初学:程序运行到 FilePut(1, Person, RecCount)报错,请各位大神指点

mini_Gui 2019-08-23 05:35:46
保存代码如下:
Private Sub btnSAVE_Click(sender As Object, e As EventArgs) Handles btnSAVE.Click
Dim Person As AdressList '结构体变量,用于保存文件中的一条记录
Dim RecCount As Integer '文件中的记录总数
Dim I As Integer
If Trim(txtNUM.Text) = "" Then '编号为零,退出本过程
MsgBox("编号不能为空")
txtNUM.Focus()
Exit Sub
End If
txtNUM.Text = Convert.ToString(Val(txtNUM.Text)) '清除文本框中的非数字字符
txtNUM.Text = Mid(txtNUM.Text + " ", 1, 4) '在编号后面补上空格
'返回首记录
If LOF(1) > 0 Then
FileGet(1, Person, 1)
End If
'判断新的编号在记录中是否存在
RecCount = 1
Do While EOF(1) = False
FileGet(1, Person, RecCount)
If Person.NUM = txtNUM.Text And State = "新记录" Then
MsgBox("相同的编号已经存在,请从新设置一个编号")
txtNUM.Text = ""
txtNUM.Focus()
Exit Sub
End If
RecCount = RecCount + 1
Loop
txtNAME.Text = Trim(txtNAME.Text)
If txtNAME.Text.Length = 0 Then
MsgBox("名字不能为空,请注意")
txtNAME.Focus()
Exit Sub
End If
Person.NUM = txtNUM.Text
Person.NAME = txtNAME.Text
Person.SEX = rbdMAN.Checked
Person.CITY = txtCITY.Text
Person.ADRESS = txtADRESS.Text
Person.PHONE = txtPHONE.Text
Person.CELL = txtCELL.Text
'准备写入文件
If State = "新记录" Then
RecCount = LastRec() + 1 '当前记录数 运行到此处报错,内容为{"错误的记录长度。"}
FilePut(1, Person, RecCount) '将新编码,姓名等增加到列表框中
istNAME.Items.Add(txtNUM.Text + "" + txtNAME.Text)

End If
If State = "编辑" Then
FilePut(1, Person, BookMark)
State = "新记录"
'改写列表框的内容
istNAME.Items.Clear()
RecCount = LastRec()
For I = 1 To RecCount
FileGet(1, Person, I)
istNAME.Items.Add(Person.NUM + "" + Person.NAME)

Next
End If
txtNUM.Text = ""
txtNAME.Text = ""
txtCITY.Text = ""
txtADRESS.Text = ""
txtPHONE.Text = ""
txtCELL.Text = ""
rbdMAN.Checked = True
txtNUM.Focus()
End Sub

通用函数过程 LastRec() 如下
Private Function LastRec() As Integer
Dim RecCount As Integer
'文件中的总记录数
Dim Person As AdressList
'结构体变量用于保存文件中的一条记录
If LOF(1) = 0 Then
'如果文件长度为0,则记录数为0
LastRec = 0
Exit Function

End If
RecCount = 1
FileGet(1, Person, RecCount)
Do While EOF(1) = False
RecCount = RecCount + 1
FileGet(1, Person, RecCount)
Loop
MsgBox("当前记录数为:" & istNAME.Items.Count & "" & RecCount & "条")
LastRec = RecCount
End Function
...全文
84 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
hztltgg 2019-08-27
  • 打赏
  • 举报
回复
是自学还是老师在教?你这学的是用vb.net的皮去套vb6的写法,可别误入歧途。

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧