Solved

Binary convertion

Posted on 1998-07-25
3
239 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

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…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…

726 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