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.....
Right before bedtime I created a little Function for you that will convert a Hexadecimal String to a 'Plain Olde ASCII' String. Here goes: - Function Definition:
- Public Function fConvertHexToString(strHexString As String) As String
-
Dim intLenOfString As Integer
-
Dim intCounter As Integer
-
Dim strBuild As String
-
-
'Hex String must have a valid length, and it must be an even length
-
If Len(strHexString) = 0 Or Len(strHexString) Mod 2 <> 0 Then Exit Function
-
-
intLenOfString = Len(strHexString)
-
-
For intCounter = 1 To Len(strHexString)
-
If intCounter Mod 2 <> 0 Then 'need Hex pairs
-
'Retrieve the Value of the Hex Pair, then Convert to a Character,
-
'then Append to a Base String
-
strBuild = strBuild & Chr$(Val("&H" & Mid$(strHexString, intCounter, 2)))
-
End If
-
Next
- Sample Call:
- Debug.Print fConvertHexToString("7378786775707461204F4B3F")
- OUTPUT from Function Call:
- Any questions, feel free to ask. If you need help implementing it in a Query, just let us know.
- Lights Out! ADezii has left the building!
13 14906
Right before bedtime I created a little Function for you that will convert a Hexadecimal String to a 'Plain Olde ASCII' String. Here goes: - Function Definition:
- Public Function fConvertHexToString(strHexString As String) As String
-
Dim intLenOfString As Integer
-
Dim intCounter As Integer
-
Dim strBuild As String
-
-
'Hex String must have a valid length, and it must be an even length
-
If Len(strHexString) = 0 Or Len(strHexString) Mod 2 <> 0 Then Exit Function
-
-
intLenOfString = Len(strHexString)
-
-
For intCounter = 1 To Len(strHexString)
-
If intCounter Mod 2 <> 0 Then 'need Hex pairs
-
'Retrieve the Value of the Hex Pair, then Convert to a Character,
-
'then Append to a Base String
-
strBuild = strBuild & Chr$(Val("&H" & Mid$(strHexString, intCounter, 2)))
-
End If
-
Next
- Sample Call:
- Debug.Print fConvertHexToString("7378786775707461204F4B3F")
- OUTPUT from Function Call:
- Any questions, feel free to ask. If you need help implementing it in a Query, just let us know.
- Lights Out! ADezii has left the building!
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...?
- SELECT ActionList_1.arg1, Converthex([arg1]) AS arg11
-
FROM ActionList_1
-
WITH OWNERACCESS OPTION;
I have called your public function "Converthex" instead of fConvertHexToString. Otherwise everthing else is the same. - Public Function Converthex(strHexString As String) As String
-
Dim intLenOfString As Integer
-
Dim intCounter As Integer
-
Dim strBuild As String
-
-
'Hex String must have a valid length, and it must be an even length
-
If Len(strHexString) = 0 Or Len(strHexString) Mod 2 <> 0 Then Exit Function
-
-
intLenOfString = Len(strHexString)
-
-
For intCounter = 1 To Len(strHexString)
-
If intCounter Mod 2 <> 0 Then 'need Hex pairs
-
'Retrieve the Value of the Hex Pair, then Convert to a Character,
-
'then Append to a Base String
-
strBuild = strBuild & Chr$(Val("&H" & Mid$(strHexString, intCounter, 2)))
-
End If
-
Next
-
-
End Function
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".
@NeoPa
Thanks NeoPa, it's the Olde Val() Trick! (LOL)
@sxxgupta - The Field used to 'Call' this Function is a Calculated Field, and in the Query grid should look like:
- Are you sure that Converthex() is a 'Public' Function and 'NOT' a Public Sub-Routine?
- As requested by NeoPa, kindly post a Result Set.
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 : - fConvertHexToString = strBuild
-
End Function
@NeoPa
My apologies to you and the OP. You are, of course, 100% correct.
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.
Thank you everyone for their help.
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!
@subedimite
Debug.Print Hex$(Val(&H40)) will return the String 40
Sign in to post your reply or Sign up for a free account.
Similar topics
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)
...
|
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...
|
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...
|
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...
|
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
|
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...
|
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...
|
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.
|
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() ==...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |