Answer to Question #2706 in Visual Basic for MoMo

Question #2706
rogram Description: Write a program that has four sub procedures that will calculate and print out a table of numbers 0 to 17 in decimal, hex, octal, and binary notation.

Statements Required: output, loop control, subprogram

Sample Output: (you will design your own output but 4 adjacent label boxes would be suitable)

Base:
10 16 8 2

0 0 0 00000000
1 1 1 00000001
2 2 2 00000010
3 3 3 00000011
4 4 4 00000100
5 5 5 00000101
6 6 6 00000110
7 7 7 00000111
8 8 10 00001000
9 9 11 00001001
10 A 12 00001010
11 B 13 00001011
12 C 14 00001100
13 D 15 00001101
14 E 16 00001110
15 F 17 00001111
16 10 20 00010000
17 11 21 00010001
1
Expert's answer
2011-06-01T13:17:55-0400
.frm file:

VERSION 5.00
Begin VB.Form Form1
Caption = quot;Form1"
ClientHeight = 6015
ClientLeft = 60
ClientTop = 345
ClientWidth & = 8145
LinkTopic = quot;Form1"
ScaleHeight & = 6015
ScaleWidth = 8145
StartUpPosition = 3& 'Windows Default
Begin VB.ListBox List2
Height = 4155
Left = 6000
TabIndex & = 8
Top = 1440
Width & = 1695
End
Begin VB.ListBox List8
Height = 4155
Left = 4200
TabIndex & = 7
Top = 1440
Width & = 1695
End
Begin VB.ListBox List16
Height = 4155
Left = 2400
TabIndex & = 6
Top = 1440
Width & = 1695
End
Begin VB.ListBox List10
Height = 4155
Left = 600
TabIndex & = 5
Top = 1440
Width & = 1695
End
Begin VB.Label Label2
Caption = quot;BASE"
Height = 255
Left = 720
TabIndex & = 4
Top = 360
Width & = 1935
End
Begin VB.Label Label1
Alignment = 2& 'Center
Caption = quot;2"
Height = 375
Index & = 3
Left = 6120
TabIndex & = 3
Top = 840
Width & = 1455
End
Begin VB.Label Label1
Alignment = 2& 'Center
Caption = quot;8"
Height = 375
Index & = 2
Left = 4320
TabIndex & = 2
Top = 840
Width & = 1455
End
Begin VB.Label Label1
Alignment = 2& 'Center
Caption = quot;16"
Height = 375
Index & = 1
Left = 2520
TabIndex & = 1
Top = 840
Width & = 1455
End
Begin VB.Label Label1
Alignment = 2& 'Center
Caption = quot;10"
Height = 375
Index & = 0
Left = 720
TabIndex & = 0
Top = 840
Width & = 1455
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Sub PrintDecimal()
& For i = 0 To 17
& List10.AddItem (i)
& Next i
End Sub

Sub PrintHex()
& For i = 0 To 17
& List16.AddItem (Hex(i))
& Next i
End Sub

Sub PrintOctal()
& For i = 0 To 17
& List8.AddItem (Oct(i))
& Next i
End Sub

' returns binary presentation of a number q of length l filling the initial positions with zeros.
Function Binary(ByVal q As Integer, ByVal l As Integer)
& Dim s As String
& Dim i, rest As Integer
&
& i = q
& s = ""
& While i > 0
rest = i Mod 2
If rest = 0 Then
s = "0" + s
Else
s = "1" + s
End If
i = (i - rest) / 2
& Wend
&
& Binary = String(l - Len(s), "0") + s
End Function
Sub PrintBinary()
& For i = 0 To 17
& List2.AddItem (Binary(i, 5))
& Next i
End Sub
Private Sub Form_Load()
PrintDecimal
PrintHex
PrintOctal
PrintBinary
End Sub

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS