473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

convert hex to string

How do I convert Hext code output from a MySQL db to a string output in an Access db. Currently, the file is output in Excel format that I import into my access db. I have very limited knowledge about vba but am knowledgeable in creating queries, reports etc. I need a public function that I can call in my query to perform this conversion.

I got this link for this site
http://bytes.com/topic/visual-basic-...ert-hex-string

But I keep getting vba errors that are syntax related and I have no clue.....
Sep 28 '09 #1

✓ answered by ADezii

Right before bedtime I created a little Function for you that will convert a Hexadecimal String to a 'Plain Olde ASCII' String. Here goes:
  1. Function Definition:
    Expand|Select|Wrap|Line Numbers
    1. Public Function fConvertHexToString(strHexString As String) As String
    2. Dim intLenOfString As Integer
    3. Dim intCounter As Integer
    4. Dim strBuild As String
    5.  
    6. 'Hex String must have a valid length, and it must be an even length
    7. If Len(strHexString) = 0 Or Len(strHexString) Mod 2 <> 0 Then Exit Function
    8.  
    9. intLenOfString = Len(strHexString)
    10.  
    11. For intCounter = 1 To Len(strHexString)
    12.   If intCounter Mod 2 <> 0 Then     'need Hex pairs
    13.     'Retrieve the Value of the Hex Pair, then Convert to a Character,
    14.     'then Append to a Base String
    15.     strBuild = strBuild & Chr$(Val("&H" & Mid$(strHexString, intCounter, 2)))
    16.   End If
    17. Next
  2. Sample Call:
    Expand|Select|Wrap|Line Numbers
    1. Debug.Print fConvertHexToString("7378786775707461204F4B3F")
  3. OUTPUT from Function Call:
    Expand|Select|Wrap|Line Numbers
    1. sxxgupta OK?
  4. Any questions, feel free to ask. If you need help implementing it in a Query, just let us know.
  5. Lights Out! ADezii has left the building!

13 14906
ADezii
8,834 Expert 8TB
Right before bedtime I created a little Function for you that will convert a Hexadecimal String to a 'Plain Olde ASCII' String. Here goes:
  1. Function Definition:
    Expand|Select|Wrap|Line Numbers
    1. Public Function fConvertHexToString(strHexString As String) As String
    2. Dim intLenOfString As Integer
    3. Dim intCounter As Integer
    4. Dim strBuild As String
    5.  
    6. 'Hex String must have a valid length, and it must be an even length
    7. If Len(strHexString) = 0 Or Len(strHexString) Mod 2 <> 0 Then Exit Function
    8.  
    9. intLenOfString = Len(strHexString)
    10.  
    11. For intCounter = 1 To Len(strHexString)
    12.   If intCounter Mod 2 <> 0 Then     'need Hex pairs
    13.     'Retrieve the Value of the Hex Pair, then Convert to a Character,
    14.     'then Append to a Base String
    15.     strBuild = strBuild & Chr$(Val("&H" & Mid$(strHexString, intCounter, 2)))
    16.   End If
    17. Next
  2. Sample Call:
    Expand|Select|Wrap|Line Numbers
    1. Debug.Print fConvertHexToString("7378786775707461204F4B3F")
  3. OUTPUT from Function Call:
    Expand|Select|Wrap|Line Numbers
    1. sxxgupta OK?
  4. Any questions, feel free to ask. If you need help implementing it in a Query, just let us know.
  5. Lights Out! ADezii has left the building!
Sep 29 '09 #2
Hi ADezii:

I called this function in my query. The query runs and opens up in access but the field that I use to call this function does not show me any strings...?
Sep 29 '09 #3
ADezii
8,834 Expert 8TB
@sxxgupta
Kindly post the SQL Statement.
Sep 29 '09 #4
Expand|Select|Wrap|Line Numbers
  1. SELECT ActionList_1.arg1, Converthex([arg1]) AS arg11
  2. FROM ActionList_1
  3. WITH OWNERACCESS OPTION;
