标题: 一个VB的问题
性别:未知-离线 金圭子

白衣伯爵中大夫

Rank: 14Rank: 14Rank: 14Rank: 14Rank: 14
组别 白衣卿相
级别 征西将军
好贴 4
功绩 265
帖子 4926
编号 27961
注册 2004-12-16


发表于 2005-2-4 12:49 资料 文集 短消息 看全部作者
刚刚牺牲了午饭查了查资料,写了一段,
command2用来新建文件,command1用来截断文件

Option Explicit

Private Const OFS_MAXPATHNAME = 128
Private Type OFSTRUCT
        cBytes As Byte
        fFixedDisk As Byte
        nErrCode As Integer
        Reserved1 As Integer
        Reserved2 As Integer
        szPathName(OFS_MAXPATHNAME) As Byte
End Type

Private Const OF_READWRITE = &H2
Private Const OF_SHARE_COMPAT = &H0
Private Const OF_SHARE_DENY_NONE = &H40

Private Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long

Private Declare Function SetEndOfFile Lib "kernel32" (ByVal hFile As Long) As Long

Private Const FILE_BEGIN = 0
Private Declare Function SetFilePointer Lib "kernel32" (ByVal hFile As Long, ByVal lDistanceToMove As Long, lpDistanceToMoveHigh As Long, ByVal dwMoveMethod As Long) As Long

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Private Declare Function GetLastError Lib "kernel32" () As Long


Private Sub Command1_Click()
Dim fHandle As Long
Dim ofs As OFSTRUCT
fHandle = OpenFile("c:\aa.dbc", ofs, OF_READWRITE Or OF_SHARE_DENY_NONE)
If fHandle = -1 Then
    MsgBox "OpenError=" & ofs.nErrCode
Else
  If SetFilePointer(fHandle, 3, 0, FILE_BEGIN) = -1 Then
    MsgBox "SetPointError=" & GetLastError
  Else
    If SetEndOfFile(fHandle) = 0 Then MsgBox "LastError=" & GetLastError Else MsgBox "Ok"
  End If
  Call CloseHandle(fHandle)
End If
End Sub

Private Sub Command2_Click()
Open "c:\aa.dbc" For Binary As #1
Put #1, 1, "aa"
Put #1, 5, "bb"
Put #1, 9, "cc"
Close #1
End Sub


顶部
性别:未知-离线 金圭子

白衣伯爵中大夫

Rank: 14Rank: 14Rank: 14Rank: 14Rank: 14
组别 白衣卿相
级别 征西将军
好贴 4
功绩 265
帖子 4926
编号 27961
注册 2004-12-16


发表于 2005-2-4 12:53 资料 文集 短消息 看全部作者


QUOTE:
原帖由Maxwell于2005-02-04, 12:51:47发表
    金圭子强,连代码都写出来了。

我想吃午饭


顶部

正在浏览此帖的会员 - 共 1 人在线




当前时区 GMT+8, 现在时间是 2025-2-5 19:52
京ICP备2023018092号 轩辕春秋 2003-2023 www.xycq.org.cn

Powered by Discuz! 5.0.0 2001-2006 Comsenz Inc.
Processed in 0.011779 second(s), 9 queries , Gzip enabled

清除 Cookies - 联系我们 - 轩辕春秋 - Archiver - WAP