Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
'....
#End Region
Function vandecimaal(ByVal getal As Integer, ByVal basis As Integer) As String
Dim positie As Integer
Dim kopie As Integer
Dim doorloper As Integer
Dim aantaltekens As Integer
Dim teken As Integer
kopie = getal
aantaltekens = Int(Math.Log(getal) / Math.Log(basis))
For doorloper = aantaltekens To 0 Step -1
teken = kopie \ Math.Pow(basis, doorloper)
kopie = kopie - teken * Math.Pow(basis,
doorloper)
vandecimaal = vandecimaal & teken.ToString
Next
End Function
Function naardecimaal(ByVal getal As String, ByVal basis As Integer) As Integer
Dim positie As Integer
Dim doorloper As Integer
Dim teken As Integer
For positie = 0 To Len(getal) - 1
doorloper = Len(getal) - positie
teken = Mid(getal, doorloper, 1)
naardecimaal = naardecimaal + CInt(teken) *
Math.Pow(basis, positie)
Next
End Function
Private Sub cmdVanDec_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdVanDec.Click
Try
If Not IsNumeric(txtBasis.Text) Then
MsgBox("Je hebt geen basis opgegeven")
End If
If CInt(txtBasis.Text) = 0 Then
MsgBox("De basis kan niet nul zijn")
End If
Me.txtNotatie.Text = vandecimaal(CInt(Me.txtWaarde.Text), CInt(Me.txtBasis.Text))
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub txtNaarDec_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles txtNaarDec.Click
Try
If Not IsNumeric(txtNotatie.Text) Then
MsgBox("Je hebt geen niet decimale notatie ingegeven")
Exit Sub
End If
If Not IsNumeric(txtWaarde.Text) Then
MsgBox("Je hebt geen geldige waarde opgegeven")
Exit Sub
End If
If Not IsNumeric(txtBasis.Text) Then
MsgBox("Je hebt geen basis opgegeven")
End If
If CInt(txtBasis.Text) = 0 Then
MsgBox("De basis kan niet nul zijn")
End If
Me.txtWaarde.Text = naardecimaal(CInt(Me.txtNotatie.Text), CInt(Me.txtBasis.Text))
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class