Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,584 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,956 people online right now. Registration is fast and FREE... Join Now!




Visual Basic Problem

 
Reply to this topicStart new topic

Visual Basic Problem, Some Conversion Problem

hit
6 Oct, 2008 - 06:10 AM
Post #1

New D.I.C Head
*

Joined: 14 Sep, 2008
Posts: 7

I am trying to convert ASCII string into hex and I am using the following function to accomplish that.
CODE

Private Function HexString(EvalString As String) As String
Dim intStrLen As Integer
Dim intLoop As Integer
Dim strHex As String

EvalString = Trim(EvalString)

intStrLen = Len(EvalString)
For intLoop = 1 To intStrLen
strHex = strHex & " " & Hex(Asc(Mid(EvalString, intLoop, 1)))
Next
HexString = strHex
End Function

However this function is not giving the right results.
Can anybody tell what is the error? rolleyes.gif
User is offlineProfile CardPM
+Quote Post

jaakko
RE: Visual Basic Problem
6 Oct, 2008 - 11:53 AM
Post #2

New D.I.C Head
*

Joined: 26 Sep, 2008
Posts: 21



Thanked: 1 times
My Contributions
CODE

>================================
Private Sub Command1_Click()
    Dim strHex As String

    cDecString = "255"
    nDec = Val(cDecString)
    strHex = Hex(nDec)

    Text2.Text = strHex

End Sub
>==================================
Private Sub Command1_Click()
    Dim strHex, strAsc As String

    strAsc = "ABCDabcd"
    strHex = ""
    For m = 1 To Len(strAsc)
       strHex = strHex + Hex(Asc(Mid(strAsc, m, 1))) + " "
    Next
    
    Text2.Text = strHex

End Sub
>===================================


** Edit ** code.gif

This post has been edited by no2pencil: 6 Oct, 2008 - 11:19 PM
User is offlineProfile CardPM
+Quote Post

akhileshbc
RE: Visual Basic Problem
6 Oct, 2008 - 11:09 PM
Post #3

D.I.C Head
Group Icon

Joined: 26 Sep, 2008
Posts: 177



Thanked: 3 times
Dream Kudos: 50
My Contributions
QUOTE
I am trying to convert ASCII string into hex and I am using the following function to accomplish that.
CODE

Private Function HexString(EvalString As String) As String
Dim intStrLen As Integer
Dim intLoop As Integer
Dim strHex As String

EvalString = Trim(EvalString)

intStrLen = Len(EvalString)
For intLoop = 1 To intStrLen
strHex = strHex & " " & Hex(Asc(Mid(EvalString, intLoop, 1)))
Next
HexString = strHex
End Function

However this function is not giving the right results.
Can anybody tell what is the error?


Hello hit,
There is no error with your function... smile.gif Do you find any error on running it....???

Try converting something like this: "a<A"

User is offlineProfile CardPM
+Quote Post

hit
RE: Visual Basic Problem
7 Oct, 2008 - 05:47 AM
Post #4

New D.I.C Head
*

Joined: 14 Sep, 2008
Posts: 7

QUOTE(akhileshbc @ 7 Oct, 2008 - 12:09 AM) *

QUOTE
I am trying to convert ASCII string into hex and I am using the following function to accomplish that.
CODE

Private Function HexString(EvalString As String) As String
Dim intStrLen As Integer
Dim intLoop As Integer
Dim strHex As String

EvalString = Trim(EvalString)

intStrLen = Len(EvalString)
For intLoop = 1 To intStrLen
strHex = strHex & " " & Hex(Asc(Mid(EvalString, intLoop, 1)))
Next
HexString = strHex
End Function

However this function is not giving the right results.
Can anybody tell what is the error?


Hello hit,
There is no error with your function... smile.gif Do you find any error on running it....???

Try converting something like this: "a<A"



well, there is. it shows 0 instead of 00 and 1 instead of 01..........

User is offlineProfile CardPM
+Quote Post

thava
RE: Visual Basic Problem
7 Oct, 2008 - 04:59 PM
Post #5

D.I.C Regular
Group Icon

Joined: 17 Apr, 2007
Posts: 450



Thanked: 18 times
Dream Kudos: 50
My Contributions
may i know that string value

if possible i can solve it

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 12:46AM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month