Sunday, April 30, 2017

Decimal To Roman Numeral in Visual Basic 6

Here is a sample program that will ask the user to give a number and then it will be converted into roman numeral value using Visual Basic 6.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.






Sample Program Output


Program Listing

Public Function ConvertRoman(ByVal n As Integer) As String
   If n = 0 Then FormatRoman = "0": Exit Function
    
   Const r = "IVXLCDM"
   Dim i As Integer: i = Abs(n)
   Dim s As String, p As Integer
   For p = 1 To 5 Step 2
      Dim d As Integer: d = i Mod 10: i = i \ 10
      Select Case d
         Case 0 To 3: s = String(d, Mid(r, p, 1)) & s
         Case 4:      s = Mid(r, p, 2) & s
         Case 5 To 8: s = Mid(r, p + 1, 1) & String(d - 5, Mid(r, p, 1)) & s
         Case 9:      s = Mid(r, p, 1) & Mid(r, p + 2, 1) & s
         End Select
      Next
   s = String(i, "M") & s
   If n < 0 Then s = "-" & s
   ConvertRoman = s
   End Function


Private Sub Command1_Click()
Label2.Caption = "The equivalent value of " & Text1.Text & " is " & ConvertRoman(Text1.Text) & "."
End Sub

Private Sub Command2_Click()
End
End Sub



No comments:

Post a Comment