vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
Brandneu! sevEingabe v3.0 - Das Eingabecontrol der Superlative!  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2025
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

VB.NET - Ein- und Umsteiger
Re: Schbreiben von Bytes little / big Endian 
Autor: lastyle
Datum: 02.05.12 21:39

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
alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
Schbreiben von Bytes little / big Endian3.507lastyle01.05.12 14:34
Re: Schbreiben von Bytes little / big Endian2.432lastyle01.05.12 22:52
Re: Schbreiben von Bytes little / big Endian2.346Manfred X02.05.12 07:51
Re: Schbreiben von Bytes little / big Endian2.495lastyle02.05.12 13:03
Re: Schbreiben von Bytes little / big Endian2.371Manfred X02.05.12 13:06
Re: Schbreiben von Bytes little / big Endian2.348eierlein02.05.12 16:55
Re: Schbreiben von Bytes little / big Endian2.305keco02.05.12 19:10
Re: Schbreiben von Bytes little / big Endian2.286lastyle02.05.12 19:22
Re: Schbreiben von Bytes little / big Endian2.318ModeratorDaveS02.05.12 21:05
Re: Schbreiben von Bytes little / big Endian2.323ModeratorDaveS02.05.12 21:20
Re: Schbreiben von Bytes little / big Endian2.768lastyle02.05.12 21:39
Re: Schbreiben von Bytes little / big Endian2.492ModeratorDaveS02.05.12 21:49
Re: Schbreiben von Bytes little / big Endian2.334lastyle02.05.12 22:00
Schreiben von Bytes little / big Endian2.323Manfred X03.05.12 10:05
Re: Schbreiben von Bytes little / big Endian2.284ModeratorDaveS03.05.12 10:52
Re: Schbreiben von Bytes little / big Endian2.244lastyle03.05.12 12:34
Re: Schbreiben von Bytes little / big Endian2.323ModeratorDaveS03.05.12 13:43
Re: Schbreiben von Bytes little / big Endian2.240lastyle03.05.12 17:25
Re: Schbreiben von Bytes little / big Endian2.447ModeratorDaveS02.05.12 14:00

Sie sind nicht angemeldet!
Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.

Einloggen  |  Neu registrieren

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2025 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel