473,386 Members | 1,841 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,386 software developers and data experts.

hex to text(ascii) conversion

I have a xml file that I import to access and I have two fields that are in the hex format. Is there away to convert those fields to text within access? I am thinking to do it after the import or should I do it on import?

Thanks,

Also thanks for all previous help, much appreciated.
Jan 2 '08 #1
10 18991
FishVal
2,653 Expert 2GB
Hi, there.

Import hex number to a text field of a table (tbl.txtHex in the example). Run the following query:
Expand|Select|Wrap|Line Numbers
  1. UPDATE tbl SET tbl.txtHex = Chr(Val("&H" & [txtHex]));
  2.  
Regards,
Fish

P.S. Assumed you have two-digit hexadecimal number.
Jan 2 '08 #2
thanks i'll give it a try. I will post back success or failure.
Jan 2 '08 #3
it is a base 16 hexadecimal number i think. The field has 1024 characters. I guess that makes that query not work or am i missing something? If that query would still apply, then i get the error that it is not updatable.
Jan 2 '08 #4
FishVal
2,653 Expert 2GB
it is a base 16 hexadecimal number i think. The field has 1024 characters. I guess that makes that query not work or am i missing something? If that query would still apply, then i get the error that it is not updatable.
More details would be nice.
So, you mean hexadecimal number with more than 2 hexadecimal digits (this means more than 1 ASCII character). So far so good.
Have you import the data to an Access table? What is the type of field in the table where this hexadecimal number is stored?
Jan 2 '08 #5
thanks FishVal. I do have the data in an access table, and the column name is called RemoteData with a data type memo(used memo because on importing the xml file, the RemoteData node had 1024 characters or less).

Here is a sample of my data in one of the fields:

Expand|Select|Wrap|Line Numbers
  1. 485454502f312e3120323030204f4b0d0a446174653a205475652c2031382044656320323030372031323a35323a323320474d540d0a5365727665723a204170616368652f322e302e3532202843656e744f53290d0a4c6173742d4d6f6469666965643a204672692c203138204d61722032303035
Which using an online converter should be converted to:

Expand|Select|Wrap|Line Numbers
  1. HTTP/1.1 200 OK
  2.  
  3. Date: Tue, 18 Dec 2007 12:52:23 GMT
  4.  
  5. Server: Apache/2.0.52 (CentOS)
  6.  
  7. Last-Modified: Fri, 18 Mar 2005
Anything else should I provide?
Jan 2 '08 #6
FishVal
2,653 Expert 2GB
Quite enough. Try this.

Expand|Select|Wrap|Line Numbers
  1. Public Function Hex2ASCII(strInput As Variant) As Variant
  2.  
  3.     'if field is null then exit function
  4.     If IsNull(strInput) Then Exit Function
  5.     'make number of digits even
  6.     If Len(strInput) / 2 <> Int(Len(strInput) / 2) Then strInput = "0" & strInput
  7.     'convert hex codes to ASCII
  8.     For i = 1 To Len(strInput) Step 2
  9.         Hex2ASCII = Hex2ASCII & Chr(Val("&H" & Mid(strInput, i, 2)))
  10.     Next i
  11.  
  12. End Function
  13.  
Expand|Select|Wrap|Line Numbers
  1. UPDATE tbl SET tbl.txtHex = Hex2ASCII([txtHex]);
  2.  
Jan 2 '08 #7
ADezii
8,834 Expert 8TB
I have a xml file that I import to access and I have two fields that are in the hex format. Is there away to convert those fields to text within access? I am thinking to do it after the import or should I do it on import?

Thanks,

