Public Function Digital(ByVal Amount As Double, FLAGTYPE As String)
On Error Resume Next
Select Case FLAGTYPE
Case "Saudi"
rs = " ريـال "
H = "هلله "
hS = "هلل "
POUNDS = " ريالات "
V = Int(Math.Abs(Amount))
VPS = Val(Right(Format(Amount, "000000000000.00"), 2))
WORDINTEGER = AmountWord(V)
WORDPS = AmountWord(VPS)
If WORDINTEGER <> "" And (VPS <= 2) Then Result = WORDINTEGER & rs & " و " & WORDPS & H
If WORDINTEGER <> "" And (VPS >= 3 And VPS <= 9) Then Result = WORDINTEGER & rs & " و " & WORDPS & hS
If WORDINTEGER <> "" And (VPS > 9) Then Result = WORDINTEGER & rs & " و " & WORDPS & H
If WORDINTEGER = "" And (VPS <= 2) Then Result = WORDPS & H
If WORDINTEGER = "" And (VPS >= 3 And VPS <= 9) Then Result = WORDPS & hS
If WORDINTEGER = "" And VPS > 9 Then Result = WORDPS & H
If WORDINTEGER = "" And VPS = 0 Then Result = ""
If WORDINTEGER <> "" And VPS = 0 Then Result = WORDINTEGER & rs
Digital = Result
End Select
End Function
Public Function AmountWord(ByVal Amount As Double)
On Error Resume Next
n = Int(Amount)
c = Format(n, "000000000000")
C1 = Val(Mid(c, 12, 1))
Select Case C1
Case Is = 1: str1 = "واحد"
Case Is = 2: str1 = "اثنان"
Case Is = 3: str1 = "ثلاثة"
Case Is = 4: str1 = "اربعة"
Case Is = 5: str1 = "خمسة"
Case Is = 6: str1 = "ستة"
Case Is = 7: str1 = "سبعة"
Case Is = 8: str1 = "ثمانية"
Case Is = 9: str1 = "تسعة"
End Select
C2 = Val(Mid(c, 11, 1))
Select Case C2
Case Is = 1: str2 = "عشر"
Case Is = 2: str2 = "عشرون"
Case Is = 3: str2 = "ثلاثون"
Case Is = 4: str2 = "اربعون"
Case Is = 5: str2 = "خمسون"
Case Is = 6: str2 = "ستون"
Case Is = 7: str2 = "سبعون"
Case Is = 8: str2 = "ثمانون"
Case Is = 9: str2 = "تسعون"
End Select
If str1 <> "" And C2 > 1 Then str2 = str1 + " و" + str2
If str2 = "" Then str2 = str1
If C1 = 0 And C2 = 1 Then str2 = str2 + "ة"
If C1 = 1 And C2 = 1 Then str2 = "احدى عشر "
If C1 = 2 And C2 = 1 Then str2 = "اثنى عشر "
If C1 > 2 And C2 = 1 Then str2 = str1 + " " + str2
C3 = Val(Mid(c, 10, 1))
Select Case C3
Case Is = 1: str3 = "مائة"
Case Is = 2: str3 = " مئتان "
Case Is > 2: str3 = Left(AmountWord(C3), Len(AmountWord(C3)) - 1) + "مائة"
End Select
If str3 <> "" And str2 <> "" Then str3 = str3 + " و" + str2
If str3 = "" Then str3 = str2
C4 = Val(Mid(c, 7, 3))
Select Case C4
Case Is = 1: str4 = " ألف"
Case Is = 2: str4 = " الفان"
Case 3 To 10: str4 = AmountWord(C4) + " آلاف"
Case Is > 10: str4 = AmountWord(C4) + " ألف"
End Select
If str4 <> "" And str3 <> "" Then str4 = str4 + " و" + str3
If str4 = "" Then str4 = str3
C5 = Val(Mid(c, 4, 3))
Select Case C5
Case Is = 1: str5 = " مليون "
Case Is = 2: str5 = " مليونان "
Case 3 To 10: str5 = AmountWord(C5) + " ملايين "
Case Is > 10: str5 = AmountWord(C5) + " مليون "
End Select
If str5 <> "" And str4 <> "" Then str5 = str5 + " و" + str4
If str5 = "" Then str5 = str4
C6 = Val(Mid(c, 1, 3))
Select Case C6
Case Is = 1: str6 = " مليار "
Case Is = 2: str6 = " ملياران "
Case Is > 2: str6 = AmountWord(C6) + " مليار "
End Select
If str6 <> "" And str5 <> "" Then str6 = str6 + " و" + str5
If str6 = "" Then str6 = str5
AmountWord = str6
End Function