标题:[求助]一个关于用VB对随即文件读写操作的问题
只看楼主
redmouse12
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2007-9-13
 问题点数:0 回复次数:3 
[求助]一个关于用VB对随即文件读写操作的问题

我在学习VB“访问随即文件”时遇到一个程序搞不明白,请大家帮帮我。
要求就是利用随即文件保存学生成绩,可以输入学生的学号、姓名以及三门功课的成绩,浏览或删除数据。我向大家请教的问题是,为什么程序运行时不能达到Command2.Enabled = False和Command3.Enabled = False的效果。

代码如下:
Private Type cj
xm As String * 6
xh As String * 6
sx As Integer
yw As Integer
wy As Integer
End Type
Private da As cj

Private Sub Command1_Click()
For i = 0 To 4
Text1(i).Text = ""
Next
Text1(0).SetFocus

End Sub

Private Sub Command2_Click()
Dim lastrec As Integer
With da
.xh = Text1(0).Text
.xm = Text1(1).Text
.yw = Val(Text1(2).Text)
.wy = Val(Text1(3).Text)
.sx = Val(Text1(4).Text)
End With
Open "xsda2.dat" For Random As #1 Len = Len(da)
lastrec = LOF(1) / Len(da)
Put #1, lastrec + 1, da
Close #1
Call Form_Load
Text1(0).SetFocus


End Sub

Private Sub Command3_Click()
Dim lastrec As Integer
recnum = List1.ListIndex + 1
Open "rec.tem" For Random As #1 Len = Len(da)
Open "xsda2.dat" For Random As #2 Len = Len(da)
lastrec = LOF(2) / Len(da)
For n = 1 To lastrec
If n <> recnum Then
Get #2, n, da
Put #1, , da
Else
Get #2, n, da
With da
Text1(0).Text = .xh
Text1(1).Text = .xm
Text1(2).Text = .yw
Text1(3).Text = .wy
Text1(4).Text = .sx
End With
End If
Next
Close #1
Close #2
Kill "xsda2.dat"
Name "rec.tem" As "xsda2.dat"
Call Form_Load
Text1(0).SetFocus


End Sub

Private Sub Form_Load()
Dim lastrec As Integer
Open "xsda2.dat" For Random As #1 Len = Len(da)
lastrec = LOF(1) / Len(da)
List1.Clear
For n = 1 To lastrec
Get #1, n, da
With da
xh = Format(.xh, "@@@@@@")
xm = Format(RTrim(.xm), "@@@@")
yw = Format(.yw, "####")
sx = Format(.sx, "####")
msg = xh & xm & "" & yw & "" & wy & "" & sx
End With
List1.AddItem msg
Next
Close #1
If List1.ListIndex > -1 Then
Command2.Enabled = False
Else
Command2.Enabled = True
End If


End Sub

Private Sub List1_Click()
If List1.ListIndex > -1 Then
Command3.Enabled = True
Else
Command3.Enabled = False
End If

End Sub


附件: 游客没有浏览附件的权限,请 登录注册
搜索更多相关主题的帖子: 文件 Integer Private String False 
2007-10-23 00:04
redmouse12
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2007-9-13
得分:0 
附件为我设置的界面,请大家帮忙看下吧。我就不明白为什么不能使“添加”“删除”那两个按纽弄成“灰色”即不可点击状态。
2007-10-23 00:06
悠蓝
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2007-10-23
得分:0 
。。。。。以前碰到过``忘记了````貌似灰的要用true``你试过没。。
VB删掉了没办法弄``如果错了别见怪哦``呵呵``
2007-10-23 10:54
redmouse12
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2007-9-13
得分:0 

“灰的”应该是Command2.Enabled = False这样吧,但我这程序就是实现不了

2007-10-23 16:28



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-179938-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.350977 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved