Important alert: (current site time 7/16/2013 1:43:57 AM EDT)
 

VB icon

* Make your own Active X Binary Control!!! *

Email
Submitted on: 4/24/1999
By: Matt Evans 
Level: Not Given
User Rating: By 12 Users
Compatibility: VB 3.0, VB 4.0 (16-bit), VB 4.0 (32-bit), VB 5.0, VB 6.0
Views: 45043
 
     * This is the code to put in the General place of you UserControl. By Doing this you can make a Active-X control that Makes Text to Binary, Binary to Text, and to see if a string is Binary! *
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: * Make your own Active X Binary Control!!! *
' Description:* This is the code to put in the General place of you UserControl. By Doing this you can make a Active-X control that Makes Text to Binary, Binary to Text, and to see if a string is Binary! *
' By: Matt Evans
'
' Inputs:Text to change
'
' Returns:Changed text
'
' Assumes:none!!! easy for beginners!
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=1653&lngWId=1'for details.'**************************************

'enjoy! ;D
'put this in a module, we don't want the user to
'see this lil function, he has no need too
Public Function ChrAscii(Char As String) As Long
 Dim GetAscii&
 For GetAscii& = 0 To 255
If Mid(Char$, 1, 1) = Chr(GetAscii) Then
 ChrAscii = GetAscii
Exit Function
End If
 Next GetAscii&
End Function
'Double Click on the user control, and in the General Declarations
'Put this... these are the subs the you will use
Public Function TextToBinary(StringT As String) As String
Dim Ascii, FinalBinary$, GetNum&
FinalBinary$ = ""
For GetNum& = 1 To Len(StringT$)
 Ascii = ChrAscii(Mid(StringT$, GetNum, 1))
' 128
 If Ascii >= 128 Then
 FinalBinary$ = FinalBinary$ & "1"
Ascii = Ascii - 128
 Else
FinalBinary$ = FinalBinary$ & "0"
 End If
 
 ' 64
 If Ascii >= 64 Then
FinalBinary$ = FinalBinary$ & "1"
Ascii = Ascii - 64
 Else
FinalBinary$ = FinalBinary$ & "0"
 End If
 
 ' 32
 If Ascii >= 32 Then
FinalBinary$ = FinalBinary$ & "1"
Ascii = Ascii - 32
 Else
FinalBinary$ = FinalBinary$ & "0"
 End If
 
 ' 16
 If Ascii >= 16 Then
FinalBinary$ = FinalBinary$ & "1"
Ascii = Ascii - 16
 Else
FinalBinary$ = FinalBinary$ & "0"
 End If
 
 ' 8
 If Ascii >= 8 Then
FinalBinary$ = FinalBinary$ & "1"
Ascii = Ascii - 8
 Else
FinalBinary$ = FinalBinary$ & "0"
 End If
 
 ' 4
 If Ascii >= 4 Then
FinalBinary$ = FinalBinary$ & "1"
Ascii = Ascii - 4
 Else
FinalBinary$ = FinalBinary$ & "0"
 End If
 
 ' 2
If Ascii >= 2 Then
 FinalBinary$ = FinalBinary$ & "1"
 Ascii = Ascii - 2
Else
 FinalBinary$ = FinalBinary$ & "0"
End If
 
 ' 1
If Ascii >= 1 Then
 FinalBinary$ = FinalBinary$ & "1"
 Ascii = Ascii - 1
Else
 FinalBinary$ = FinalBinary$ & "0"
End If
If Mid(StringT$, GetNum + 1, 1) = Chr(32) Then
FinalBinary$ = FinalBinary$ '& " "
Else
FinalBinary$ = FinalBinary$ '& Chr(32)
End If
 Next GetNum&
 TextToBinary$ = FinalBinary$
End Function
Public Function BinaryToText(BinaryString As String) As String
Dim GetBinary&, Num$, Binary&, FinalString$, NewString$
NextChr:
For GetBinary& = 1 To 8
 Num$ = Mid(BinaryString$, GetBinary&, 1)
 Select Case Num$
 
Case "1"
If GetBinary = 1 Then
 Binary = Binary + 128
ElseIf GetBinary = 2 Then
 Binary = Binary + 64
ElseIf GetBinary = 3 Then
 Binary = Binary + 32
ElseIf GetBinary = 4 Then
 Binary = Binary + 16
ElseIf GetBinary = 5 Then
Binary = Binary + 8
ElseIf GetBinary = 6 Then
Binary = Binary + 4
ElseIf GetBinary = 7 Then
Binary = Binary + 2
ElseIf GetBinary = 8 Then
Binary = Binary + 1
End If
End Select
 Next GetBinary&
FinalString$ = FinalString$ & Chr(Binary)
NewString$ = Mid(BinaryString$, 9)
 
 If NewString$ = "" Then
BinaryToText$ = FinalString$
 Else
BinaryString$ = NewString$
Binary = 0
GoTo NextChr
 End If
End Function
Public Function IsBinary(StringB As String) As Boolean
Dim XX$, GetLet&
For GetLet& = 1 To Len(StringB$)
 XX$ = Mid(StringB$, GetLet&, 1)
 If XX$ <> "0" Or XX$ <> "1" Then
If XX$ = "0" Or XX$ = "1" Then GoTo GetNext
IsBinary = False
Exit Function
 Else
