Перевод целых неотрицательных чисел в различных системах счисления

Министерство образования Республики Таджикистан

Таджикский Технический Университет им. ак. М. С. Осими

Кафедра АСОИиУ

Лабораторная работа №4

“Перевод целых неотрицательных чисел в различных системах счисления”

Выполнил:

Принял:

-Душанбе 2009-

Программа Enhanced Converter

Publicx0, x, i, j, zAsDoubleПроцедура инициализации приложения

Public y As String

Private Sub clr_Click()

Inp. Text = “” Процедура очистки текстовых полей

Out. Text = “”

EndSub

Внешний вид окна приложения с введенными данными

Private Sub Form_KeyPress(KeyAscii As Integer)

Dim val As String

Val = Chr(KeyAscii)

Select Case cmb. ListIndex

Case 0

Select Case val

Case “0”

Inp. Text = inp. Text &; “0”

Case “1”

Inp. Text = inp. Text &; “1”

End Select

Case 1

If val >= “0” And val <= “9” Then

If val >= “8” And val <= “9” And inp. Text = “” Then

Exit Sub

Else

End If

Inp. Text = inp. Text &; CStr(val)

Else

End If

Case 2

If (val >= “0” And val <= “9”) Or (val >= “a” And val <= “f”) Or (val >= “A” And val <= “F”) Then

Inp. Text = inp. Text &; CStr(val)

Else

End If

Case 3, 4, 5

If val >= “0” And val <= “9” Then

Inp. Text = inp. Text &; CStr(val)

Else

End If

End Select

End Sub

Private Sub inp_KeyDown(KeyCode As Integer, Shift As Integer)

On Error GoTo err:

If (KeyCode = vbKeyBack) Then

Inp. Text = Left(inp. Text, Len(inp. Text) – 1)

ElseIf (KeyCode = vbKeyDelete) Then

Inp. Text = “”

Else

End If

Exit Sub

Err:

Beep

End Sub

Private Sub Form_Load()

Inp. Text = “”

End Sub

Private Sub inp_Change()

Dim d(100) As Double

Dim ds(100) As String

Select Case cmb. ListIndex

Case 0

Inp. MaxLength = 40

If inp. Text = “” Then

Out. Text = “”

Exit Sub

Else

I = (Len(inp. Text))

X = 0

J = 0

Do

X = x + (val(Mid(inp. Text, i, 1)) * (2 ^ j))

I = i – 1

J = j + 1

Loop Until i = 0

Out. Text = x

End If

Case 1

Inp. MaxLength = 40

If inp. Text = “” Then

Out. Text = “”

Exit Sub

Else

I = (Len(inp. Text))

X = 0

J = 0

Do

X = x + (val(Mid(inp. Text, i, 1)) * (8 ^ j))

I = i – 1

J = j + 1

Loop Until i = 0

Out. Text = x

End If

Case 2

Inp. MaxLength = 40

Z = 0

If inp. Text = “” Then

Out. Text = “”

Exit Sub

Else

I = (Len(inp. Text))

X = 0

J = 0

Do

Select Case Mid(inp. Text, i, 1)

Case “A”, “a”

Z = 10

Case “B”, “b”

Z = 11

Case “C”, “c”

Z = 12

Case “D”, “d”

Z = 13

Case “E”, “e”

Z = 14

Case “F”, “f”

Z = 15

Case “0”, “1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”

Z = val(Mid(inp. Text, i, 1))

End Select

X = x + z * (16 ^ j)

I = i – 1

J = j + 1

Loop Until i = 0

Out. Text = x

End If

Case 3

Inp. MaxLength = 15

On Error GoTo err:

If inp. Text = “” Then

Out. Text = “”

Exit Sub

ElseIf val(inp. Text) = 0 Or val(inp. Text) = 1 Then

Out. Text = inp. Text

Exit Sub

Else

I = 1

X0 = val(inp. Text)

Do

D(i) = val(x0 – (val(x0 / 2) * 2))

X = Round((x0 / 2) – 0.3, 0)

I = i + 1

X0 = x

Loop Until x = 1

D(i) = x

Out. Text = “”

Do

Out. Text = out. Text &; val(d(i))

I = i – 1

Loop Until i = 0

End If

Case 4

Inp. MaxLength = 15

On Error GoTo err:

If inp. Text = “” Then

Out. Text = “”

Exit Sub

Else

I = 1

X0 = val(inp. Text)

If x0 >= 0 And x0 <= 7 Then

Out. Text = inp. Text

Exit Sub

Else

Do

D(i) = val(x0 – (val(x0 / 8) * 8))

X = val(x0 / 8)

If x >= 0 And x <= 7 Then

I = i + 1

D(i) = x

Exit Do

Else

I = i + 1

X0 = x

End If

Loop Until x = 1

Out. Text = “”

Do

Out. Text = val(out. Text) &; val(d(i))

I = i – 1

Loop Until i = 0

End If

End If

Case 5

Inp. MaxLength = 15

Z = 0

If inp. Text = “” Then

Out. Text = “”

Exit Sub

Else

I = 1

X0 = val(inp. Text)

If val(inp. Text) >= 0 And val(inp. Text) <= 15 Then

Select Case val(inp. Text)

Case 10

Y = “A”

Case 11

Y = “B”

Case 12

Y = “C”

Case 13

Y = “D”

Case 14

Y = “E”

Case 15

Y = “F”

Case 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

Y = inp. Text

End Select

Out. Text = y

Exit Sub

Else

Do

Z = val(x0 – (val(x0 / 16) * 16))

Select Case z

Case 10

Y = “A”

Case 11

Y = “B”

Case 12

Y = “C”

Case 13

Y = “D”

Case 14

Y = “E”

Case 15

Y = “F”

Case 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

Y = CStr(z)

End Select

Ds(i) = y

X = val(x0 / 16)

If x <= 0 Then Exit Do

I = i + 1

X0 = x

Loop Until x = 1

Out. Text = “”

Do

Out. Text = out. Text &; ds(i)

I = i – 1

Loop Until i = 0

End If

End If

End Select

ExitSub

Err:

MsgBox “Введены неверные значения или значения не являются корректными”, , “=VaMp1r3=™”

Call clr_Click

End Sub

Private Sub cmb_Click()

Call clr_Click

End Sub

Private Sub ext_Click()

End

End Sub

Private Sub cop_Click()

MsgBox “=VaMp1r3=™. Все права защищены. По всем вопросам а также с претензиями обращаться в гр. 6546 Б2 к Столову Юрию.”, , “=VaMp1r3=™”

End Sub


Перевод целых неотрицательных чисел в различных системах счисления