PDA

View Full Version : تبدیل عدد به حروف



arsalansalar
سه شنبه 05 شهریور 1387, 14:53 عصر
با سلام
چی جوری میشه در یک تکست باکس که عددنوشته شده با یک کد کاری کرد که در یک تکست باکس دیگر به حروف آن عدد نوشته شود؟

Sharif Lotfi
سه شنبه 05 شهریور 1387, 15:01 عصر
براي اين كار لازمه كه كد تبديل رو بنويسي يا از كدهاي آماده dll درست كني و استفاده كني
من كدشو تو محيط ماكروهاي اكسل نوشتم و تبديل به تابع شده ميتوني فايل اجرايي بهمراه راهنماشو دانلود كني . سعي مي كنم در اولين فرصت dll كنم برات آپلود كنم استفاده كني

parsavb
سه شنبه 05 شهریور 1387, 15:04 عصر
این رو نگاه کن
عدد به حروف (http://barnamenevis.org/forum/attachment.php?attachmentid=21336&d=1217904854)

elmira_63
سه شنبه 05 شهریور 1387, 16:46 عصر
اینم فایل dll اش الان برات نوشتمش
کافیه add refrence رو بزنی و اینو add کنی توی برنامت و مثل این کد هر جای برنامه که خواستی ازش استفاده کنی

Private Sub Text2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Text2.TextChanged
Dim n As New numtotextdll.Class1
Dim i As Double = Val(Text2.Text)
Text3.Text = n.NumToText(i)
End Sub
امید وارم به دردت بخوره

arsalansalar
چهارشنبه 06 شهریور 1387, 08:06 صبح
این رو نگاه کن
عدد به حروف (http://barnamenevis.org/forum/attachment.php?attachmentid=21336&d=1217904854)
دوست عزیز با تشکر از شما.
کد شما Vb هست.من vb.net می خواستم.

elmira_63
چهارشنبه 06 شهریور 1387, 09:19 صبح
اینم کد vb.net اش 2005 هم هست


Private Function NumToText(ByRef Adad As Double) As String
Static sefr_ta_noh(9) As String
Static dah_ta_noozdah(9) As String
Static bist_ta_navado(9) As String
Static sad_ta_nohsad(9) As String
Static hezar_ta_trilion(4) As String

Dim i As Short
Dim tamam_sefr As Boolean
Dim show_balatar_az_hezar As Boolean
Dim adad_vorodi As String
Dim string_temp As String
Dim tabdil As String
Dim Ragham As Short
Dim character As Short
System.Diagnostics.Debug.Assert(Adad > 0, "")

sefr_ta_noh(0) = "صفر"
sefr_ta_noh(1) = "يک"
sefr_ta_noh(2) = "دو"
sefr_ta_noh(3) = "سه"
sefr_ta_noh(4) = "چهار"
sefr_ta_noh(5) = "پنج"
sefr_ta_noh(6) = "شش"
sefr_ta_noh(7) = "هفت"
sefr_ta_noh(8) = "هشت"
sefr_ta_noh(9) = "نه"
dah_ta_noozdah(0) = "ده"
dah_ta_noozdah(1) = "يازده"
dah_ta_noozdah(2) = "دوازده"
dah_ta_noozdah(3) = "سيزده"
dah_ta_noozdah(4) = "چهارده"
dah_ta_noozdah(5) = "پانزده"
dah_ta_noozdah(6) = "شانزده"
dah_ta_noozdah(7) = "هفده"
dah_ta_noozdah(8) = "هجده"
dah_ta_noozdah(9) = "نوزده"
'bist_ta_navado(0) = ""
'bist_ta_navado(1) = "ده"
bist_ta_navado(2) = "بيست"
bist_ta_navado(3) = "سي"
bist_ta_navado(4) = "چهل"
bist_ta_navado(5) = "پنجاه"
bist_ta_navado(6) = "شصت"
bist_ta_navado(7) = "هفتاد"
bist_ta_navado(8) = "هشتاد"
bist_ta_navado(9) = "نود"
'sad_ta_nohsad(0) = ""
sad_ta_nohsad(1) = "يک صد"
sad_ta_nohsad(2) = "دويست"
sad_ta_nohsad(3) = "سيصد"
sad_ta_nohsad(4) = "حهارصد"
sad_ta_nohsad(5) = "پانصد"
sad_ta_nohsad(6) = "ششصد"
sad_ta_nohsad(7) = "هفتصد"
sad_ta_nohsad(8) = "هشتصد"
sad_ta_nohsad(9) = "نهصد"
'hezar_ta_trilion(0) = ""
hezar_ta_trilion(1) = "هزار"
hezar_ta_trilion(2) = "ميليون"
hezar_ta_trilion(3) = "ميليارد"
hezar_ta_trilion(4) = "تريليون"


On Error GoTo vbErrorHandler

adad_vorodi = CStr(Adad)

tamam_sefr = True

For i = Len(adad_vorodi) To 1 Step -1
character = Val(Mid(adad_vorodi, i, 1))
Ragham = (Len(adad_vorodi) - i) + 1

Select Case (Ragham Mod 3)
Case 0
If character > 0 Then
tabdil = sad_ta_nohsad(character) & " و " & tabdil
End If
Case 1
show_balatar_az_hezar = True
If i = 1 Then
string_temp = sefr_ta_noh(character) & " "
ElseIf Mid(adad_vorodi, i - 1, 1) = "1" Then
string_temp = dah_ta_noozdah(character) & " "
i = i - 1
ElseIf character > 0 Then
string_temp = sefr_ta_noh(character) & " "
Else
show_balatar_az_hezar = False
If Mid(adad_vorodi, i - 1, 1) <> "0" Then
show_balatar_az_hezar = True
ElseIf i > 2 Then
If Mid(adad_vorodi, i - 2, 1) <> "0" Then
show_balatar_az_hezar = True
End If
End If
string_temp = ""
End If
If show_balatar_az_hezar = True Then
If Ragham > 1 Then

string_temp = string_temp & hezar_ta_trilion(Ragham \ 3)
If tamam_sefr = True Then
string_temp = string_temp & " "
Else
string_temp = string_temp & " و "
End If
End If
tamam_sefr = False
End If
tabdil = string_temp & tabdil
Case 2
If character > 0 Then
If Mid(adad_vorodi, i + 1, 1) <> "0" Then
tabdil = bist_ta_navado(character) & " و " & tabdil
Else
tabdil = bist_ta_navado(character) & " " & tabdil
End If
End If

End Select
Next i

tabdil = UCase(VB.Left(tabdil, 1)) & Mid(tabdil, 2)

EndNumToText:
NumToText = tabdil
Return tabdil
Exit Function

vbErrorHandler:
tabdil = "خطا"
Resume EndNumToText

parsavb
شنبه 09 شهریور 1387, 17:40 عصر
ببخشید عوضی اشتباه شده این هم برنامه .net