Hallo, nein kein VBScript, das ist schon richtig VB.net 2010.
Normalerweise habe ich immer alle meine projekte unter VB6 gemacht und auch weiter gepflegt, nur jetzt ging es mir sehr auf die Nerven immer wieder den VirtualXP Mode zu starten um zu Programmieren. Aus dem Grund habe ich das neue Projekt dann direkt unter vb2010 angefangen und habe leider noch zu viele Umstellungsschwierigkeiten. Unter VB6 hab ich hat eine Datei aufgemacht und dann Binary geschrieben, fertig, aber egal.
Ich Poste dann mal meinen Code in dem ich dann das Binary schreiben möchte.
(Bitte nicht auslachen, wie gesagt erster VB2010 Code.
Private Function joinfiles()
Dim sPath As String
sPath = TextBox1.Text
Dim oDir As New System.IO.DirectoryInfo(sPath)
If My.Computer.FileSystem.FileExists(sPath & "\" & txtprojectname.Text _
+ ".bin") Then
My.Computer.FileSystem.DeleteFile(sPath & "\" & txtprojectname.Text _
+ ".bin")
Else
MsgBox(txtprojectname.Text + ".bin" & vbCrLf & "not found, building" & _
"new File!")
End If
' alle Dateien des Ordners
Dim oFiles As System.IO.FileInfo() = oDir.GetFiles()
Dim oFile As System.IO.FileInfo
Dim flen As String = 0
Dim fcount As String = 0
Dim filepos As String = 0
Dim orgname, padname, padnameforlist, filebank As String
Dim FileContent() As Byte
If My.Computer.FileSystem.FileExists(sPath & "\" & txtprojectname.Text _
+ "_Filedir.bin") Then
My.Computer.FileSystem.DeleteFile(sPath & "\" & txtprojectname.Text _
+ "_Filedir.bin")
End If
Dim Writedirbin As New System.IO.StreamWriter(sPath & "\" & _
txtprojectname.Text & "_Filedir.bin")
Dim binWriter As New BinaryWriter(New MemoryStream())
Dim fc As String = 0
txtdata.Text = ""
filebank = Val(lblsbank.Text)
For Each oFile In oFiles
fc = fc + 1
If oFile.Name = txtprojectname.Text & "_Filedir.bin" Then GoTo _
skipdirfile
If oFile.Name = txtprojectname.Text & "_Filedir.txt" Then GoTo _
skipdirfile
flen = flen + oFile.Length
fcount = fcount + 1
orgname = oFile.Name
If Mid(orgname, orgname.Length - 3, 1) = "." Then
orgname = Mid(orgname, 1, orgname.Length - 4)
End If
reloopbancinc:
If filepos > 16384 Then
filepos = filepos - 16384
filebank = filebank + 1
End If
If filepos > 16384 Then GoTo reloopbancinc
Dim b As String
Dim s1 As String = filepos
Dim sh As UShort
b = Chr(0)
padname = Microsoft.VisualBasic.Left(orgname, 16).PadRight(16, _
Microsoft.VisualBasic.Chr(0))
padnameforlist = Microsoft.VisualBasic.Left(orgname, 16).PadRight( _
16, " "c)
txtdata.Text = txtdata.Text & Chr(34) & padnameforlist.ToUpper & _
Chr(34) & " Bank $" & Microsoft.VisualBasic.Left(Decimal2Hex( _
filebank), 2).PadLeft(2, "0"c) & ", $" & Microsoft.VisualBasic.Left( _
Decimal2Hex(oFile.Length), 4).PadLeft(4, "0"c) & " Bytes , Startpos" & _
"$" & Microsoft.VisualBasic.Left(Decimal2Hex(filepos), 4).PadLeft( _
4, "0"c) & vbCrLf
filepos = filepos + oFile.Length
FileContent = My.Computer.FileSystem.ReadAllBytes(sPath & "\" & _
oFile.Name)
My.Computer.FileSystem.WriteAllBytes(sPath & "\" & _
txtprojectname.Text + ".bin", FileContent, append:=True)
' Name 16 bytes File name, 16 characters , done !
Writedirbin.Write(padname.ToUpper)
'Flags 1 byte File type and some flags , done !
Writedirbin.Write(Chr(1))
'Bank 1 byte Bank where the file starts, 0..63 , done !
Writedirbin.Write(Chr(Val(filebank)))
'Bank High 1 byte Reserved for high byte of bank, currently always
' 0 , done !
Writedirbin.Write(Chr(0))
'Offset 2 bytes File start offset in this bank 0x0000..0x3FFF,
' little endian
sh = Convert.ToUInt16(s1) ' Dezimal z.b. = 49152
REM sh = Convert.ToUInt16(s2, 16) ' oder Hex z.b. = C000
Dim c() As Byte = BitConverter.GetBytes(sh)
Dim c0 As Byte = c(0)
c(0) = c(1)
c(1) = c0
IO.File.WriteAllBytes(sPath & "\" & txtprojectname.Text + ".bin" & _
fc, c)
Writedirbin.Write(Chr(4))
Writedirbin.Write(Chr(5))
Writedirbin.Write(Chr(0)) 'fillbyte stays 0
skipdirfile:
Next
Writedirbin.Close()
Return Nothing
End Function |