I have called your public function "Converthex" instead of fConvertHexToString. Otherwise everthing else is the same.
Expand|Select|Wrap|Line Numbers
  1. Public Function Converthex(strHexString As String) As String
  2. Dim intLenOfString As Integer
  3. Dim intCounter As Integer
  4. Dim strBuild As String
  5.  
  6. 'Hex String must have a valid length, and it must be an even length
  7. If Len(strHexString) = 0 Or Len(strHexString) Mod 2 <> 0 Then Exit Function
  8.  
  9. intLenOfString = Len(strHexString)
  10.  
  11. For intCounter = 1 To Len(strHexString)
  12.   If intCounter Mod 2 <> 0 Then     'need Hex pairs
  13.     'Retrieve the Value of the Hex Pair, then Convert to a Character,
  14.     'then Append to a Base String
  15.     strBuild = strBuild & Chr$(Val("&H" & Mid$(strHexString, intCounter, 2)))
  16.   End If
  17. Next
  18.  
  19. End Function
Sep 29 '09 #5
NeoPa
32,556 Expert Mod 16PB
@sxxgupta
How about posting some of the results from this query. Just ten reccords say.

PS. Nice one ADezii. I didn't know Val() could handle "&H".
Sep 29 '09 #6
ADezii
8,834 Expert 8TB
@NeoPa
Thanks NeoPa, it's the Olde Val() Trick! (LOL)
Sep 29 '09 #7
ADezii
8,834 Expert 8TB
@sxxgupta
  1. The Field used to 'Call' this Function is a Calculated Field, and in the Query grid should look like:
    Expand|Select|Wrap|Line Numbers
    1. arg11:Converthex([arg1])
  2. Are you sure that Converthex() is a 'Public' Function and 'NOT' a Public Sub-Routine?
  3. As requested by NeoPa, kindly post a Result Set.
Sep 29 '09 #8
NeoPa
32,556 Expert Mod 16PB
@ADezii
No. From the code posted it may be a function, but it never assigns a value.

"Why?" one asks oneself. Looking at post #2 it becomes evident. You left off the code after line #17. The line, I suspect, where you assigned the value in your original code :D

I suspect the missing lines would have been something like :
Expand|Select|Wrap|Line Numbers
  1. fConvertHexToString = strBuild
  2. End Function
Sep 29 '09 #9
ADezii
8,834 Expert 8TB
@NeoPa
My apologies to you and the OP. You are, of course, 100% correct.
Sep 29 '09 #10
NeoPa
32,556 Expert Mod 16PB
@ADezii
Apologies?? You gave me a giggle. What's to be sorry for :D

I'm sure that will be all that's required for the OP to get his code working. ... most of which was supplied by you originally I need hardly add.
Sep 29 '09 #11
Thank you everyone for their help.
Sep 30 '09 #12
For the function Converthex()

I can see that if I pass the parameter say 40 hex ( as number, For this I change the function argument type to avariant). It will convert into the Ascii value @.
Is there any function that will convert 40 Hex ( number) into "40" text?

Cheers!
Apr 20 '10 #13
ADezii
8,834 Expert 8TB
@subedimite
Debug.Print Hex$(Val(&H40)) will return the String 40
Apr 20 '10 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Joel Moore | last post by:
Maybe I'm just easily baffled after an all-nighter but I can't seem to figure out how to represent a BitArray as a hexadecimal string. For example: Dim outputBank As New BitArray(8) ...
4
by: Eric Lilja | last post by:
Hello, I've made a templated class Option (a child of the abstract base class OptionBase) that stores an option name (in the form someoption=) and the value belonging to that option. The value is...
4
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
3
by: Convert TextBox.Text to Int32 Problem | last post by:
Need a little help here. I saw some related posts, so here goes... I have some textboxes which are designed for the user to enter a integer value. In "old school C" we just used the atoi function...
7
by: patang | last post by:
I want to convert amount to words. Is there any funciton available? Example: $230.30 Two Hundred Thirty Dollars and 30/100
6
by: patang | last post by:
Could someone please tell me where am I supposed to put this code. Actually my project has two forms. I created a new module and have put the following code sent by someone. All the function...
3
by: GM | last post by:
Dear all, Could you all give me some guide on how to convert my big5 string to unicode using python? I already knew that I might use cjkcodecs or python 2.4 but I still don't have idea on what...
4
by: tshad | last post by:
I am trying to convert a string character to an int where the string is all numbers. I tried: int test; string stemp = "5"; test = Convert.ToInt32(stemp); But test is equal to 53.
9
by: Marco Nef | last post by:
Hi there I'm looking for a template class that converts the template argument to a string, so something like the following should work: Convert<float>::Get() == "float"; Convert<3>::Get() ==...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.