dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Need help in VB6.0 Understanding..

  1. #1
    Join Date
    Feb 2010
    Posts
    3

    Need help in VB6.0 Understanding..

    Can i know what does this command?

    Mid$(Temp, I, 1) = Chr$(Val("&H" & Mid$(HexStr, I * 2 - 1, 2)))

    I understand part "Chr$(Val("&H" & Mid$(HexStr, I * 2 - 1, 2)))", but, why it need equal to the "Mid$(Temp, I, 1)"

    The complete function as follow:


    Function EBCDIC_To_ASCII_Table() As String
    EBCDIC_To_ASCII_Table = _
    HexToStr("000102039C09867F978D8E0B0C0D0E0F10111213 9D8508871819928F1C1D1E1F") & _
    HexToStr("80818283840A171B88898A8B8C05060790911693 9495960498999A9B14159E1A") & _
    HexToStr("20A0A1A2A3A4A5A6A7A8D52E3C282B7C26A9AAAB ACADAEAFB0B121242A293B5E") & _
    HexToStr("2D2FB2B3B4B5B6B7B8B9E52C255F3E3FBABBBCBD BEBFC0C1C2603A2340273D22") & _
    HexToStr("C3616263646566676869C4C5C6C7C8C9CA6A6B6C 6D6E6F707172CBCCCDCECFD0") & _
    HexToStr("D17E737475767778797AD2D3D45BD6D7D8D9DADB DCDDDEDFE0E1E2E3E45DE6E7") & _
    HexToStr("7B414243444546474849E8E9EAEBECED7D4A4B4C 4D4E4F505152EEEFF0F1F2F3") & _
    HexToStr("5C9F535455565758595AF4F5F6F7F8F930313233 343536373839FAFBFCFDFEFF")
    End Function


    Function HexToStr(ByVal HexStr As String) As String
    Dim Temp As String, I As Long
    Temp = Space$(Len(HexStr) \ 2)
    For I = 1 To Len(HexStr) \ 2
    Mid$(Temp, I, 1) = Chr$(Val("&H" & Mid$(HexStr, I * 2 - 1, 2)))
    Next I
    HexToStr = Temp
    End Function

  2. #2
    Join Date
    Apr 2009
    Posts
    394

    Re: Need help in VB6.0 Understanding..

    You have that backwards. Mid Temp eye one is to equal the other portion...

  3. #3
    Join Date
    Feb 2010
    Posts
    3

    Re: Need help in VB6.0 Understanding..

    thanks for the reply.. so, can i have an example for the mid(temp, eye 1)? example, eye = 2. what will be the mid(temp, 2, 1) ? and, what for the function using the space$ that is a 32. then, used in the mid.. not really get that part..

  4. #4
    Join Date
    Feb 2008
    Location
    Bangalore
    Posts
    149

    Re: Need help in VB6.0 Understanding..

    Quote Originally Posted by jasonkhoo87 View Post
    Can i know what does this command?
    I understand part "Chr$(Val("&H" & Mid$(HexStr, I * 2 - 1, 2)))", but, why it need equal to the "Mid$(Temp, I, 1)"

    The complete function as follow:
    you mean how does MID$ function works?
    Encourage the efforts of fellow members by rating

    Lets not Spoon Feed and create pool of lazy programmers

    - ComIT Solutions

  5. #5
    Join Date
    Apr 2009
    Posts
    394

    Re: Need help in VB6.0 Understanding..

    Well, the variable temp equals what? Lets say that the variable Temp = "Temp". So then
    Code:
    Dim Temp As String
    Temp = "Temp"
    MsgBox Mid(Temp, 2, 1) 'will equal e
    and so what your forumula is doing is replacing characters in the Temp variable with the results of the right side of the formula and it looks like it is a decoding algorithm...

    As for the space character,... if that formula is doing what I think it is doing, it is decoding a string that was encoded in hex using the acsii values of each letter in the string. So there is a function out there that takes something like this...> "This is a test!" and encodes it into a representitave hex value string, and what you have is the decoding of it... (Perhaps base 64?). So then the ascii character 32 equals a space...

    And finally, the Space$ Function that you see in the HexToString function is initializing the Temp variable with the number of characters needed to decode the current hex string passed to that function... and why the \2? because the hex string uses two characters to describe one ascii value... Normal ascii values = 0 to 255 and a two character hex value (base 16) = 0 to 255



    Good Luck

  6. #6
    Join Date
    Feb 2010
    Posts
    3

    Re: Need help in VB6.0 Understanding..

    i understand the use of mid. i just confuse the program. im new in visual basic.. sorry..

    thanks for the explanation..

  7. #7
    Join Date
    Feb 2008
    Location
    Bangalore
    Posts
    149

    Re: Need help in VB6.0 Understanding..

    in addition to vb5prgrmr's explanation. You can also use MID$ Function to replace a specific location character with Another.


    Code:
    Dim TmpStr as string
    tmpstr =  "BAT"
    MID$(TmpStr,2,1)="U" ' After execution This line  Tmpstr will contain "BUT"
    Encourage the efforts of fellow members by rating

    Lets not Spoon Feed and create pool of lazy programmers

    - ComIT Solutions

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)