Return Roman Numerals

Return Roman Numerals

This VB procedure returns decimal numbers (integers) as Roman numerals (a string), ranging from 1 to 4999. Numbers outside this range return the same number as a string. The optional parameter iStyle allows two different numerical styles: standard (4 = iv, 9 = ix, and so on) when iStyle = -1, or classical (4 = iiii, 9 = viiii, and so on) when iStyle = -2.

The variable x should make the function more efficient, although you might not notice the time saved on a fast machine:

Public Function Roman(ByVal n As Integer, _	Optional iStyle As Integer = -1) As String	If n < 1 Or n >= 5000 Then 		Roman = CStr(n)		Exit Function	End If	If iStyle <> -2 Then iStyle = -1	Dim sRtn As String, i As Integer, x As Integer	Dim r(1 To 13) As String, v(1 To 13) As Integer	r(1) = "i": v(1) = 1	r(2) = "iv": v(2) = 4	r(3) = "v": v(3) = 5	r(4) = "ix": v(4) = 9	r(5) = "x": v(5) = 10	r(6) = "xl": v(6) = 40	r(7) = "l": v(7) = 50	r(8) = "xc": v(8) = 90	r(9) = "c": v(9) = 100	r(10) = "cd": v(10) = 400	r(11) = "d": v(11) = 500	r(12) = "cm": v(12) = 900	r(13) = "m": v(13) = 1000	x = UBound(v)	sRtn = ""	Do		For i = x To LBound(v) Step iStyle			If v(i) 7lt;= n Then				sRtn = sRtn & r(i)				n = n - v(i)				x = i				Exit For			End If		Next i	Loop Until n = 0	Roman = sRtnEnd Function
Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several