谁能给我文件操作的例子.

wei8011 2003-05-08 06:04:42
谁能给我文件操作的例子?
...全文
9 点赞 收藏 1
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
Ozone_79 2003-05-08
dlgFileOpen.CancelError = True
On Error GoTo err

' Set flags
dlgFileOpen.Flags = cdlOFNHideReadOnly
dlgFileOpen.InitDir = Dpath.MENTE_TANA

' Set filters
dlgFileOpen.Filter = "All Files (*.*)|*.*|Data Files(*.DAT)|*.DAT|Text Files" & _
"(*.txt)|*.txt|Excel Files (*.xls)|*.xls"

' Specify default filter
dlgFileOpen.FilterIndex = 2
dlgFileOpen.FileName = ""

' Display the Open dialog box
dlgFileOpen.ShowOpen

' Display name of selected file
strFileName = dlgFileOpen.FileName

Me.Refresh 'Refresh the pic.
' SetCursor (gLnCurBusy) 'Set cursor to be busy.


' Get the File Num.
intFileNum = FreeFile

' File Open
err.Clear
Open strFileName For Input As #intFileNum
If err.Number > 0 Then
'OPEN Fail!
handleMsg "30001"
GoTo err
End If

Me.Refresh

Do While Not EOF(intFileNum) ' Read file untile blank line.
err.Clear
Line Input #intFileNum, buff
If buff = "" Then ' Blank line, exit.
Exit Do
End If
iRow = iRow + 1
buff = LTrim(buff)
' Modify by LiuYang 2002/11/21
If Len(buff) <> intLiu_TANA_REC_ACTS And Len(buff) <> intLiu_TANA_REC_PRISM Then
MsgBox "第 " & iRow & " 行の長さが間違っています!", vbCritical, "YFC保管システム"
' Unload dlgProcessBar
GoTo err
End If
' Modify End
Loop
Close #intFileNum
Open strFileName For Input As #intFileNum

fraProcess.ZOrder 0
fraProcess.Visible = True
Me.barCheck.Value = 0
Me.barPutDB.Value = 0
Me.Refresh

Do While Not EOF(intFileNum) ' Read file untile blank line.
err.Clear
Line Input #intFileNum, buff
If buff = "" Then ' Blank line, exit.
Exit Do
End If

If err.Number > 0 Then ' Error.
'READ Fail!
handleMsg "30001"
' Unload dlgProcessBar
GoTo err
End If

ReDim Preserve strFileData(1 To 6, UBound(strFileData(), 2) + 1)
' Added by LiuYang in ShangHai wanbishi on 2002/11/21
intSartPos = 3
If Len(buff) = intLiu_TANA_REC_ACTS Then
intSartPos = intSartPos + intLiu_TANA_INTPOS_ACTS
strFileData(1, UBound(strFileData(), 2)) = Trim(Mid(buff, intSartPos, intLiu_TANA_CUSTCD_ACTS))
intSartPos = intSartPos + intLiu_TANA_CUSTCD_ACTS
strFileData(2, UBound(strFileData(), 2)) = Trim(Mid(buff, intSartPos, intLiu_TANA_HOBON2_ACTS))
intSartPos = intSartPos + intLiu_TANA_HOBON2_ACTS
strFileData(3, UBound(strFileData(), 2)) = Trim(Mid(buff, intSartPos, intLiu_TANA_KANRINO_ACTS))
intSartPos = intSartPos + intLiu_TANA_KANRINO_ACTS
strFileData(4, UBound(strFileData(), 2)) = Trim(Mid(buff, intSartPos, intLiu_TANA_CENCODE_ACTS))
intSartPos = intSartPos + intLiu_TANA_CENCODE_ACTS
strFileData(5, UBound(strFileData(), 2)) = Trim(Mid(buff, intSartPos, intLiu_TANA_TANAADD_ACTS))
intSartPos = intSartPos + intLiu_TANA_TANAADD_ACTS
strFileData(6, UBound(strFileData(), 2)) = Trim(Mid(buff, intSartPos, intLiu_TANA_MEMO_ACTS))
End If
If Len(buff) = intLiu_TANA_REC_PRISM Then
intSartPos = intSartPos + intLiu_TANA_INTPOS_PRISM
strFileData(1, UBound(strFileData(), 2)) = Trim(Mid(buff, intSartPos, intLiu_TANA_CUSTCD_PRISM))
intSartPos = intSartPo
回复
相关推荐
发帖
VB基础类
创建于2007-09-28

7489

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2003-05-08 06:04
社区公告
暂无公告