luvbox
Member Since: 1998/07/24
Tech Certifications:

Provide a quick, creative biography in 140 characters or less.

More bio
Activity
Points this month0
Total points400
Questions:
Solutions: 2
Articles:
Videos:
Tutorials:
Posts:
Professional Background
No Professional Background shown
More
Education
No Education Background shown
More
Full Biography

'jast place this in your project
VERSION 2.00
Begin Form Form1
   Caption         =   "Form1"
   ClientHeight    =   2070
   ClientLeft      =   1095
   ClientTop       =   1485
   ClientWidth     =   4800
   Height          =   2475
   Left            =   1035
   LinkTopic       =   "Form1"
   ScaleHeight     =   2070
   ScaleWidth      =   4800
   Top             =   1140
   Width           =   4920
   Begin TextBox Text2
      Height          =   285
      Left            =   360
      TabIndex        =   3
      Top             =   1320
      Width           =   4335
   End
   Begin TextBox Text1
      Height          =   285
      Left            =   360
      TabIndex        =   1
      Top             =   480
      Width           =   3015
   End
   Begin Label Label2
      Caption         =   "Display Binary len = 30"
      Height          =   255
      Left            =   360
      TabIndex        =   2
      Top             =   840
      Width           =   2295
   End
   Begin Label Label1
      Caption         =   "Enter Decimal"
      Height          =   255
      Left            =   360
      TabIndex        =   0
      Top             =   120
      Width           =   1935
   End
End
Sub Text1_Change ()
Dim i As Long, x As Long, bin As String
      Const maxpower = 30   ' Maximum number of binary digits supported.

      Text1.MaxLength = 9   ' Maximum number of decimal digits allowed.
      Text2.Enabled = False ' Prevent typing in second text box.
      bin = ""  'Build the desired binary number in this string, bin.
      x = Val(Text1.Text) 'Convert decimal string in text1 to long integer

      If x > 2 ^ maxpower Then
         MsgBox "Number must be no larger than " & Str$(2 ^ maxpower)
         Text2.Text = ""
         Exit Sub
      End If

      ' Here is the heart of the conversion from decimal to binary:

      ' Negative numbers have "1" in the 32nd left-most digit:
      If x < 0 Then bin = bin + "1" Else bin = bin + "0"

      For i = maxpower To 0 Step -1
         If x And (2 ^ i) Then   ' Use the logical "AND" operator.
            bin = bin + "1"
         Else
            bin = bin + "0"
         End If
      Next
      Text2.Text = bin  ' The bin string contains the binary number.

End Sub

More
Languages
No Languages shown

Level Progress

Current: Level 0
luvbox needs 1,600 points to level up.
LVL 1
  • Overall
    0