VB 如何去掉文件头部指定的字节数
发布网友
发布时间:2022-12-25 23:42
我来回答
共2个回答
热心网友
时间:2023-07-02 15:12
新建并打开一个文件夹,在新建的文件夹里创建两个 文本文档 文件,分别粘贴保存指定内容,并按要求命名文件。最后双击“工程1.vbp”这个文件即可!
第一个粘贴以下内容(不要等号分隔线),保存,并命名为 工程1.vbp
Type=Exe
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\WINDOWS\system32\stdole2.tlb#OLE Automation
Form=Form1.frm
Object={F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0; COMDLG32.OCX
Startup="Form1"
HelpFile=""
Command32=""
Name="工程1"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="FREE"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1
[MS Transaction Server]
AutoRefresh=1
======================================
第二个粘贴以下内容(不要等号分隔线),保存并命名为 Form1.frm
VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form Form1
BorderStyle = 4 'Fixed ToolWindow
Caption = "Form1"
ClientHeight = 3120
ClientLeft = 45
ClientTop = 360
ClientWidth = 4680
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3120
ScaleWidth = 4680
ShowInTaskbar = 0 'False
StartUpPosition = 3 '窗口缺省
Begin VB.OptionButton Option2
Caption = "擦除"
Height = 375
Left = 1440
TabIndex = 9
Top = 1800
Width = 1215
End
Begin VB.OptionButton Option1
Caption = "剪掉"
Height = 375
Left = 0
TabIndex = 8
Top = 1800
Value = -1 'True
Width = 1215
End
Begin MSComDlg.CommonDialog CDL
Left = 2880
Top = 2160
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.CommandButton Command3
Caption = "打开文件"
Height = 615
Left = 2880
TabIndex = 7
Top = 0
Width = 1695
End
Begin VB.CommandButton Command2
Caption = "取消"
Height = 615
Left = 2880
TabIndex = 5
Top = 1440
Width = 1695
End
Begin VB.CommandButton Command1
Caption = "执行"
Height = 615
Left = 2880
TabIndex = 4
Top = 720
Width = 1695
End
Begin VB.TextBox Text2
Height = 375
Left = 0
TabIndex = 3
Text = "0"
Top = 1080
Width = 2775
End
Begin VB.TextBox Text1
Height = 375
Left = 0
TabIndex = 2
Text = "0"
Top = 360
Width = 2775
End
Begin VB.Label Label4
Caption = "去除方式:"
Height = 495
Left = 0
TabIndex = 10
Top = 1560
Width = 2775
End
Begin VB.Label Label3
BorderStyle = 1 'Fixed Single
Caption = "准备就绪"
Height = 375
Left = 0
TabIndex = 6
Top = 2760
Width = 4695
End
Begin VB.Label Label2
Caption = "去除的字节数:"
Height = 495
Left = 0
TabIndex = 1
Top = 840
Width = 2775
End
Begin VB.Label Label1
Caption = "从第几个字节开始去除:"
Height = 375
Left = 0
TabIndex = 0
Top = 120
Width = 2655
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Doing As Boolean '是否正在处理
Private FName As String '将要处理的文件名及路径
Private Sub Command1_Click()
Dim FNum As Long, Fnum2 As Long
Dim FLen As Long
Dim Dat() As Byte
Dim PathGet() As Byte
Dim NewFile As String
Dim ChukLen As Long
Dim Start As Long
Dim Cuts As Long
Dim i As Long, j As Long, Abyte As Byte
Start = Val(Text1)
Cuts = Val(Text2)
If Start < 1 Or Cuts < 1 Or FName = "" Then Exit Sub
Command3.Enabled = False
Command1.Enabled = False
PathGet = StrConv(FName, vbFromUnicode)
FNum = UBound(PathGet)
For i = UBound(PathGet) To 0 Step -1
If PathGet(i) = Asc("\") Then
ReDim Preserve PathGet(0 To UBound(PathGet) + 4)
For j = 0 To FNum - i
PathGet(UBound(PathGet) - j) = PathGet(FNum - j)
Next
PathGet(i + 1) = Asc("P")
PathGet(i + 2) = Asc("i")
PathGet(i + 3) = Asc("k")
PathGet(i + 4) = Asc("_")
NewFile = StrConv(PathGet, vbUnicode)
MsgBox "新的文件为:" & vbNewLine & NewFile
Exit For
End If
Next
FNum = FreeFile
Open FName For Binary As FNum
FLen = LOF(FNum)
If Start + Cuts > FLen Then
MsgBox "超出文件尾!"
Close FNum
Exit Sub
End If
Fnum2 = FreeFile
Open NewFile For Binary As Fnum2
Start = Start - 1
Doing = True
i = Start
Do While i > 0
If i <= 1024 Then
ReDim Dat(i - 1)
Get FNum, , Dat
Put Fnum2, , Dat
ChukLen = ChukLen + i
i = 0
Label3 = Int(ChukLen / FLen * 100) & "%"
If Doing Then GoTo Last
DoEvents
Else
ReDim Dat(1023)
Get FNum, , Dat
Put Fnum2, , Dat
i = i - 1024
ChukLen = ChukLen + 1024
Label3 = Int(ChukLen / FLen * 100) & "%"
If Doing Then GoTo Last
DoEvents
End If
Loop
If Option2 Then
i = Cuts
Do While i > 0
If i <= 1024 Then
ReDim Dat(i - 1)
Put Fnum2, , Dat
i = 0
ChukLen = ChukLen + i
Label3 = Int(ChukLen / FLen * 100) & "%"
If Doing Then GoTo Last
DoEvents
Else
ReDim Dat(1023)
Put Fnum2, , Dat
i = i - 1024
ChukLen = ChukLen + 1024
Label3 = Int(ChukLen / FLen * 100) & "%"
If Doing Then GoTo Last
DoEvents
End If
Loop
End If
Get FNum, Start + Cuts, Abyte
i = FLen - Start - Cuts
Do While i > 0
If i <= 1024 Then
ReDim Dat(i - 1)
Get FNum, , Dat
Put Fnum2, , Dat
i = 0
ChukLen = ChukLen + i
Label3 = Int(ChukLen / FLen * 100) & "%"
If Doing Then GoTo Last
DoEvents
Else
ReDim Dat(1023)
Get FNum, , Dat
Put Fnum2, , Dat
i = i - 1024
ChukLen = ChukLen + 1024
Label3 = Int(ChukLen / FLen * 100) & "%"
If Doing Then GoTo Last
DoEvents
End If
Loop
Close FNum
Close Fnum2
Doing = False
Command1.Enabled = True
Exit Sub
Last:
Close FNum
Close Fnum2
Doing = False
Command1.Enabled = True
On Error Resume Next
Kill NewFile
End Sub
Private Sub Command2_Click()
Command3.Enabled = True
Command1.Enabled = False
Command2.Enabled = False
Doing = True
End Sub
Private Sub Command3_Click()
CDL.CancelError = False
CDL.ShowOpen
If CDL.FileName = "" Then Exit Sub
FName = CDL.FileName
Command1.Enabled = True
Command2.Enabled = True
Command3.Enabled = False
Doing = False
End Sub
Private Sub Form_Load()
Doing = False
Command1.Enabled = False
Command2.Enabled = False
End Sub
=================================================
热心网友
时间:2023-07-02 15:13
用 SEEK=...来解决 再接着读取就是了