Jump to content

  •  

  • iBotModz CBox


    Photo

    VB Writing help


    • Please log in to reply
    2 replies to this topic

    #1 halodu03de

    halodu03de

      Corporal Grade 1

    • Members+

    • 167 posts
    • Joined: 13-May 08

    Posted 03 June 2009 - 05:20 PM

    In VB when I write to a file, and what I write is fewer characters than what was originally there, I need it to clear the extra characters. For example, if I have 1234567 in a text box that was read from an offset in a file, and I change it to 55555 and write it to the same offset, it is 5555567 instead of 55555. Does anyone have any idea how to fix that?

    #2 Dark Slipstream

    Dark Slipstream

      Blue Shadowz Owner

    • Members+

    • 2,829 posts
    • Joined: 19-April 08
    • Gender:Male
    • Location:Canada, ON

    Posted 03 June 2009 - 08:27 PM

    You could use a Replace() method, I wrote one in my DLL, but this version hasn't been released yet.

    Here is some reference code, don't copy paste, it won't work unless you try to work with it. -.-

    Dim Filepath As String = "C:\test"
    Dim Binary As New Dark.Slipstream.OperatingSystem.Binary
    Dim OperatingSystem As New Dark.Slipstream.OperatingSystem
    Dim fi As New System.IO.FileInfo(Filepath )
    Dim originalStr As String = "1234567"
    Dim Offset As Integer = CInt(OperatingSystem.ScanForString(Filepath, originalStr, 0)
    Dim Length As Integer = str.Length()
    Dim Beginning As Byte() = Binary.Read(Filepath, 0, Offset)
    Dim Ending As Byte() = Binary.Reader(Filepath, (Offset + Length), (CInt(fi.Length) - Offset))
    Dim newStr As String = "55555"
    Dim AddByte As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(newStr)
    Dim tempByte As Byte() = OperatingSystem.CombineByteArray(AddByte, Beginning)
    Dim completeByte As Byte() = OperatingSystem.CombineByteArray(Ending, tempByte)
    Binary.Write(Filepath, completeByte) 'New function that will overwrite a file, and write completely new data.

    Ok so I lied, if you have my new DLL, that should actually work 100% lol... Wait until it's released, that is basically my Replace() function, just this one is double the size because I'm a little tired, and tried to make it more easily understandable.

    #3 halodu03de

    halodu03de

      Corporal Grade 1

    • Members+

    • 167 posts
    • Joined: 13-May 08

    Posted 04 June 2009 - 01:23 PM

    You could use a Replace() method, I wrote one in my DLL, but this version hasn't been released yet.

    Here is some reference code, don't copy paste, it won't work unless you try to work with it. -.-

    Dim Filepath As String = "C:\test"
    Dim Binary As New Dark.Slipstream.OperatingSystem.Binary
    Dim OperatingSystem As New Dark.Slipstream.OperatingSystem
    Dim fi As New System.IO.FileInfo(Filepath )
    Dim originalStr As String = "1234567"
    Dim Offset As Integer = CInt(OperatingSystem.ScanForString(Filepath, originalStr, 0)
    Dim Length As Integer = str.Length()
    Dim Beginning As Byte() = Binary.Read(Filepath, 0, Offset)
    Dim Ending As Byte() = Binary.Reader(Filepath, (Offset + Length), (CInt(fi.Length) - Offset))
    Dim newStr As String = "55555"
    Dim AddByte As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(newStr)
    Dim tempByte As Byte() = OperatingSystem.CombineByteArray(AddByte, Beginning)
    Dim completeByte As Byte() = OperatingSystem.CombineByteArray(Ending, tempByte)
    Binary.Write(Filepath, completeByte) 'New function that will overwrite a file, and write completely new data.

    Ok so I lied, if you have my new DLL, that should actually work 100% lol... Wait until it's released, that is basically my Replace() function, just this one is double the size because I'm a little tired, and tried to make it more easily understandable.


    Alright thanks a lot.