Results 1 to 4 of 4

Thread: Denary To Binary

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    11

    Red face

    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

  2. #2
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    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.

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    11

    Oh sorry

    Any whole number. And if it is not too hard decimals as well.

    Thanks

    Mike

  4. #4

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    11

    Talking 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
  •  



Click Here to Expand Forum to Full Width