Results 1 to 16 of 16

Thread: [RESOLVED] VB6 - Program crashes trying to convert hex data into bin file.

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2017
    Posts
    38

    [RESOLVED] VB6 - Program crashes trying to convert hex data into bin file.

    Hi, friends!

    I'm trying to create an application in VB6 that converts hexadecimal data printed in a rich textbox into a binary file. Some time ago, with the help of this forum, I created a similar application in .NET.

    To do the same in VB6, I researched this forum and found a very well developed code. My problem is in the data types. The code in my program is:

    Code:
    'Button code
    
    Private Sub Command2_Click()
    
    Dim Fno As Long
    Dim ByteArray() As Byte
    Dim i As Long
    
    Fno = FreeFile
    
     ReDim ByteArray(VBA.Len(RichTextBox1.Text))
    
    For i = 0 To VBA.Len(RichTextBox1.Text) - 1
        ByteArray(i) = HexToDec(VBA.Mid(RichTextBox1, i + 1, 1))
    Next i
     
    
    Open App.Path & "\testfile.bin" For Binary As #Fno
         Put #Fno, , ByteArray
    Close #Fno
    
    End Sub
    
    
    'Function code
     
    Public Function HexToDec(ByVal HexStr As String) As Double
    
    Dim mult As Double
    Dim DecNum As Double
    Dim ch As String
    Dim i As Integer
    mult = 1
    DecNum = 0
    For i = Len(HexStr) To 1 Step -1
        ch = VBA.Mid(HexStr, i, 1)
        If (ch >= "0") And (ch <= "9") Then
            DecNum = DecNum + (val(ch) * mult)
        Else
            If (ch >= "A") And (ch <= "F") Then
                DecNum = DecNum + ((Asc(ch) - Asc("A") + 10) * mult)
            Else
                If (ch >= "a") And (ch <= "f") Then
                    DecNum = DecNum + ((Asc(ch) - Asc("a") + 10) * mult)
                Else
                    HexToDec = 0
                    Exit Function
                End If
            End If
        End If
        mult = mult * 16
    Next i
    HexToDec = DecNum
    
    End Function

    The hexadecimal data I want to convert to binary it is in the format I show below:

    IMPORTANT! this file contains more than 280.000 characters. So, Im just show the hex data format. The hex text file with all characters will be attached to this post.

    Code:
    F3ED5631F0DF187D7BD3BF7AD3BFC9FF
    874F0600097E23666FC9FFCB7FC8E60F
    875F1600197E23666FE9FFFFFFFFFFFF
    CF0EBEEDA320FCC9C3C0006D076D07E5
    094F19CE18C91B0C6CC97D5016880A88
    0ACD1FAF321FC0211FC07EE60FD9213B
    00E7C35700FFF53A1AC3FE0FCA82003A
    15C0B7C282003A1FC0FE8A38053E0132
    93C0F1ED453E8232FFFFCD029E2100C0
    1101C001FF1F75EDB0CD4103CD50033E
    8232FFFF31F0DFCD029ECD6B02210000
    110040010038CD8401FBCDF602C35300
    F5C5D5E5D908F5C5D5E5DDE5FDE5DBBF
    DBDDE6102196C04E77A9A1C29F003AFF
    FFF53A08C00FF5DCF701CDB341F10FF5
    CD6703CD7C10F10FF5CD4F26F10F3A1F
    C0212701DC1B003E8232FFFFCD4F98AF
    3208C0F132FFFFFDE1DDE1E1D1C1F1D9
    08E1D1C1F1FBC942084208350A011ACD

    If I declare "i" as Integer, I have an exception of type "overflow", because the hexadecimal data goes beyond the maximum accepted by integer values. So I declared "i" as Long.

    But my program crashes in runtime and I can't et the bin file.

    When I try to use dbBigint, the build points to a "user-defined type" error. The following is the image of the libraries I am using.



    Name:  libraries.png
Views: 1326
Size:  11.0 KB





    I am using Visual Basic 6 on Windows 7 Ultimate 64 bit.



    Is there any solution to my problem?


    Thanks in advance.
    Attached Files Attached Files
    Last edited by vbnewbieuser; Jul 24th, 2019 at 01:44 PM. Reason: Resolved

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width