|
-
Nov 8th, 2000, 11:33 AM
#1
Thread Starter
New Member
I am trying to make a program that will convert a Denary number to binary. I want the user to type the denary number in the text box and then press a command button to show the binary number in a lable. Please can somone help me, as i'm quite new to VB and have to make this program today.
Thanks
Mike
-
Nov 8th, 2000, 11:40 AM
#2
Frenzied Member
Sorry.. but what's Denary?
Do you mean Decimal? (with to-the-powers with 10?)
In that case, Yonatan got a short way to do that:
Code:
Function Bin(ByVal lNum As Long) As String
Do
Bin = Chr(48 + (lNum And 1)) & Bin
lNum = lNum \ 2
Loop Until lNum = 0
End Function
and I made a longer one 
Code:
Private Function MakeBin()
Static bin As String, asc As Long
bin = ""
asc = Val(Text1.Text)
Do
'If 0 Then Exit the loop
If asc = 0 Then Exit Do
'Check if even
If asc Mod 2 = 0 Then
'If even then add 0 to the binair number
bin = "0" & bin
'and divide ascii by 2
asc = asc / 2
Else
'If odd then add 1 to the binair number
bin = "1" & bin
'Subtract 1 and divide by 2
asc = (asc - 1) / 2
End If
Loop
MakeBin = bin
End Function
Have funnn
[Edited by Jop on 11-08-2000 at 11:44 AM]
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Nov 8th, 2000, 11:45 AM
#3
Thread Starter
New Member
Oh sorry
Any whole number. And if it is not too hard decimals as well.
Thanks
Mike
-
Nov 8th, 2000, 11:48 AM
#4
Thread Starter
New Member
Great
I got it working.
Thanks
Mike
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|