Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / December 2005

Tip: Looking for answers? Try searching our database.

Text to binary

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gary D. - 16 Dec 2005 10:29 GMT
Can anyone point me in the direction of a resource for converting standard
ASCII text into binary?

I am using Access2003. I already have VBA routines for converting decimal
numbers in binary, now I want to convert text (for very simple encryption
purposes).

Thanks
John Nurick - 16 Dec 2005 11:40 GMT
You could just use Asc() or AscW() to convert each character of text
into a number, and then use your existing routine on these numbers.

>Can anyone point me in the direction of a resource for converting standard
>ASCII text into binary?
[quoted text clipped - 4 lines]
>
>Thanks

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
Gary D. - 16 Dec 2005 16:06 GMT
>You could just use Asc() or AscW() to convert each character of text
>into a number, and then use your existing routine on these numbers.

Yes, but it doesn't give very clean results for non-alphanumceirc characters,
at least not the way I currently do it.
John Nurick - 16 Dec 2005 18:01 GMT
>>You could just use Asc() or AscW() to convert each character of text
>>into a number, and then use your existing routine on these numbers.
>
>Yes, but it doesn't give very clean results for non-alphanumceirc characters,
>at least not the way I currently do it.

I have no idea what you mean by "clean results". Asc() returns an
integer between 0 and 255, which fits into 8 binary digits.

AscW() is a bit messier because it seems that for some Unicode
characters it returns a negative integer (there being VBA not having
unsigned integer types). But if I understand it right you can use
something like this

Function AscWAsLong(S As String) As Long
 Dim L As Long
 L = AscW(S)
 If L < 0 Then L = 65536 + L
 AscWAsLong = L
End Function

to return a Long containing an integer between 0 and 65535, which fits
into 16 binary digits.

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
Gary D. - 17 Dec 2005 09:02 GMT
>>>You could just use Asc() or AscW() to convert each character of text
>>>into a number, and then use your existing routine on these numbers.
[quoted text clipped - 19 lines]
>to return a Long containing an integer between 0 and 65535, which fits
>into 16 binary digits.

Thanks for the info John. I'll have to get my head around that later.
Ideally, I wanted to translate text into binary in the sense that it would
produce something like a blob, that is, return a non-text type of value.
I don't know if that's even possible with VBA.
John Nurick - 17 Dec 2005 13:28 GMT
>Thanks for the info John. I'll have to get my head around that later.
>Ideally, I wanted to translate text into binary in the sense that it would
>produce something like a blob, that is, return a non-text type of value.
>I don't know if that's even possible with VBA.

I took your mention of "binary" to mean converting (say) 9 to  00001001
and so on.

If you want to obscure your text but don't need to protect it against
any real decryption effort, consider using a (bidirectional) function
like this:

Function ROT128(ByVal S As String) As String
 Dim j As Long
 
 For j = 1 To Len(S)
   Mid(S, j, 1) = Chr((Asc(Mid(S, j, 1)) + 128) Mod 256)
 Next
 ROT128 = S
End Function

Otherwise, a web search will probably find some encryption algorithms
implemented in VB(A).

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.