Results 1 to 5 of 5
  1. #1
    Access_Novice is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Posts
    265

    Converting a text string to its ASCII value


    Let's say I have a string that includes mm/dd/yyyy + person's name. All of this is concatenated and is recognized as a text value. Then I want to convert all of these characters to a number. Since each character has an ASCII code, I would like to find ASCII equivalent.

    In Excel, this would involve using something like the CODE ( ) function, but that only gives the numerical equivalent for the first character in the string, but I want all characters at once.

    When I try the VAL ( ) function, it returns the first character which is the number of the month.

  2. #2
    Rawb is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    I'm not sure exactly what you're trying to do. Are you wanting to convert a text string into a list of ASCII values (one number for each character in the string) so you can store each one separately? Are you trying to add all the values together (sum them)? Are you wanting to just concatenate them all together into one big number?

    Also be aware that, especially if your program is going to be used to parse text strings from a word processing program (Like Wordpad, MS Word, OOo Writer, or Google Docs) or in non-english languages, it's possible to run into characters that don't exist in the ASCII character map.

    Can you tell us more about what you're trying to accomplish and why?

  3. #3
    Access_Novice is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Posts
    265
    Quote Originally Posted by Rawb View Post
    I'm not sure exactly what you're trying to do. Are you wanting to convert a text string into a list of ASCII values (one number for each character in the string) so you can store each one separately? Are you trying to add all the values together (sum them)? Are you wanting to just concatenate them all together into one big number?

    Also be aware that, especially if your program is going to be used to parse text strings from a word processing program (Like Wordpad, MS Word, OOo Writer, or Google Docs) or in non-english languages, it's possible to run into characters that don't exist in the ASCII character map.

    Can you tell us more about what you're trying to accomplish and why?
    I plan to use a table of data where many of the rows are the same except for the date. For example, I might have a concatenated value of 1/1/2015Johnson,Barry and 03/1/2015Johnson,Barry, each with a different billing rate. I was thinking that in order to differentiate between the two, I would convert the concatenated values to their ASCII equivalent (the code for each character would be summed) and the instance with the later date would have a higher numerical value.

    Then in order to get the billing rate tied to that value, I would do something like DLOOKUP where the and take the higher concatenated value or something to that effect.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850
    Can I suggest that you do not have to concoct some sort of concatenation. Database works very well when you put 1 fact in 1 field.
    Please tell us - in plain English - WHAT you are trying to accomplish. Once readers understand that, they may have options on how it may be accomplished. But we have to understand the issue before focused responses can be made.

  5. #5
    Rawb is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    I agree with orange. At the very least, you should split the date portion out into its own Column in the Table if at all possible. This would accomplish 3 things:
    • It would simplify and speed up your date comparisons - You wouldn't have to worry about cutting apart data in a single Column. And since Date/Time Columns are stored as numbers instead of Text strings, the comparison (between multiple dates) would be computationally less intense as well.
    • It would save space in the database to store the data in an actual Date/Time Column - Since Date/Time Columns are stored as numbers, they take up less space than a date stored as a Text string.
    • It would force consistency - Date/Time Columns would allow you to control display of your data without changing how it's stored in the database or how much space it takes. For example, you will be able to control if the dates have leading zeroes or not or if you have a two-digit year or a four-digit year. And it would let you display the data using those rules even if users enter data without following them.

    P.S.
    Summing characters like you want could also lead to inconsistent results: Using your method 04/02/2015 and 03/03/2015 would have the same values even though they are clearly different dates.
    Last edited by Rawb; 03-19-2015 at 10:32 PM. Reason: Added P.S. note

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Converting a string to date/time
    By RayMilhon in forum Programming
    Replies: 8
    Last Post: 09-28-2012, 10:02 AM
  2. OpenTextFile, unicode/ascii
    By dssrun in forum Programming
    Replies: 4
    Last Post: 11-23-2011, 01:22 PM
  3. Converting Pictures to Base64 string and back
    By djoosten in forum Programming
    Replies: 4
    Last Post: 03-14-2011, 03:40 AM
  4. Replies: 2
    Last Post: 07-03-2010, 08:45 PM
  5. Converting/Viewing OLE Data as String...
    By oldgem in forum Access
    Replies: 0
    Last Post: 09-12-2009, 06:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums