I wondered if someone knew how to make a binary counter with vb?

Hello, and welcome.
Can you give us a little more information on what you're trying to do?

you mean convert char to binary code example

"5" = 00110101
"a" = 01100001

this is what you mean ?

## All 6 Replies

Hello, and welcome.
Can you give us a little more information on what you're trying to do?

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

Hello, and welcome.
Can you give us a little more information on what you're trying to do?

you mean convert char to binary code example

"5" = 00110101
"a" = 01100001

this is what you mean ?

exactly

you mean convert char to binary code example

"5" = 00110101
"a" = 01100001

this is what you mean ?

exactly

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.

``````Private Sub Form_Load()
MsgBox (char2bin("a"))
MsgBox (txt2bin("Hello World"))
End Sub

Function txt2bin(str2bin As String) As String
Dim result As String
For i = 1 To Len(str2bin)
result = result & char2bin(Mid(str2bin, i, 1))
Next i
txt2bin = result
End Function

Function char2bin(chr2bin As String) As String
Dim result As String
Dim char2asc As Integer, total As Integer
char2asc = Asc(chr2bin)
For i = 7 To 0 Step -1
If char2asc >= (total + (2 ^ i)) Then
total = total + (2 ^ i)
result = result & "1"
Else
result = result & "0"
End If
Next i
char2bin = result
End Function``````
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.