Also thanks for all previous help, much appreciated.
I followed in FishVal's footsteps but only took a different approach. I Delimited the String by the Carriage Return/Line Feed Characters (0d0a in Hex), then used the Split() Function to populate a Variant Array which would then consist of each sentence (terminated by 0d0a). I then used FishVal's code to convert each Byte. The code and subsequent Output are listed below. If you have any problem implementing this approach, let us know:
Expand|Select|Wrap|Line Numbers
  1. Dim strHex As String, varHex As Variant, intCounter As Integer
  2. Dim T, strString As String
  3.  
  4. strHex = "485454502f312e3120323030204f4b0d0a446174653a205475" & _
  5.          "652c2031382044656320323030372031323a35323a323320474" & _
  6.          "d540d0a5365727665723a204170616368652f322e302e3532202" & _
  7.          "843656e744f53290d0a4c6173742d4d6f6469666965643a2046" & _
  8.          "72692c203138204d61722032303035"
  9.  
  10. varHex = Split(strHex, "0d0a")
  11.  
  12. For intCounter = LBound(varHex) To UBound(varHex)
  13.   For T = 1 To Len(varHex(intCounter)) Step 2
  14.     strString = strString & Chr$(Val("&H" & Mid$(varHex(intCounter), T, 2)))
  15.   Next
  16.     Debug.Print strString
  17.     strString = ""        'Reset String
  18. Next
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1. HTTP/1.1 200 OK
  2. Date: Tue, 18 Dec 2007 12:52:23 GMT
  3. Server: Apache/2.0.52 (CentOS)
  4. Last-Modified: Fri, 18 Mar 2005
P.S. - FishVal, Hope you didn't mind the intrusion, just found this problem interesting. If I stepped on your toes, I do apologize.
Jan 3 '08 #8
FishVal
2,653 Expert 2GB
P.S. - FishVal, Hope you didn't mind the intrusion, just found this problem interesting. If I stepped on your toes, I do apologize.
Hello, ADezii.

Apologies not needed. I appreciate every comment concerning my posts.
Jan 3 '08 #9
FishVal and ADezii thank you so much. I greatly appreciate it.

FishVal I got yours to work flawless and fast. ADezii I kept getting a compile error: invalid outside procedure. I haven't had time to look into it, but it hopefully i can figure it out.

Thanks once again.
Jan 3 '08 #10
ADezii
8,834 Expert 8TB
FishVal and ADezii thank you so much. I greatly appreciate it.

FishVal I got yours to work flawless and fast. ADezii I kept getting a compile error: invalid outside procedure. I haven't had time to look into it, but it hopefully i can figure it out.

Thanks once again.
Very interesting, I had no problem running this code in Access 2000 and 2003. If you find out what the problem is, please let me know. In any event, I'm glad you got FishVal's code to work flawlessly. Glad we were able to assist you, I'm not speaking for FishVal, but I'm sure he will feel the same way also. See you around.
Jan 3 '08 #11

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

Similar topics

1
by: Timothy Rue | last post by:
I found the online and free PHP manual(s) but what I need is one that is plain text/ascii Is there such a beast and if not what is the closest to it? I'd like to do my own markup on it. ...
2
by: Albert Tu | last post by:
Hi, I am learning and pretty new to Python and I hope your guys can give me a quick start. I have an about 1G-byte binary file from a flat panel x-ray detector; I know at the beggining there...
0
by: Alison | last post by:
I have data in an oracle9i database that is in RTF format and I need to convert it to text format.. I have not found a way to do it with SQL or PL/SQL. Is there a tool that can access the db an...
1
by: Calvin Lai | last post by:
If my data in SQL server was stored from a web application with requestEncoding set as iso8859-1. And now I want to change the data encoding to big5, (or anything else), how could I do that? Thanks...
0
by: Knut-Olav Traa | last post by:
Hello, I need a component that transfers html strings to text format. The component must format the text nice, and not just strip off the html-tags. For example: The tabledata should be formated...
0
by: sandeep Naredla via .NET 247 | last post by:
(Type your message here) I need a code for extracting Text from PDF files without having to use any third party tools in C#.Although there are many free API's in Java available i need one for...
8
by: Benjamin Bécar | last post by:
Hello everyone. I have to find a correct architecture to achieve this XML <=Text conversion platform. The platform (based on Win2003Server) will have to deal with 21 million XML files and 16...
4
by: =?Utf-8?B?Um9zaGFuIFIuRA==?= | last post by:
Hi All, I am new to C# programming; I am developing an application for recording audio data using voice modem. I am using HyperTerminal to manually process audio data. The modem when configured...
10
by: shwetamodi | last post by:
I have find this code of converting numeric to text but it displays wrong result for 1000000 ten lakh and for all lakh values. Can anybody help me to correct this code. <% ss =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.