VB写入到EXE时候中文不能写入
Dim MainFile As String
Dim AlterFile As String
Dim TempStr As Integer
Dim strName As String
Dim strKey As String
Dim OffsetStep As Integer
Dim Record As Integer
Private Sub Command1_Click()
Dim TempByte As Integer
Dim UserData(20) As Integer
OffsetStep = 60
MainFile = App.Path & "\ " & App.EXEName & ".exe "
AlterFile = App.Path & "\ " & App.EXEName & "1.exe "
Open MainFile For Binary Access Read As #1
Open AlterFile For Binary Access Write As #2
For i = 1 To LOF(1)
Get #1, i, TempByte
Put #2, i, TempByte
Next i
Close #1
For i = 1 To Len(Text1.Text)
UserData(i) = AscW(Mid(Text1.Text, i, 1))
Next i
If Len(Text1.Text) < 20 Then
For i = Len(Text1.Text) + 1 To 20
UserData(i) = AscW( " ")
Next i
End If
For i = 1 To 20
OffsetStep = OffsetStep - 1
Record = LOF(2) - OffsetStep
Put #2, Record, UserData(i)
MsgBox Record & "___ " & UserData(i)
Next i
Close #2
'MsgBox "数据生成成功! "
End Sub
Private Sub Form_Load()
strUser = " "
MainFile = App.Path & "\ " & App.EXEName & ".exe "
Open MainFile For Binary Access Read As #1
OffsetStep = 60
'取数据
For i = 1 To 20
OffsetStep = OffsetStep - 1
Record = LOF(1) - OffsetStep
Get #1, Record, TempStr
If App.EXEName = "工程11 " Then
MsgBox Record & "___ " & TempStr
End If
strUser = strUser & ChrW(TempStr)
Next i
Close #1
Text1.Text = strUser
End Sub
这是我整理的方法,现在出现的问题是中文不能写入
如果我把 Dim TempStr As Integer 改为 Dim TempStr As Byte
可以写入英文或数字
中文的问题不知道怎么解决
[解决办法]
hex(asc( "他 "))
chr$(&hcbfb)
[解决办法]
如果我把 Dim TempStr As Integer 改为 Dim TempStr As Byte
可以写入英文或数字,这没有问题
当text1里中英文混合时,Dim TempStr As Integer
就不行了,哪样记录号(OffsetStep = OffsetStep - 1:Record = LOF(1) - OffsetStep)一次移两个字节,而英文只占一个字节,会发生错位