Function DesimalKeOktal$(Nilai&)
Dim Nilai2 As Long
Dim Hasil As String
Dim LHasil As Integer
Dim i As Integer
Do Until Nilai = 0
Nilai2 = Nilai Mod 8
Nilai = Nilai \ 8
Hasil = Hasil & CStr(Nilai2)
Loop
LHasil = Len(Hasil)
For i = 0 To LHasil - 1
DesimalKeOktal$ = DesimalKeOktal$ & _
Mid(Hasil, LHasil - i, 1)
Next
End Function
Function OktalKeDesimal$(Nilai$)
Dim LNilai As Integer
Dim i As Integer
Dim Hasil As Long
LNilai = Len(Nilai$)
For i = 1 To LNilai
Hasil = Hasil + CLng(Mid(Nilai, i, 1)) * (8 ^ (LNilai - i))
Next
'
OktalKeDesimal$ = Hasil
End Function
Private Sub cmdJumlah_Click()
Dim Temp1&, Temp2&
Dim Angka1&, Angka2&
Dim Hasil&
Angka1 = Me.txtAngka1.Text
Angka2 = Me.txtAngka2.Text
'Mengubah oktal ke desimal lebih dulu dari angka-angka yg diinputkan
Temp1 = OktalKeDesimal$(CStr(Angka1))
Temp2 = OktalKeDesimal$(CStr(Angka2))
'Menghitung angka yg diinputkan (dalam basis desimal)
Hasil& = Temp1 * Temp2
Me.txtHasil.Text = DesimalKeOktal(Hasil&) '<-- mengembalikan ke basis oktal
End Sub
Private Sub Timer1_Timer()
Label1.Caption = Format(Now, "dd mmmm yyyy hh:mm:ss")
End Sub
Private Sub txtAngka1_KeyPress(KeyAscii As Integer)
If Not (KeyAscii >= ("0") And _
KeyAscii <= Asc("7") Or _
KeyAscii = vbKeyBack Or _
KeyAscii = vbKeyReturn Or _
KeyAscii = vbKeyDelete) Then
'KeyAscii adalah 0 (tidak berfungsi)
Beep
KeyAscii = 0
End If
End Sub
Private Sub txtAngka2_KeyPress(KeyAscii As Integer)
If Not (KeyAscii >= 48 And _
KeyAscii <= Asc("7") Or _
KeyAscii = vbKeyBack Or _
KeyAscii = vbKeyReturn Or _
KeyAscii = vbKeyDelete) Then
'KeyAscii adalah 0 (tidak berfungsi)
Beep
KeyAscii = 0
End If
End Sub
Tidak ada komentar:
Posting Komentar
silahkan berkomentar