View Single Post
Old May 18th, 2008 (9:30 AM). Edited May 18th, 2008 by ThuGie.
ThuGie ThuGie is offline
    Join Date: May 2008
    Posts: 21
    Darthatron was kind enough to release his functions,
    And people are ofcourse using them,

    But so far i have seen nobody has even tryed to fix the problems that the functions still have,
    They use them and compain about the problems,

    For me i dont even use the functions but i thought why not take a look and thought well this could use some fixing and i did,
    People should be more kind to share what they know help each other.
    I will when i have time try and make functions like the other 2 that he released,
    But when that will be i dont know i was bored so i made ReverseHex.
    But thats only took a few minutes and the other functions will take probably about the same time..
    But when you calculate the time spend on all 3 it will add up in 1 day time.
    And to tell the truth i think making functions like this is boring :p,
    So thank god it only needs to be done once and the 2e time to see if any fixes/tweaks are posible :D.

    But really people try and be a bit more open source .

    Well as i still had some time i fixt the function a bit up,
    As you where talking about speed it could be because it writes 1 byte at a time..
    Not sure why but i kept it that way.
    If really intersted i could rewrite it to write multiple byte's at once probably.

    Public Function WriteHex(FilePath As String, Offset As Long, HexData As String)
    On Error GoTo ErrHandle
    Dim FileNum As Integer
    Dim i As Integer
    Dim Temp As String
    Dim HexHold As String
    Dim HexValue() As Byte
    HexHold = HexData
    FileNum = FreeFile
        If InStr(Len(HexHold) / 2, ",") > 0 Then HexHold = "0" & HexHold
        ReDim HexValue((Len(HexHold) / 2) - 1)
        For i = 0 To (Len(HexHold) / 2) - 1
            HexValue(i) = CLng("&H" & Mid(HexHold, 1 + (i * 2), 2))
        Next i
        Open FilePath For Binary As FileNum
            Put FileNum, Offset + 1, HexValue
        Close FileNum
    Exit Function
        MsgBox Err.Description, vbOKOnly, "Error: " & Err.Number
    End Function
    As you see i used mostly his code just tweaked it.
    But you should be able to call it using Data as many times you want .

    D-Trogh, Pointed me to a mistake what i just fixed i had Offset As integer, It should have been Offset As Long
    I compared my function and Darthatron's function and it seems his is a bit faster so if you want faster you should go for his version.
    I noticed that DoEvents was the cause of slowness,
    But also i updated it even more it now write's all data to file in 1 go!
    And as for speed its faster then Darthatron's now did a test writing 5kb 1000 times,
    Mine will take around 8 seconds while his will take around 42 seconds.
    I really do like speed dont you ?
    Reply With Quote