Se petit programme est réaliser sous "Microsoft Visual Studio 2010" est pour convertir un chiffre en toute lettre.
Source / Exemple :
Imports System.Globalization
Public Class Form1
Private Property nonNumberEntered As Boolean
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MySoundPlayer1 = New System.Media.SoundPlayer("C:\Program Files\Windows NT\Pinball\SOUND14.WAV")
Dim MySoundPlayer2 = New System.Media.SoundPlayer("C:\Program Files\Windows NT\Pinball\SOUND16.WAV")
If TextBox1.Text = "" And FR.Checked = False And AR.Checked = False Then
MySoundPlayer2.Play()
MsgBox("Entrer un Chiffre et Définir la Langue de convertion SVP!", MsgBoxStyle.Information, "Remarque")
Else
If TextBox1.Text <> "" And FR.Checked = False And AR.Checked = False Then
MySoundPlayer2.Play()
MsgBox("choisir une langue de convertion SVP!", MsgBoxStyle.Information, "Remarque")
FR.Select()
Else
'============================= Français ==============================================
If FR.Checked = True Then
If TextBox1.Text = "" Then
MySoundPlayer2.Play()
MsgBox("Entrer un Chiffre SVP!", MsgBoxStyle.Information, "Remarque")
Else
RichTextBox1.RightToLeft = Windows.Forms.RightToLeft.No
GroupBox2.RightToLeft = Windows.Forms.RightToLeft.No
GroupBox2.Text = "En Lettre"
RichTextBox1.Text = ConvNumberLetter(CDbl(TextBox1.Text), 0)
MySoundPlayer1.Play()
TextBox1.Text = Format(CDbl(TextBox1.Text), "### ### ### ### ##0.00")
End If
Else
'========================= Arabe =================================================
If AR.Checked = True Then
If TextBox1.Text = "" Then
MySoundPlayer2.Play()
MsgBox("Entrer un Chiffre SVP!", MsgBoxStyle.Information, "Remarque")
Else
RichTextBox1.RightToLeft = Windows.Forms.RightToLeft.Yes
GroupBox2.RightToLeft = Windows.Forms.RightToLeft.Yes
GroupBox2.Text = "بالحروف"
RichTextBox1.Text = NoToTxt(CDbl(TextBox1.Text), 1)
MySoundPlayer1.Play()
TextBox1.Text = Format(CDbl(TextBox1.Text), "### ### ### ### ##0.00")
End If
End If
End If
End If
End If
End Sub
Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.GotFocus
If FR.Checked = True Or AR.Checked = True Then
TextBox1.Text = ""
End If
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Select Case e.KeyChar
Case ChrW(8)
Case ChrW(46)
e.KeyChar = ChrW(44)
Case ChrW(44), ChrW(48) To ChrW(58)
Case Else
e.KeyChar = ChrW(0)
Beep()
End Select
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
Public Function ConvNumberLetter(ByVal TheNo As Double, ByVal Langue As Byte) As String
Dim dblEnt As Object, byDec As Byte
Dim bNegatif As Boolean
Dim strDev As String, strCentimes As String
If TheNo = 0 Then
ConvNumberLetter = "Zéro"
Else
If TheNo < 0 Then
bNegatif = True
TheNo = Math.Abs(TheNo)
End If
dblEnt = Int(TheNo)
byDec = CInt((TheNo - dblEnt) * 100)
If byDec = 0 Then
If dblEnt > 999999999999999.0# Then
ConvNumberLetter = "#TropGrand"
Exit Function
End If
Else
If dblEnt > 9999999999999.99 Then
ConvNumberLetter = "#TropGrand"
Exit Function
End If
End If
strDev = " Dinar"
strCentimes = " Centime"
If byDec = 1 Then strCentimes = strCentimes & "."
If byDec > 1 Then strCentimes = strCentimes & "s."
If dblEnt > 1 Then strDev = strDev & "s"
If byDec <> 0 Then
ConvNumberLetter = ConvNumEnt(CDbl(dblEnt), Langue) & strDev & " et " & _
ConvNumDizaine(byDec, Langue) & strCentimes
Else : ConvNumberLetter = ConvNumEnt(CDbl(dblEnt), Langue) & strDev & " Algérien."
End If
End If
End Function
Private Function ConvNumEnt(ByVal TheNo As Double, ByVal Langue As Byte)
Dim iTmp As Object, dblReste As Double
Dim strTmp As String
iTmp = TheNo - (Int(TheNo / 1000) * 1000)
ConvNumEnt = ConvNumCent(CInt(iTmp), Langue)
dblReste = Int(TheNo / 1000)
iTmp = dblReste - (Int(dblReste / 1000) * 1000)
strTmp = ConvNumCent(CInt(iTmp), Langue)
Select Case iTmp
Case 0
Case 1
strTmp = "Mille "
Case Else
strTmp = strTmp & " Mille "
End Select
ConvNumEnt = strTmp & ConvNumEnt
dblReste = Int(dblReste / 1000)
iTmp = dblReste - (Int(dblReste / 1000) * 1000)
strTmp = ConvNumCent(CInt(iTmp), Langue)
Select Case iTmp
Case 0
Case 1
strTmp = strTmp & " Million "
Case Else
strTmp = strTmp & " Millions "
End Select
ConvNumEnt = strTmp & ConvNumEnt
dblReste = Int(dblReste / 1000)
iTmp = dblReste - (Int(dblReste / 1000) * 1000)
strTmp = ConvNumCent(CInt(iTmp), Langue)
Select Case iTmp
Case 0
Case 1
strTmp = strTmp & " Milliard "
Case Else
strTmp = strTmp & " Milliards "
End Select
ConvNumEnt = strTmp & ConvNumEnt
dblReste = Int(dblReste / 1000)
iTmp = dblReste - (Int(dblReste / 1000) * 1000)
strTmp = ConvNumCent(CInt(iTmp), Langue)
Select Case iTmp
Case 0
Case 1
strTmp = strTmp & " Billion "
Case Else
strTmp = strTmp & " Billions "
End Select
ConvNumEnt = strTmp & ConvNumEnt
End Function
Private Function ConvNumDizaine(ByVal TheNo As Byte, ByVal Langue As Byte) As String
Dim TabUnit As Object, TabDiz As Object
Dim byUnit As Byte, byDiz As Byte
Dim strLiaison As String
Dim array01() As String = {"", "Un", "Deux", "Trois", "Quatre", "Cinq", "Six", "Sept", _
"Huit", "Neuf", "Dix", "Onze", "Douze", "Treize", "Quatorze", "Quinze", _
"Seize", "Dix-sept", "Dix-huit", "Dix-neuf"}
Dim array10() As String = {"", "", "Vingt", "Trente", "Quarante", "Cinquante", _
"Soixante", "Soixante", "Quatre-vingt", "Quatre-vingt"}
TabUnit = array01
TabDiz = array10
byDiz = Int(TheNo / 10)
byUnit = TheNo - (byDiz * 10)
strLiaison = "-"
If byUnit = 1 Then strLiaison = " et "
Select Case byDiz
Case 0
strLiaison = ""
Case 1
byUnit = byUnit + 10
strLiaison = ""
Case 7
If Langue = 0 Then byUnit = byUnit + 10
Case 8
If Langue <> 2 Then strLiaison = "-"
Case 9
If Langue = 0 Then
byUnit = byUnit + 10
strLiaison = "-"
End If
End Select
ConvNumDizaine = TabDiz(byDiz)
If byDiz = 8 And Langue <> 2 And byUnit = 0 Then ConvNumDizaine = ConvNumDizaine & "s"
If TabUnit(byUnit) <> "" Then
ConvNumDizaine = ConvNumDizaine & strLiaison & TabUnit(byUnit)
Else
ConvNumDizaine = ConvNumDizaine
End If
End Function
Private Function ConvNumCent(ByVal TheNo As Integer, ByVal Langue As Byte) As String
Dim TabUnit As Object
Dim byCent As Byte, byReste As Byte
Dim strReste As String
Dim arrray() As String = {"", "Un", "Deux", "Trois", "Quatre", "Cinq", "Six", "Sept", "Huit", "Neuf", "Dix"}
TabUnit = arrray
byCent = Int(TheNo / 100)
byReste = TheNo - (byCent * 100)
strReste = ConvNumDizaine(byReste, Langue)
Select Case byCent
Case 0
ConvNumCent = strReste
Case 1
If byReste = 0 Then
ConvNumCent = "Cent"
Else
ConvNumCent = "Cent " & strReste
End If
Case Else
If byReste = 0 Then
ConvNumCent = TabUnit(byCent) & " Cent"
Else
ConvNumCent = TabUnit(byCent) & " Cent " & strReste
End If
End Select
End Function
'================================== Arabe ==================================
Public Function NoToTxt(ByVal TheNo As Double, ByVal Langue As Byte) As String
Const MyCur = "دينار", MyCont = "جزائري", MySubCur = "سنتيما"
Dim MyArry1(0 To 9) As String
Dim MyArry2(0 To 9) As String
Dim MyArry3(0 To 9) As String
Dim Myno As String
Dim GetNo As String
Dim RdNo As String
Dim My100 As String
Dim My10 As String
Dim My1 As String
Dim My11 As String
Dim My12 As String
Dim GetTxt As String
Dim Mybillion As String
Dim MyMiliard As String
Dim MyMillion As String
Dim MyThou As String
Dim MyHun As String
Dim MyFraction As String
Dim MyAnd As String
Dim I As Integer
Dim ReMark As String
If TheNo > 999999999999999.0# Then
NoToTxt = "#رقم كبير جدا"
Exit Function
End If
If TheNo < 0 Then
TheNo = TheNo * -1
ReMark = "يتبقى لكم "
Else
ReMark = "."
End If
If TheNo = 0 Then
NoToTxt = "صفر"
Exit Function
End If
MyAnd = " و"
MyArry1(0) = ""
MyArry1(1) = "مائة"
MyArry1(2) = "مائتان"
MyArry1(3) = "ثلاثة مائة"
MyArry1(4) = "أربعة مائة"
MyArry1(5) = "خمسة مائة"
MyArry1(6) = "ستة مائة"
MyArry1(7) = "سبعة مائة"
MyArry1(8) = "ثمانية مائة"
MyArry1(9) = "تسعة مائة"
MyArry2(0) = ""
MyArry2(1) = " عشر"
MyArry2(2) = "عشرون"
MyArry2(3) = "ثلاثون"
MyArry2(4) = "أربعون"
MyArry2(5) = "خمسون"
MyArry2(6) = "ستون"
MyArry2(7) = "سبعون"
MyArry2(8) = "ثمانون"
MyArry2(9) = "تسعون"
MyArry3(0) = ""
MyArry3(1) = "واحد"
MyArry3(2) = "إثنان"
MyArry3(3) = "ثلاثة"
MyArry3(4) = "أربعة"
MyArry3(5) = "خمسة"
MyArry3(6) = "ستة"
MyArry3(7) = "سبعة"
MyArry3(8) = "ثمانية"
MyArry3(9) = "تسعة"
'======================
GetNo = Format(TheNo, "000000000000000.00")
I = 0
Do While I < 18
If I < 15 Then
Myno = Mid$(GetNo, I + 1, 3)
Else
Myno = "0" + Mid$(GetNo, I + 2, 2)
End If
If (Mid$(Myno, 1, 3)) > 0 Then
RdNo = Mid$(Myno, 1, 1)
My100 = MyArry1(RdNo)
RdNo = Mid$(Myno, 3, 1)
My1 = MyArry3(RdNo)
RdNo = Mid$(Myno, 2, 1)
My10 = MyArry2(RdNo)
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)) = 1) 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
MyMiliard = GetTxt + " مليار"
Else
MyMiliard = GetTxt + " مليارات"
If ((Mid$(Myno, 1, 3)) = 1) Then MyMiliard = " مليار"
If ((Mid$(Myno, 1, 3)) = 2) Then MyMiliard = " ملياران"
End If
End If
If (I = 6) 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 = 9) And (GetTxt <> "") Then
If ((Mid$(Myno, 1, 3)) > 10) Then
MyThou = GetTxt + " ألف"
Else
MyThou = GetTxt + " آلاف"
If ((Mid$(Myno, 2, 2)) = 1) Then MyThou = " ألف"
If ((Mid$(Myno, 3, 1)) = 2) Then MyThou = " ألفان"
End If
End If
If (I = 12) And (GetTxt <> "") Then MyHun = GetTxt
If (I = 15) And (GetTxt <> "") Then MyFraction = GetTxt
End If
I = I + 3
Loop
If (Mybillion <> "") Then
If (MyMiliard <> "") Or (MyMillion <> "") Or (MyThou <> "") Or (MyHun <> "") Then Mybillion = Mybillion + MyAnd
End If
If (MyMiliard <> "") Then
If (MyMillion <> "") Or (MyThou <> "") Or (MyHun <> "") Then MyMiliard = MyMiliard + 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 (MyMiliard <> "") Or (MyMillion <> "") Or (MyThou <> "") Or (MyHun <> "") Then
NoToTxt = Mybillion + MyMiliard + MyMillion + MyThou + MyHun + " " + MyCur + MyAnd + MyFraction + " " + MySubCur + ReMark
Else
NoToTxt = MyFraction + " " + MySubCur + ReMark
End If
Else
NoToTxt = Mybillion + MyMiliard + MyMillion + MyThou + MyHun + " " + MyCur + " " + MyCont + ReMark
End If
End Function
End Class
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.