ملاحظة: ليتم نسخ الكود بمحتواه العربي سليماً يجب أن تكون لوحة المفاتيح على اللغة العربية قبل عملية النسخ.
منقول
طريقة استخدام دالة تحويل الرقم إلى نص مع إضافة اسم العملة وإضافة خاصية اختيار الكسر العشري الثلاثي
كود :
' عملة بكسر عشري ثنائي كالعملة الأردنية باستخدام القرش حيث يتكون الدينار من 100 قرش
Me.Text2.Text = NoToTxt(Val(Me.Text1.Text), "دينار", "قرش", False)
كود :
' عملة بكسر عشري ثلاثي كالعملة الأردنية باستخدام الفلس حيث يتكون الدينار من 1000 فلس
Me.Text2.Text = NoToTxt(Val(Me.Text1.Text), "دينار", "فلس", True)
دالة التحويل بعد تحسينها وإضافة خاصية اختيار الكسر العشري الثلاثي
ضع هذا الكود في موديول Module
كود :
Option Explicit
Public Function NoToTxt(ByVal TheNo As Double, ByVal MyCur As String, ByVal MySubCur As String, Optional ByVal Dec3Digit As Boolean = False) As String
'======================
If Dec3Digit Then
If TheNo > 999999999999.999 Then
NoToTxt = ""
Exit Function
End If
Else
If TheNo > 999999999999.99 Then
NoToTxt = ""
Exit Function
End If
End If
'======================
If TheNo = 0 Then
NoToTxt = "صفر"
Exit Function
End If
'======================
Dim MyNo, GetNo, RdNo, GetTxt, ReMark As String
Dim My100, My10, My1, My11, My12 As String
Dim Mybillion, MyMillion As String
Dim MyThou, MyHun, MyFraction As String
Dim MyArry1(9) As String
Dim MyArry2(9) As String
Dim MyArry3(9) As String
Dim MyAnd As String
'======================
MyAnd = " و"
If Mid$(MyNo, 2, 2) = 11 Then My11 = "أحد عشر"
If Mid$(MyNo, 2, 2) = 12 Then My12 = "أثنا عشر"
If Mid$(MyNo, 2, 2) = 10 Then My10 = "عشرة"
If ((Mid$(MyNo, 1, 1)) > 0) And ((Mid$(MyNo, 2, 2)) > 0) Then My100 = My100 + MyAnd
If ((Mid$(MyNo, 3, 1)) > 0) And ((Mid$(MyNo, 2, 1)) > 1) Then My1 = My1 + MyAnd
GetTxt = My100 + My1 + My10
If ((Mid$(MyNo, 3, 1)) = 1) And ((Mid$(MyNo, 2, 1)) = 1) Then
GetTxt = My100 + My11
If ((Mid$(MyNo, 1, 1)) = 0) Then GetTxt = My11
End If
If ((Mid$(MyNo, 3, 1)) = 2) And ((Mid$(MyNo, 2, 1)) = 1) Then
GetTxt = My100 + My12
If ((Mid$(MyNo, 1, 1)) = 0) Then GetTxt = My12
End If
If (i = 0) And (GetTxt <> "") Then
If ((Mid$(MyNo, 1, 3)) > 10) Then
Mybillion = GetTxt + " مليون"
Else
Mybillion = GetTxt + " مليون"
If ((Mid$(MyNo, 1, 3)) = 2) Then Mybillion = " مليون"
If ((Mid$(MyNo, 1, 3)) = 2) Then Mybillion = " ملايين"
End If
End If
If (i = 3) And (GetTxt <> "") Then
If ((Mid$(MyNo, 1, 3)) > 10) Then
MyMillion = GetTxt + " مليون"
Else
MyMillion = GetTxt + " ملايين"
If ((Mid$(MyNo, 1, 3)) = 1) Then MyMillion = " مليون"
If ((Mid$(MyNo, 1, 3)) = 2) Then MyMillion = " ملايين"
End If
End If
If (i = 6) And (GetTxt <> "") Then
If ((Mid$(MyNo, 1, 3)) > 10) Then
MyThou = GetTxt + " ألف"
Else
MyThou = GetTxt + " آلاف"
If ((Mid$(MyNo, 3, 1)) = 1) Then MyThou = " ألف"
If ((Mid$(MyNo, 3, 1)) = 2) Then MyThou = " آلاف"
End If
End If
If (i = 9) And (GetTxt <> "") Then MyHun = GetTxt
If (i = 12) And (GetTxt <> "") Then MyFraction = GetTxt
End If
Next
If (Mybillion <> "") Then
If (MyMillion <> "") Or (MyThou <> "") Or (MyHun <> "") Then Mybillion = Mybillion + MyAnd
End If
If (MyMillion <> "") Then
If (MyThou <> "") Or (MyHun <> "") Then MyMillion = MyMillion + MyAnd
End If
If (MyThou <> "") Then
If (MyHun <> "") Then MyThou = MyThou + MyAnd
End If
If MyFraction <> "" Then
If (Mybillion <> "") Or (MyMillion <> "") Or (MyThou <> "") Or (MyHun <> "") Then
NoToTxt = ReMark + Mybillion + MyMillion + MyThou + MyHun + " " + MyCur + MyAnd + MyFraction + " " + MySubCur
Else
NoToTxt = ReMark + MyFraction + " " + MySubCur
End If
Else
NoToTxt = ReMark + Mybillion + MyMillion + MyThou + MyHun + " " + MyCur
End If