| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 849 人关注过本帖
标题:随机文件读写问题
只看楼主 加入收藏
kbmjj123
Rank: 1
等 级:新手上路
帖 子:46
专家分:0
注 册:2009-3-10
结帖率:92.31%
收藏
 问题点数:0 回复次数:3 
随机文件读写问题
我自己写的源代码::
Private Type Student
    Student_ID As String * 8
    Student_Name As String * 6
    Student_score1 As Integer
    Student_score2 As Integer
    Student_score3 As Integer
End Type


Private stu As Student
Dim FileName As String
Dim intCurRecord As Integer
Dim intLastRecord As Integer
Dim intCount As Integer
Dim intFileNum As Integer



Private Sub Cmd_Exit_Click()
    End
End Sub

Private Sub Cmd_Next_Click()
    If intCurRecord < intLastRecord Then
        intCurRecord = intCurRecord + 1
    Else
        If MsgBox("已经是最后一条记录了,是否回到首记录?", vbYesNo + vbQuestion) = vbYes Then
            intCurRecord = 1
        ReadStudentInfo
        End If
    End If
   
    Get #intFileNum, intCurRecord, stu
    ReadStudentInfo
    Close
End Sub

Private Sub Cmd_Previde_Click()
    If intCurRecord > 1 Then
        intCurRecord = intCurRecord - 1
    Else
        MsgBox "已经到了第一条记录了!!!", vbInformation
    End If
   
    Get #intFileNum, intCurRecord, stu
    ReadStudentInfo
    Close
End Sub
Private Sub ReadStudentInfo()
    Text1.Text = stu.Student_ID
    Text2.Text = stu.Student_Name
    Text3 = stu.Student_score1
    Text4 = stu.Student_score2
    Text5 = stu.Student_score3
   
End Sub

Private Sub Form_Load()
    intFileNum = FreeFile()
    strFileName = App.Path & "\学生成绩信息.txt"
    Open strFileName For Random As #intFileNum Len = Len(stu)
    intLastRecord = LOF(1) / Len(stu)
   
    intCurRecord = 1
    If LOF(intFileNum) <> 0 Then
        Get #intFileNum, intCurRecord, stu
        ReadStudentInfo
    End If
End Sub


 
学生成绩单.zip (1.8 KB)

  实现不了额~~望高手帮忙啊
搜索更多相关主题的帖子: 随机 文件 
2010-06-28 04:11
bczgvip
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:66
帖 子:1310
专家分:5312
注 册:2009-2-26
收藏
得分:0 
程序代码:
Option Explicit

Private Type Student
    Student_ID As String * 8
    Student_Name As String * 6
    Student_score1 As Integer
    Student_score2 As Integer
    Student_score3 As Integer
End Type

Private stu As Student
Private FileName As String
Private intCurRecord As Integer
Private intLastRecord As Integer
Private intCount As Integer
Private intFileNum As Integer
Private strFileName As String

Private Sub Cmd_Exit_Click()
    Unload Me
End Sub

Private Sub Cmd_Next_Click()
    If intCurRecord < intLastRecord Then
        intCurRecord = intCurRecord + 1
    Else
        If MsgBox("已经是最后一条记录了,是否回到首记录?", vbYesNo + vbQuestion) = vbYes Then
            intCurRecord = 1
        ReadStudentInfo
        End If
    End If
   
    Get #intFileNum, intCurRecord, stu
    ReadStudentInfo
End Sub

Private Sub Cmd_OutputAll_Click()
    stu.Student_ID = Text1.Text
    stu.Student_Name = Text2.Text
    stu.Student_score1 = Text3.Text
    stu.Student_score2 = Text4.Text
    stu.Student_score3 = Text5.Text
    'Write #intFileNum, stu
    Put #intFileNum, , stu
End Sub

Private Sub Cmd_Previde_Click()
    If intCurRecord > 1 Then
        intCurRecord = intCurRecord - 1
    Else
        MsgBox "已经到了第一条记录了!!!", vbInformation
    End If
   
    Get #intFileNum, intCurRecord, stu
    ReadStudentInfo
End Sub

Private Sub ReadStudentInfo()
    Text1.Text = stu.Student_ID
    Text2.Text = stu.Student_Name
    Text3 = stu.Student_score1
    Text4 = stu.Student_score2
    Text5 = stu.Student_score3
End Sub

Private Sub Form_Load()
    intFileNum = FreeFile()
    strFileName = App.Path & "\学生成绩信息.txt"
    Debug.Print strFileName
    Open strFileName For Random As #intFileNum Len = Len(stu)
    intLastRecord = LOF(1) / Len(stu)
   
    intCurRecord = 1
    If LOF(intFileNum) <> 0 Then
        Get #intFileNum, intCurRecord, stu
        ReadStudentInfo
    End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Close #intFileNum
End Sub
2010-06-28 04:39
lucky563591
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:4
帖 子:765
专家分:2103
注 册:2009-11-18
收藏
得分:0 
I do not know
2010-06-28 06:19
kbmjj123
Rank: 1
等 级:新手上路
帖 子:46
专家分:0
注 册:2009-3-10
收藏
得分:0 
回复 2楼 bczgvip
但是我每次运行的时候,各科成绩不能正常显示出来~~还有当按下一条的时候~~出现无效的文件或号码呃~~
学生成绩信息.zip (577 Bytes)
~~这个是我写的数据~~请问怎样才能把它给正常显示出来额啊~~谢谢了~~~
2010-06-28 14:54
快速回复:随机文件读写问题
数据加载中...
 
   



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

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