View Single Post
Old May 18th, 2008 (8:08 PM). Edited May 18th, 2008 by Darthatron.
Darthatron's Avatar
Darthatron Darthatron is offline
  • Silver Tier
Join Date: Jan 2006
Location: Melbourne, Australia
Age: 26
Gender: Male
Nature: Modest
Posts: 1,152
Originally Posted by ThuGie View Post
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 ?
Well I feel stupid. Then again I did write the first functions about 4 months ago, I have learned a lot from then. Also I'm sure if I re-wrote them they would be up to standard, then again, I'm too busy right now, if you need a faster function use TheGie's version. For now...

EDIT: You seemed to have Dimmed "Temp" and not used it, removing it could add precious micro-seconds.

EDIT2: After re-writing the WriteHEX Code from scratch I came to realize how bad my old method was. Anyway, I did a Speed Test between my Function and TheGie's. I made each Function run 4000 times. Each 1000 times it would return how fast it was going then at the end it would show the Average, here are the results:
First: 921
Second: 938
Third: 906
Forth: 1047

Average: 953

First: 1047
Second: 1000
Third: 937
Forth: 953

Average: 984.25
As you can see mine is only slightly faster. I'd also like to note my Computer is VERY slow and these speed should be closer to 500 or 600.

I plan to redo my ReadHEX Function, though I don't think it can get much faster, then again it's pretty sloppy too.
あなた は しきしゃ です
わたし は ばか です
Reply With Quote