'''
 End If
GetNext:
Next GetLet&
IsBinary = True
 End Function


Other 11 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Not Given category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
6/29/1999 8:41:00 PMTJ

Any tips on decoding UUE's to Binary (And saving to file???)
(If this comment was disrespectful, please report it.)

 
10/2/1999 7:30:00 AMzaid farooqui

Hi there,

i seem to be getting an error saying "System Error. Colintialize has not been called" after i end my program. hope someone could help me!!!

thanks
(If this comment was disrespectful, please report it.)

 
1/30/2000 5:34:35 AMketanpatel

excellent coding
Is it possible to transfer oscilloscope waveform on pc Buffer using mscomm control
reply me

(If this comment was disrespectful, please report it.)

 
2/18/2000 3:44:24 AMjanum

Keep It up Matt Evans
(If this comment was disrespectful, please report it.)

 
7/12/2000 4:58:59 AMHoyoung Hwang

Code is Too Long
Use Asc()


(If this comment was disrespectful, please report it.)

 
3/1/2001 1:47:10 PMIcEcOrE

It is good bit of code but I printed it out and came up with another way of doing it! Hope you don't mind!

Public Function TextToBinaryString(ByVal strText As String) As String

Dim CharHold As String * 1
Dim lngCharHold As Long
Dim MainFor As Long
Dim SubFor As Long

For MainFor = 1 To Len(strText)
CharHold = Mid(strText, MainFor, 1)
lngCharHold = Asc(CharHold)
For SubFor = 7 To 0 Step -1
If lngCharHold And CLng(1 * (2 ^ SubFor)) Then
TextToBinaryString = TextToBinaryString
(If this comment was disrespectful, please report it.)

 
8/8/2001 1:36:55 PMMetamorphisis

I have a problem here. I bought the learning edition of Visual Basic 6 and it does not have the User Control project or any other Active X project for that matter but when i download and open projects off of this site i notice that it will let me create the dll now i have succeded in creating templates for the dll and ocx out of projects from this site but how do i get everything else?

(If this comment was disrespectful, please report it.)

 
11/23/2001 4:02:52 PMMetaSoft

Metamorphisis: If you go to Google.com ,saerch for Visual Basic 5 Control Creation Edidtion, click on the first link, follow the links to the MSDN download, you can get the VB5CCE. It lets you actually compile the ActiveX. Thats whaat I do. One prob, tho: Notice its *VB5*CCE? yeh, only VB5. Ya can make UserControl in VB6Learning Ed, butcha cant compile them. Geez.
(If this comment was disrespectful, please report it.)

 
3/14/2002 11:23:44 AMCode Raper

Completly misleding outdated code!
Don't even use ASC! Slow and long way to do something simple.
Nice try but, very poor code... please dont upload such things
(If this comment was disrespectful, please report it.)

 
6/18/2002 4:26:00 PMSnowman

I agree that you should use the Asc() function, but overall, quite good.
(If this comment was disrespectful, please report it.)

 
1/3/2003 2:46:55 PM

I tried to make my own text to binary converter and came up with an idea. I'm not going to write out the whole 253 lines of code here but i taught my program to use the boolean (true/false) logic instead of the normal 0 to 9. All my output was gobledegook until i made 1 small discovery... all of the numbers inside my program were now classed as binary strings. i ended up with 11 instead of 3 etc.

P.S: Does anybody know anywhere that u can get a compiler/maker program for VB6 Working Model ?
I really want one. Also, all the pro's reading this, can u try and make me one if u can!
(If this comment was disrespectful, please report it.)

 
1/24/2003 11:09:56 PM

To All PRos, is there any way to code common words like is, are, the, and, etc??
(If this comment was disrespectful, please report it.)

 
5/12/2003 9:12:00 AM

very simple way to convert decimal into binary

'first define the variable answer
dim answer as integer
'then put this in a button

answer = TextBox1.Text + 1
'textbox1 is the number you want to convert
TextBox2.Text = (Convert.ToString(answer -1, 2))
'textbox2 is your answer

'and your done
(If this comment was disrespectful, please report it.)

 
5/28/2003 5:35:37 PMTheNeophyte

no no no.. dudes..
binary 2 decimal(binary=binary value=decimal):

For i = 0 To Len(StrReverse(Binary))
Value = Value & Mid(StrReverse(Binary), i + 1, 1)) * (2 ^ i)
Next i

and decimal 2 binary (number=decimal, value=binary):
Do Until Number < 1
If Number Mod 2 = 1 Then
Value = Value & "1"
Else
Value = Value & "0"
End If
Number = Int(Number / 2)
Loop
(If this comment was disrespectful, please report it.)

 
5/28/2003 5:47:41 PMTheNeophyte

whoa, sorry:

For i = 0 To
Len(StrReverse(Binary))
Value = Value
& Val(Mid(StrReverse(Binary), i + 1, 1))) *
(2 ^ i)
Next i

hehe. =) happy codin
(If this comment was disrespectful, please report it.)

 
9/16/2003 5:53:17 PMJohn Mikhaiel

this code gets a 3 from me because of the ASC function which he didnt use, and because its not optimized for speed, the whole Select Case couldve been replaced with a conditional If...Then. but good for trying.
(If this comment was disrespectful, please report it.)

 
8/31/2004 8:44:13 AM

koko
(If this comment was disrespectful, please report it.)

 
8/2/2005 4:01:18 PMhamed

Good
(If this comment was disrespectful, please report it.)

 
10/7/2006 7:02:05 PMTomás

i liked it a lot

its very good
(If this comment was disrespectful, please report it.)

 
11/28/2006 3:19:41 AMhardianto

i liked it, not bad
(If this comment was disrespectful, please report it.)

 
6/5/2007 7:55:47 AMMaggi

Excellent Coding
I like it....
keep it up....
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.