| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
共有 1733 人关注过本帖
标题:开档案写档案
只看楼主 加入收藏
yz1025
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:6
帖 子:491
专家分:919
注 册:2012-10-26
结帖率:95.56%
收藏
已结贴  问题点数:20 回复次数:7 
开档案写档案
如何开档案逐行读取内容和
逐行写入阵列资料

发现书上的写法跟VB6差很多,用了AI给的代码好像不能用
若能给个简单范例就好了

[此贴子已经被作者于2024-5-16 15:45编辑过]

搜索更多相关主题的帖子: 档案 资料 VB6 逐行 代码 
2024-05-16 15:41
yiyanxiyin
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:9
帖 子:190
专家分:1338
注 册:2023-6-29
收藏
得分:20 
什么档案?一般txt文件还是word文档还是其他的?阵列资料又是什么?如果有明确的数据格式,给出格式
2024-05-16 15:48
yz1025
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:6
帖 子:491
专家分:919
注 册:2012-10-26
收藏
得分:0 
程序代码:
Private Sub GetRegDataInStruct()
Dim FileNum As Integer, i As Integer, bStart As Boolean
Dim TempString As String
    
    With RegData(0)
    
        For i = 0 To .RegFileCount - 1
        
            If i = 0 Then .RegTitleCount = 0
            
            FileNum = FreeFile: bStart = False
            Open .RegFile(i).RegFileName For Input As #FileNum
                Do While Not EOF(FileNum)
                    
                    Line Input #FileNum, TempString
                    
                    If ((bStart = True) And (TempString <> "")) Then
                        ReDim Preserve .RegFile(i).RegFileData(.RegFile(i).RegFileDataCount)
                        .RegFile(i).RegFileData(.RegFile(i).RegFileDataCount) = TempString
                        .RegFile(i).RegFileDataCount = .RegFile(i).RegFileDataCount + 1
                    End If
                    
                    If ((i = 0) And (bStart = False)) Then
                        ReDim Preserve .RegTitle(.RegTitleCount)
                        .RegTitle(.RegTitleCount) = TempString
                        .RegTitleCount = .RegTitleCount + 1
                    End If
                    
                    If InStr(UCase$(TempString), UCase$(KeyWord)) <> 0 Then
                        bStart = True
                    End If
                    
                    DoEvents
                Loop
            Close #FileNum
        Next i
        
        For i = 0 To .RegFileCount - 1
            If GetNum(.RegFile(i).RegFileData(.RegFile(i).RegFileDataCount - 1)) > .MaxContactNum Then
               .MaxContactNum = GetNum(.RegFile(i).RegFileData(.RegFile(i).RegFileDataCount - 1)) '最大Contact Number
            End If
        Next i
        
    End With

End Sub


想把这段改为语法

不要投我
2024-05-16 15:49
yz1025
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:6
帖 子:491
专家分:919
注 册:2012-10-26
收藏
得分:0 
程序代码:
Private Sub OutputBuffData()
Dim FileNum As Integer, i As Long, j As Long, TotalCountNum As String
Dim FileN As String, MyTime As String, Temp() As String

On Error GoTo ErrorHandling

    With RegData(0)
    
        MyTime = .TimeFlowNum
        
        FileN = .RegFilePath & .m_LotID & "_" & .m_WaferID & "_" & MyTime & Extension
        
        FileNum = FreeFile
        Open FileN For Output As #FileNum
        
            For i = 0 To .RegTitleCount - 1
                Print #FileNum, .RegTitle(i)
            Next i
            
            TotalCountNum = 0
            For i = 0 To RegData(0).MaxContactNum - 1
                For j = 0 To 7 'All Site --> 0 ~ 7
                    If Trim(RegData(0).AllRegData(i, j)) <> "" Then
                       TotalCountNum = TotalCountNum + 1
                       Print #FileNum, CStr(TotalCountNum) & " " & RegData(0).AllRegData(i, j)
                    End If
                Next j
            Next i
        Close #FileNum
        
        'debug log
        FileN = "C:\MiniRegMergeTool_" & Format(Now, "yyyymm") & ".log"
        FileNum = FreeFile
        Open FileN For Append As #FileNum
            Print #FileNum, Format(Now, "yyyy-mm-dd hh:mm:ss") & " -> " & TotalCountNum & vbCrLf
        Close #FileNum
        
    End With
    
    'Erase RegData, NewRegData
    
Exit Sub

ErrorHandling:
    Resume Next
End Sub

