# Need help in VB6.0 Understanding..

• February 26th, 2010, 11:12 PM
jasonkhoo87
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("2D2FB2B3B4B5B6B7B8B9E52C255F3E3FBABBBCBD BEBFC0C1C2603A2340273D22") & _
HexToStr("C3616263646566676869C4C5C6C7C8C9CA6A6B6C 6D6E6F707172CBCCCDCECFD0") & _
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
• February 26th, 2010, 11:50 PM
vb5prgrmr
Re: Need help in VB6.0 Understanding..
You have that backwards. Mid Temp eye one is to equal the other portion...
• February 27th, 2010, 04:05 AM
jasonkhoo87
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..
• February 27th, 2010, 06:15 AM
ComITSolutions
Re: Need help in VB6.0 Understanding..
Quote:

Originally Posted by jasonkhoo87
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?
• February 27th, 2010, 08:38 AM
vb5prgrmr
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
• February 27th, 2010, 11:10 AM
jasonkhoo87
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.. :)
• February 28th, 2010, 12:41 AM
ComITSolutions
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"