|
Hi..
Anyone could help me out in writing a vb.net windows application, which converts the given numbers to appropriate words(Ex.if 123 is entered,the output should be ONE HUNDRED AND TWENTY THREE)
Vijay Mesa
|
|
|
|
|
|
That sounds like a homework assignment to me... If it is, assume your lecturer is also reading these boards.
|
|
|
|
|
You must construct an algorithm to do this routine!
It will starts from the end of the integer..and reads one by one the numbers!
You must call two functions. First returns the number string (ex. 1 one), and second the "position" (if this number is 3rd from the end this is hundred).
It's too easy..
Kostas
|
|
|
|
|
Hi,
use this function...
Public Function Wording(ByVal Digits As Int16) As String
Dim Inword() As String = {"", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen", "Twenty"}
Dim Tenth() As String = {"", "", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"}
Dim MainWord As String
If Digits <= 20 Then
MainWord = Inword(Digits)
ElseIf Digits < 100 Then
MainWord = Tenth(Mid(Digits, 1, 1)) & " " & Inword(Mid(Digits, 2, 1))
End If
Wording = Trim(MainWord)
End Function
Public Function Convert(ByVal Indigit As String) As String
On Error GoTo err1
Dim word(8), Outword As String
Dim length, num2, i As Int16
Dim frac As Single
Dim flg As Boolean
frac = Val(Indigit) - Int(Val(Indigit))
If frac <> 0 Then
num2 = Mid(Str(frac), 3, 2)
If num2 <= 9 Then num2 = num2 * 10
If frac < 0.1 Then num2 = Mid(Str(frac), 3, 2)
word(0) = Wording(num2)
End If
Indigit = Int(Val(Indigit))
If Val(Indigit) <> 0 Then flg = True
length = Len(Indigit)
num2 = Val(Mid(Indigit, length, 1))
word(1) = Wording(num2)
num2 = Val(Mid(Indigit, length - 1, 2))
word(1) = Wording(num2)
num2 = Val(Mid(Indigit, length - 2, 1))
word(2) = Wording(num2)
num2 = Val(Mid(Indigit, length - 3, 1))
word(3) = Wording(num2)
num2 = Val(Mid(Indigit, length - 4, 2))
word(3) = Wording(num2)
num2 = Val(Mid(Indigit, length - 5, 1))
word(4) = Wording(num2)
num2 = Val(Mid(Indigit, length - 6, 2))
word(4) = Wording(num2)
num2 = Val(Mid(Indigit, length - 7, 1))
word(5) = Wording(num2)
num2 = Val(Mid(Indigit, length - 8, 2))
word(5) = Wording(num2)
err1:
For i = 5 To 0 Step -1
If word(i) <> "" Then
Select Case i
Case 0
If flg = False Then Outword = Outword + word(i) + " Paise" Else Outword = Outword + " And " + word(i) + " Paise"
Case 1
Outword = Outword + word(i)
Case 2
Outword = Outword + word(i) + " Hundred "
Case 3
Outword = Outword + word(i) + " Thousand "
Case 4
Outword = Outword + word(i) + " Lac "
Case 5
Outword = Outword + word(i) + " Crore "
End Select
End If
Next
If Outword = "" Then Outword = "Zero"
Convert = Outword
End Function
Public Function NumToWord(ByVal StrDigits As String) As String
Dim l, Pos As Int16
Dim a, b As String
Pos = InStr(StrDigits, ".")
If Pos = 0 Then a = StrDigits Else a = Mid(StrDigits, 1, Pos - 1)
l = Len(a)
If l > 7 Then
a = Mid(a, 1, l - 7)
b = Mid((StrDigits), l - 6)
NumToWord = Convert(a) & " Crore " & Convert(b)
Else
NumToWord = Convert(StrDigits)
End If
End Function
Thanks & Regards...
Amit
|
|
|
|
|
Your example is about twice the size it needs to be, but CONGRATULATIONS!!
You just did this guy's homework for him!! His prize?? A FAILING grade because the prof WILL know he didn't write the code! I hope you're happy...
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi..
Anyone could help me out in writing a vb.net windows application, which converts the given numbers to appropriate words(Ex.if 123 is entered,the output should be ONE HUNDRED AND TWENTY THREE)
Vijay Mesa
|
|
|
|
|
Ahhh, the ubiquitous homework assignment. Just Google for "convert number to words" and you'll see thousands of examples.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I HAVE COMPLETED MY VB.NET WIN APPLICATION(consists of crystal report nd ado.net).
I HAVE ALSO GOT AN '.exe' FILE FOR IT.
NOW I NEED TO RUN THIS EXE AT ANOTHER PC
PLS SUGGEST THE REQUIREMENTS TO INSTALL IN THE OTHER PC
IS JUST DOTNET FRAME WORK SUFFICIENT
thanks in adv for ur reply
ramana mohan
|
|
|
|
|
Please don't SHOUT. It's annoying and rude.
From MSDN
In order for a .NET Framework application to run on a given computer, it must have the .NET Framework installed. Any .NET Framework application that uses ADO.NET to connect to databases requires MDAC 2.7. Many computers already have these components installed; however, to ensure an application will run, these components should be redistributed with your application.
dotnetfx.exe[^] (for .NET 1.1)
dotnetfx.exe[^] (for .NET 2.0)
MDAC 2.8[^]
|
|
|
|
|
ramana mohan wrote: PLS SUGGEST THE REQUIREMENTS TO INSTALL IN THE OTHER PC
Create a setup and deployment package.
ramana mohan wrote: IS JUST DOTNET FRAME WORK SUFFICIENT
You need to have crystal report runtime libraries as well.
|
|
|
|
|
Still having same problem with formatting numbers in database. I am using the following code:
This is the function that I am calling
Public Function FormatPartNumber(ByVal formatstyle As String, ByVal partnumber As String) As String
FormatPartNumber = String.Format(formatstyle, partnumber)
End Function
Code to format number:
If Trim(row("formatcodeforitemnumber").ToString()) = "0" Or Trim(row("formatcodeforitemnumber").ToString()) = "" Then
FormattedPartnumber = FormatPartNumber("XXXXX-XXX", row("itemnumber").ToString())
ElseIf Trim(row("formatcodeforitemnumber").ToString()) = "1" Then
FormattedPartnumber = FormatPartNumber("XXXXX-XXX-XX", row("itemnumber").ToString())
ElseIf Trim(row("formatcodeforitemnumber").ToString()) = "2" Then
FormattedPartnumber = FormatPartNumber("XXXXXX-XXXX", row("itemnumber").ToString())
The number are not formatting at all. Any ideas!
jds1207
|
|
|
|
|
The part number is already a string, so it got formatted when you convert it to a string. You have to get it as a number to be able to format it into a string.
---
b { font-weight: normal; }
|
|
|
|
|
Could you give me an example?
|
|
|
|
|
jds1207 wrote: Could you give me an example?
An example of what?
How do you store the value in the database? Do you store it as a number? Otherwise you have to first convert it to a number to be able to convert it to a string again.
---
b { font-weight: normal; }
|
|
|
|
|
I don't think X works with numbers. It's 0
FormattedPartnumber = FormatPartNumber("00000-000", clng(row("itemnumber"))
Public Function FormatPartNumber(ByVal formatstyle As String, ByVal partnumber As long) As String
return partnumber.tostring(formatstyle)
End Function
|
|
|
|
|
I got the following error when trying to run project which was for this code
return partnumber.tostring(formatstyle)
Error message:
Unable to cast object of type 'System.String' to type 'System.IFormatProvider'. W
|
|
|
|
|
did you notice that I changed the argument type to LONG in the procedure definition?
I just tried the code and it worked fine. FormattedPartNumber = '03833-733'
Dim FormattedPartnumber As String = FormatPartNumber("00000-000", CLng("3833733"))
Public Function FormatPartNumber(ByVal formatstyle As String, ByVal partnumber As Long) As String
Return partnumber.tostring(formatstyle)
End Function
|
|
|
|
|
The numbers in the database are all showing as Xs now. Do you have any ideas?
|
|
|
|
|
you can't use X you must either use 0 or # (removes leading zeros).
my code that I sent along has the format of "00000-00" don't use X.
|
|
|
|
|
When I use 0 or # I get the error: Could not find installable ISAM.
|
|
|
|
|
does this code work for you?
Dim FormattedPartnumber As String = FormatPartNumber("00000-000", CLng("3833733"))
Public Function FormatPartNumber(ByVal formatstyle As String, ByVal partnumber As Long) As String
Return partnumber.tostring(formatstyle)
End Function
|
|
|
|
|
No, that code does not work. I want the number to be formatted when it is stored in the database.
|
|
|
|
|
Your original code indicates you want to format the value as your reading it from the database. If you want the database to have the formatted value then when you inserted the record you need to have it formatted at that point not as your reading it. if you want it to be displayed formatted then the code I gave does work.
|
|
|
|
|
The value is being read from a file and inserted into the database. I am not reading it from the database. The X that I am using will work when shown in the database with my original code. I am using X because they are used for the format code in the file. Here is some code that show the file I am pulling the values from:
Dim dttable As New DataTable
Dim row As DataRow
Dim CheckforProducts As DataTable
Dim FormattedPartnumber As String
Dim FormattedSupercedePartNumber As String
Dim Conn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Data Feeds\Current\Kawasaki\Jet Ski Trailer Generator;EXtended Properties=""TeXt;HDR=No;FMT=FiXedLength"""
Dim SQLstr As String = "SELECT TOP 5 * FROM IMINF010.dat"
Dim da As New OleDb.OleDbDataAdapter(SQLstr, Conn)
FormattedPartnumber = vbNull
FormattedSupercedePartNumber = vbNull
da.Fill(dttable)
For Each row In dttable.Rows
CheckforProducts = ProductExist(row("itemnumber").ToString(), "3")
If Trim(row("formatcodeforitemnumber").ToString()) = "0" Or Trim(row("formatcodeforitemnumber").ToString()) = "" Then
FormattedPartnumber = FormatPartNumber("XXXXX-XXX", CLng(row("itemnumber").ToString))
ElseIf Trim(row("formatcodeforitemnumber").ToString()) = "1" Then
FormattedPartnumber = FormatPartNumber("XXXXX-XXX-XX", CLng(row("itemnumber").ToString))
ElseIf Trim(row("formatcodeforitemnumber").ToString()) = "2" Then
FormattedPartnumber = FormatPartNumber("XXXXXX-XXXX", CLng(row("itemnumber").ToString))
If CheckforProducts.Rows.Count > 0 Then
UpdateProduct(FormattedPartnumber, "0", FormattedSupercedePartNumber, "0", RemoveQuotes(row("itemdescription").ToString()), "0", "0", "0", "0", "0", "0", row("dlrcost").ToString(), row("rtlprice").ToString())
|
|
|
|
|