不要投我
2024-05-16 15:50
yz1025
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:6
帖 子:491
专家分:919
注 册:2012-10-26
收藏
得分:0 
因为VB6二维阵列开不到6万以上,需求至少要到12万,所以改成.NET试试看

不要投我
2024-05-16 15:52
yz1025
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:6
帖 子:491
专家分:919
注 册:2012-10-26
收藏
得分:0 
还是爆

程序代码:
Private Sub GetRegDataInStruct()
        Dim i As Integer, bStart As Boolean

        With RegData(0)

            For i = 0 To .RegFileCount - 1

                If i = 0 Then .RegTitleCount = 0
                Dim sr As StreamReader = New StreamReader(.RegFile(i).RegFileName)
                Dim line As String

                Do
                    line = sr.ReadLine()
                    'Console.WriteLine(line)
                    If ((bStart = True) And (line <> "")) Then
                        ReDim Preserve .RegFile(i).RegFileData(.RegFile(i).RegFileDataCount)
                        .RegFile(i).RegFileData(.RegFile(i).RegFileDataCount) = line
                        .RegFile(i).RegFileDataCount = .RegFile(i).RegFileDataCount + 1
                    End If

                    If ((i = 0) And (bStart = False)) Then
                        ReDim Preserve .RegTitle(.RegTitleCount)
                        .RegTitle(.RegTitleCount) = line
                        .RegTitleCount = .RegTitleCount + 1
                    End If

                    If InStr(UCase$(line), UCase$(KeyWord)) <> 0 Then
                        bStart = True
                    End If

                Loop Until line Is Nothing
                sr.Close()

            Next i

            For i = 0 To .RegFileCount - 1
                If GetNum(.RegFile(i).RegFileData(.RegFile(i).RegFileDataCount - 1)) > .MaxContactNum Then
                    .MaxContactNum = GetNum(.RegFile(i).RegFileData(.RegFile(i).RegFileDataCount - 1)) '最大Contact Number
                End If
            Next i

        End With

    End Sub


程序代码:
Private Sub OutputBuffData()
        Dim FileNum As Integer, i As Long, j As Long, TotalCountNum As String
        Dim FileN As String, MyTime As String, Temp() As String

        On Error GoTo ErrorHandling

        With RegData(0)

            MyTime = .TimeFlowNum

            FileN = .RegFilePath & .m_LotID & "_" & .m_WaferID & "_" & MyTime & Extension

            Dim sw As StreamWriter = New StreamWriter(FileN)
            For i = 0 To .RegTitleCount - 1
                sw.WriteLine(.RegTitle(i))
            Next i

            TotalCountNum = 0
            For i = 0 To RegData(0).MaxContactNum - 1
                For j = 0 To 7 'All Site --> 0 ~ 7
                    If Trim(RegData(0).AllRegData(i, j)) <> "" Then
                        TotalCountNum = TotalCountNum + 1
                        sw.WriteLine(CStr(TotalCountNum) & " " & RegData(0).AllRegData(i, j))
                    End If
                Next j
            Next i
            sw.Close()

            'debug log
            '    FileN = "C:\MiniRegMergeTool_" & Format(Now, "yyyymm") & ".log"
            '    FileNum = FreeFile()
            'Open FileN For Append As #FileNum
            '    Print #FileNum, Format(Now, "yyyy-mm-dd hh:mm:ss") & " -> " & TotalCountNum & vbCrLf
            'Close #FileNum

        End With

        'Erase RegData, NewRegData

        Exit Sub

ErrorHandling:
        Resume Next
    End Sub

不要投我
2024-05-16 17:05
yuma
Rank: 12Rank: 12Rank: 12
来 自:银河系
等 级:贵宾
威 望:37
帖 子:1933
专家分:3012
注 册:2009-12-22
收藏
得分:0 
回复 6楼 yz1025
你为什么没有写注释的习惯?


心生万象,万象皆程序!
本人计算机知识网:http://bbs.为防伸手党,本站已停止会员注册。
2024-05-20 18:49
yz1025
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:6
帖 子:491
专家分:919
注 册:2012-10-26
收藏
得分:0 
以下是引用yuma在2024-5-20 18:49:38的发言:

你为什么没有写注释的习惯?


一来因为是我写的,架构自己清楚,写不写没差别
二来因为是我写的,没人会接,有问题没人会帮忙,一切还是得自己来

若复杂一点的部分还是会写注释,只是目前这只程式没复杂到那个地步

不要投我
2024-05-29 16:37
快速回复:开档案写档案
数据加载中...
 
   



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

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