vb中随机文件中如何删除与修改记录,急。请高手帮忙了!
PrivateSubCommand1_Click(IndexAsInteger)DimnAsIntegern=IndexIfn=0Then'添加Form2.ShowFor...
Private Sub Command1_Click(Index As Integer)
Dim n As Integer
n = Index
If n = 0 Then '添加
Form2.Show
Form2.Text1(6).Text = Str(Form1.List1.ListCount + 1)
ElseIf n = 1 Then '修改
t = Split(Form1.List1.ListIndex, ";")
Form2.Show
Form2.Command1.Visible = False: Form2.Command2.Visible = True
Form2.Text1(0) = t(1)
Form2.Text1(1) = t(2)
Form2.Text1(2) = t(3)
Form2.Text1(3) = t(4)
Form2.Text1(4) = t(5)
Form2.Text1(5) = t(6)
Form2.Text1(6) = t(0)
Form2.Text1(6).Locked = True
Form1.List1.RemoveItem List1.ListIndex
(在第2窗体里Private Sub Command2_Click()
today = Form2.Text1(0).Text
lenth(10) = Len(today)
bar1 = Mid(today, 5, 1): bar2 = Mid(today, 8, 1)
If lenth(10) = 10 And bar1 = bar2 And bar1 = "-" Then
With jl
.xa = Text1(6).Text
.xb = Text1(0).Text
.xc = Text1(1).Text
.xd = Text1(2).Text
.xe = Text1(3).Text
.xf = Text1(4).Text
.xg = Text1(5).Text
.xh = Combo1.Text
End With
h = Val(Text1(6).Text)
Open "vb期末作业.CLL" For Random As #4 Len = Len(jl)
lastrec = LOF(4) / Len(jl)
Put #4, h, jl
Close #4
Call Form1.Form_Load
Form2.Hide
Else
MsgBox ("添加失败,请检查填入数据是否正确")
End If
End Sub)
ElseIf n = 2 Then '删除
Open "vb期末作业.CLL" For Random As #1 Len = Len(jl)
Open "rec.CLL" For Random As #2 Len = Len(jl)
lastrec = LOF(1) / Len(jl)
recnum = Form1.List1.ListIndex + 1
w = 1
For i = 1 To laxtrec
If y <> recnum Then
Get #1, i, jl
Put #2, w, jl
w = w + 1
End If
Next i
Close #1
Close #2
Kill "vb期末作业.CLL"
Name "rec.CLL" As "vb期末作业.CLL"
Call Form1.Form_Load
End If
End Sub
我点删除它就把全部都删除了,点修改就说下标越界!!谢谢1
你说的我有弄啊 Private Type xx
xa As String * 3'序号
xb As String * 10
xc As String * 3
xd As String * 3
xe As String * 4 '''''
xf As String * 4
xg As String * 5 ''''''
xh As String * 2
End Type
Private jl As xx
form1.form_load 和form1.combo1.text几additeam也有的
删除的我马马乎乎弄好了,只是序号怎么让它从1到lastrec不会搞,现在急需怎么样实现修改啊!! 展开
Dim n As Integer
n = Index
If n = 0 Then '添加
Form2.Show
Form2.Text1(6).Text = Str(Form1.List1.ListCount + 1)
ElseIf n = 1 Then '修改
t = Split(Form1.List1.ListIndex, ";")
Form2.Show
Form2.Command1.Visible = False: Form2.Command2.Visible = True
Form2.Text1(0) = t(1)
Form2.Text1(1) = t(2)
Form2.Text1(2) = t(3)
Form2.Text1(3) = t(4)
Form2.Text1(4) = t(5)
Form2.Text1(5) = t(6)
Form2.Text1(6) = t(0)
Form2.Text1(6).Locked = True
Form1.List1.RemoveItem List1.ListIndex
(在第2窗体里Private Sub Command2_Click()
today = Form2.Text1(0).Text
lenth(10) = Len(today)
bar1 = Mid(today, 5, 1): bar2 = Mid(today, 8, 1)
If lenth(10) = 10 And bar1 = bar2 And bar1 = "-" Then
With jl
.xa = Text1(6).Text
.xb = Text1(0).Text
.xc = Text1(1).Text
.xd = Text1(2).Text
.xe = Text1(3).Text
.xf = Text1(4).Text
.xg = Text1(5).Text
.xh = Combo1.Text
End With
h = Val(Text1(6).Text)
Open "vb期末作业.CLL" For Random As #4 Len = Len(jl)
lastrec = LOF(4) / Len(jl)
Put #4, h, jl
Close #4
Call Form1.Form_Load
Form2.Hide
Else
MsgBox ("添加失败,请检查填入数据是否正确")
End If
End Sub)
ElseIf n = 2 Then '删除
Open "vb期末作业.CLL" For Random As #1 Len = Len(jl)
Open "rec.CLL" For Random As #2 Len = Len(jl)
lastrec = LOF(1) / Len(jl)
recnum = Form1.List1.ListIndex + 1
w = 1
For i = 1 To laxtrec
If y <> recnum Then
Get #1, i, jl
Put #2, w, jl
w = w + 1
End If
Next i
Close #1
Close #2
Kill "vb期末作业.CLL"
Name "rec.CLL" As "vb期末作业.CLL"
Call Form1.Form_Load
End If
End Sub
我点删除它就把全部都删除了,点修改就说下标越界!!谢谢1
你说的我有弄啊 Private Type xx
xa As String * 3'序号
xb As String * 10
xc As String * 3
xd As String * 3
xe As String * 4 '''''
xf As String * 4
xg As String * 5 ''''''
xh As String * 2
End Type
Private jl As xx
form1.form_load 和form1.combo1.text几additeam也有的
删除的我马马乎乎弄好了,只是序号怎么让它从1到lastrec不会搞,现在急需怎么样实现修改啊!! 展开
展开全部
描述不详细,只好简略贴出来一点:
1.简单删除:
dim i as long
dim a as xx
for i=lastrec to 要删的记录号 step -1
get #?,i,a
put #?,i-1,a
next
lastrec=lastrec-1
标准删除:
把除了要删记录号以外的记录考到另一个文件,再用该文件替换源文件。
相关函数:
filecopy 源文件路径,目标文件路径(文件复制)
kill 要删的文件路径(文件删除)
(路径均为String类型)
2.修改:
put #?,要改的记录号,改后的内容(自定义类型)
1.简单删除:
dim i as long
dim a as xx
for i=lastrec to 要删的记录号 step -1
get #?,i,a
put #?,i-1,a
next
lastrec=lastrec-1
标准删除:
把除了要删记录号以外的记录考到另一个文件,再用该文件替换源文件。
相关函数:
filecopy 源文件路径,目标文件路径(文件复制)
kill 要删的文件路径(文件删除)
(路径均为String类型)
2.修改:
put #?,要改的记录号,改后的内容(自定义类型)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你在2处的代码非常不全,较难提供建议。
1)缺
Form1.Form_Load事件代码
2)缺Form1.Combo1装载内容
3)缺Form1.List1.ListIndex内容
以下网址有相似问题的讨论和代码:
http://zhidao.baidu.com/question/42391753.html
http://zhidao.baidu.com/question/42391351.html
1)缺
Form1.Form_Load事件代码
2)缺Form1.Combo1装载内容
3)缺Form1.List1.ListIndex内容
以下网址有相似问题的讨论和代码:
http://zhidao.baidu.com/question/42391753.html
http://zhidao.baidu.com/question/42391351.html
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
什么玩意,代码又不全,最好把代码全贴出来
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询