binary counter

Reply

Join Date: Oct 2005
Posts: 5
Reputation: selot is an unknown quantity at this point 
Solved Threads: 0
selot selot is offline Offline
Newbie Poster

binary counter

 
0
  #1
Oct 10th, 2005
I wondered if someone knew how to make a binary counter with vb?
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 70
Reputation: w00dy is an unknown quantity at this point 
Solved Threads: 2
w00dy w00dy is offline Offline
Junior Poster in Training

Re: binary counter

 
0
  #2
Oct 11th, 2005
Hello, and welcome.
Can you give us a little more information on what you're trying to do?
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 5
Reputation: selot is an unknown quantity at this point 
Solved Threads: 0
selot selot is offline Offline
Newbie Poster

Re: binary counter

 
0
  #3
Oct 11th, 2005
sure, the idea is is that I got a textbox (txtNumber). a label(lblBinary)

As you may know the binary siystem consists of to digits 1 and 0

now, what I want is for the number 5 for example, to change into binary code when I use a command button

The conde regarding the button could look something like this:

lblBinary.caption=val(txtNumber)^2

This code only doubles the number inserted. It does not produce the binary code for that number.

How do I pull this off?

Help needed

Originally Posted by w00dy
Hello, and welcome.
Can you give us a little more information on what you're trying to do?
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 466
Reputation: invisal is a jewel in the rough invisal is a jewel in the rough invisal is a jewel in the rough 
Solved Threads: 49
invisal's Avatar
invisal invisal is offline Offline
Posting Pro in Training

Re: binary counter

 
0
  #4
Oct 11th, 2005
you mean convert char to binary code example

"5" = 00110101
"a" = 01100001

this is what you mean ?
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 5
Reputation: selot is an unknown quantity at this point 
Solved Threads: 0
selot selot is offline Offline
Newbie Poster

Re: binary counter

 
0
  #5
Oct 11th, 2005
exactly

Originally Posted by invisal
you mean convert char to binary code example

"5" = 00110101
"a" = 01100001

this is what you mean ?
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 5
Reputation: selot is an unknown quantity at this point 
Solved Threads: 0
selot selot is offline Offline
Newbie Poster

Re: binary counter

 
0
  #6
Oct 11th, 2005
exactly
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 466
Reputation: invisal is a jewel in the rough invisal is a jewel in the rough invisal is a jewel in the rough 
Solved Threads: 49
invisal's Avatar
invisal invisal is offline Offline
Posting Pro in Training

Re: binary counter

 
0
  #7
Oct 11th, 2005
In this code I write 2 functions, one function convert from char to binary and another one is for convert from string to binary code.

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Form_Load()
  2. MsgBox (char2bin("a"))
  3. MsgBox (txt2bin("Hello World"))
  4. End Sub
  5.  
  6. Function txt2bin(str2bin As String) As String
  7. Dim result As String
  8. For i = 1 To Len(str2bin)
  9. result = result & char2bin(Mid(str2bin, i, 1))
  10. Next i
  11. txt2bin = result
  12. End Function
  13.  
  14. Function char2bin(chr2bin As String) As String
  15. Dim result As String
  16. Dim char2asc As Integer, total As Integer
  17. char2asc = Asc(chr2bin)
  18. For i = 7 To 0 Step -1
  19. If char2asc >= (total + (2 ^ i)) Then
  20. total = total + (2 ^ i)
  21. result = result & "1"
  22. Else
  23. result = result & "0"
  24. End If
  25. Next i
  26. char2bin = result
  27. End Function
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum


Views: 3977 | Replies: 6
Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC