AmtToWords
This function converts amount in words with supplied currency parameters. e.g. AmtToWords(12345.01, "GB POUND", "PENNY", "GB POUNDS", "PENNIES") will return GB POUNDS TWELVE THOUSAND THREE HUNDRED FORTY-FIVE and ONE PENNY ONLY
AI
KI-Zusammenfassung: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Quellcode
Private units(20), teens(11)
Function AmtToWords(amount As Currency, UnitCurr As String, DecCurr As String, UnitsCurr As String, DecsCurr As String) As String
Dim new_amt, TRstring, BIstring, MIstring, THstring, HUstring, DEstring, Separator As String
If amount = 0 Then
AmtToWords = "NIL"
Exit Function
End If
units(0) = ""
units(1) = " ONE"
units(2) = " TWO"
units(3) = " THREE"
units(4) = " FOUR"
units(5) = " FIVE"
units(6) = " SIX"
units(7) = " SEVEN"
units(8) = " EIGHT"
units(9) = " NINE"
units(10) = " TEN"
units(11) = " ELEVEN"
units(12) = " TWELVE"
units(13) = " THIRTEEN"
units(14) = " FOURTEEN"
units(15) = " FIFTEEN"
units(16) = " SIXTEEN"
units(17) = " SEVENTEEN"
units(18) = " EIGHTEEN"
units(19) = " NINETEEN"
teens(0) = ""
teens(1) = " TEN"
teens(2) = " TWENTY"
teens(3) = " THIRTY"
teens(4) = " FORTY"
teens(5) = " FIFTY"
teens(6) = " SIXTY"
teens(7) = " SEVENTY"
teens(8) = " EIGHTY"
teens(9) = " NINETY"
teens(10) = " HUNDRED"
new_amt = Format(amount, "000000000000000.00")
TRstring = Mid(new_amt, 1, 3)
BIstring = Mid(new_amt, 4, 3)
MIstring = Mid(new_amt, 7, 3)
THstring = Mid(new_amt, 10, 3)
HUstring = Mid(new_amt, 13, 3)
DEstring = "0" + Mid(new_amt, 17, 2)
AmtToWords = ""
UnitCurr = IIf(Val(Left(new_amt, 15)) = 0, "", UnitCurr)
DecCurr = IIf(Val(Right(new_amt, 2)) = 0, "", DecCurr)
UnitCurr = IIf(Val(Left(new_amt, 15)) > 1, UnitsCurr, UnitCurr)
DecCurr = IIf(Val(Right(new_amt, 2)) > 1, DecsCurr, DecCurr)
Separator = IIf(UnitCurr <> "" And DecCurr <> "", " and", "")
AmtToWords = UnitCurr + AmtToWords
AmtToWords = AmtToWords + IIf(Val(TRstring) > 0, numconv(TRstring) + " TRILLION", "")
AmtToWords = AmtToWords + IIf(Val(BIstring) > 0, numconv(BIstring) + " BILLION", "")
AmtToWords = AmtToWords + IIf(Val(MIstring) > 0, numconv(MIstring) + " MILLION", "")
AmtToWords = AmtToWords + IIf(Val(THstring) > 0, numconv(THstring) + " THOUSAND", "")
AmtToWords = AmtToWords + IIf(Val(HUstring) > 0, numconv(HUstring), "")
AmtToWords = AmtToWords + IIf(Val(DEstring) > 0, Separator + numconv(DEstring), "")
AmtToWords = Trim(AmtToWords + " " + DecCurr) + " ONLY"
End Function
Function numconv(amt) As String
Dim aAmount, bAmount, cAmount, dAmount As Integer
Dim hyphen As String
aAmount = Val(Mid(amt, 2, 2))
bAmount = Val(Mid(amt, 3, 1))
cAmount = Val(Mid(amt, 2, 1))
dAmount = Val(Mid(amt, 1, 1))
If aAmount < 20 Then
numconv = units(aAmount)
Else
numconv = units(bAmount)
If bAmount > 0 And cAmount > 0 Then
hyphen = "-"
End If
numconv = teens(cAmount) + hyphen + LTrim(numconv)
End If
If dAmount > 0 Then
numconv = units(dAmount) + " HUNDRED" + numconv
End If
End Function
Option Strict Off
Option Explicit On
Imports System
Imports System.Data.OleDb
sub whatever()
Dim myconnection As New OleDbConnection()
Dim myReader As OleDbDataReader
Dim cmSQL As OleDbCommand
Dim strSQL As String
myconnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\ database.mdb;"
('or add the database in bin folder of the project and substitute with the following)
myconnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=database.mdb;"
Try
strSQL = "SELECT * FROM tablename"
cmSQL = New OleDbCommand(strSQL, myconnection)
myconnection.Open()
myReader = cmSQL.ExecuteReader()
Do While myReader.Read()
Console.WriteLine(vbTab & "{0}" & vbTab & "{1}", myReader.GetInt32(0), myReader.GetString(1))
Loop
Catch Exp As OleDbException
MsgBox(Exp.Message, MsgBoxStyle.Critical, "Oledb Error")
Catch Exp As Exception
MsgBox(Exp.Message, MsgBoxStyle.Critical, "General Error")
End Try
' Close and Clean up objects
myconnection.Close()
cmSQL.Dispose()
myconnection.Dispose()
myReader.Close)
end sub
Originalkommentare (3)
Wiederhergestellt von der Wayback Machine