Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Binary convertion

Posted on 1998-07-25
3
Medium Priority
?
243 Views
Last Modified: 2010-05-03
Can anyone tell me how to convert decimal to binary in VB?
0
Comment
Question by:twosons
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 2

Expert Comment

by:chris_a
ID: 1466672
I assume you mean '7' -> 0000 0111

The usual way to do this is to see if it is odd then divide by 2 in a loop.
0
 
LVL 7

Accepted Solution

by:
kamall earned 50 total points
ID: 1466673
On your form, put 2 text boxes and one command button. Copy and paste the following code in the general-declarations section of the form:

Private Sub Command1_Click()

    DecValue = Val(Text1.Text)
   
    BinValue = ""
   
    Do
    TempValue = DecValue Mod 2
        BinValue = CStr(TempValue) + BinValue
    DecValue = DecValue \ 2
    Loop Until DecValue = 0
   
    'Print
    'Print BinValue
   
    Text2.Text = BinValue

End Sub

Run the project, enter your number in the Text1 box and click the command button. Text2 text box will show the binary value of the number.

Hope that helps.
Regards
0
 

Author Comment

by:twosons
ID: 1466674
Thank you very much "kamall".  I knew the loop structure you have mentioned, but I was hoping to see if there is any other way to convert to binary, like "oct(number), hex(number)" in VB.
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question