Argentina Warez » Zona Internet » TI - Programación & Webmasters Me redondea 500.12 a 600.12 escrito Visual Basic! Que error tiene?
08-may-2012
marcostech1
Black User
Me redondea 500.12 a 600.12 escrito Visual Basic! Que error tiene?
Bueno tengo un codigo de visual basic pero al momento de ingresar un monto que al multiplicarse por el IVA de .16 me da 500.12 por ejemplo. Y en mi factura sale escrito con palabras Seiscientos pesos con 12/100. No sale escrito Quinientos se redondea. Solo pasa eso con el 500 para arriba. Que puede ser?

Codigo:

Option Compare Database

Private Sub Report_Load()

myUnit = unitID

Dim myRecs As DAO.Recordset
' Select the record of invoiceDetail table whose invoice number is the same
' as typed in the combobox

Set myRecs = CurrentDb.OpenRecordset("SELECT sum(invoicesDetail.quantity*invoicesDetail.price) AS [mySubtotalCost] " _
& ", sum(invoicesDetail.quantity*invoicesDetail.price)* 0.16 As [myVAT]" _
& "FROM [invoicesDetail] WHERE ((invoicesDetail.invoiceNumber)=" _
& Me.invoiceNumber.Value & ");")

Me.subtotalCost.Value = myRecs!mySubtotalCost
Me.valueAddedTax.Value = myRecs!myVAT
Me.totalCost.Value = (myRecs!mySubtotalCost + myRecs!myVAT)

If (IsNull(myUnit) Or myUnit = 0) Then
unitID_Label.Visible = False
unitID.Visible = False
End If

wordAmount.Value = numberToWords(CStr(Format((myRecs!mySubtotalCost + myRecs!myVAT), "#.00")))
' Check if there is no records, if so labels have to be hidden
On Error GoTo ErrHandler:
myDate = dayField.Text
Exit Sub

ErrHandler:
unitID_Label.Visible = False
unitID.Visible = False
dayField.Visible = False
monthField.Visible = False
yearField.Visible = False
postCode_Label.Visible = False
unitID_Label.Visible = False
wordAmount.Visible = False
Resume Next

End Sub

Private Function numberToWords(myNumber As String) As String
Dim myAmount As Long, myDecimal As Integer
Dim myTokens() As Integer, myUBound As Integer
Dim myAmountString As String

' Split the number into integer and decimal part
If (InStr(myNumber, ".") > 0) Then
myAmount = Val(Left(myNumber, InStr(myNumber, ".") - 1))
myDecimal = Val(Right(myNumber, Len(myNumber) - InStr(myNumber, ".")))
Else
myAmount = Val(myNumber)
myDecimal = 0
End If

myAmountString = CStr(myAmount)
myDigits = Len(myAmountString)

'Split the integer part into tokens
X = 0
Do
ReDim Preserve myTokens(X)
If (Len(myAmountString) Mod 3 = 0) Then
myUBound = 3
Else: myUBound = (Len(myAmountString) Mod 3)
End If

myTokens(X) = Val(Left(myAmountString, myUBound))
If (Len(myAmountString) - myUBound = 0) Then
Exit Do
Else: myAmountString = Right(myAmountString, Len(myAmountString) - myUBound)
End If
X = X + 1
Loop Until (3 * X > (myDigits))

'Convert tokens to letters
For i = 0 To UBound(myTokens) Step 1
numberToWords = numberToWords & convertTokens(myTokens(i))
If (UBound(myTokens) - i > 0) Then
If ((UBound(myTokens) - i + 1) Mod 3 = 0) Then
If (myTokens(i) = 1) Then
numberToWords = " UN MILLÓN "
Else
If (Val(Right(CStr(myTokens(i)), 1)) = 1) Then
numberToWords = Replace(numberToWords, "UNO", "UN MILLONES", , 1)
Else: numberToWords = numberToWords & " MILLONES "
End If
End If
End If
If ((UBound(myTokens) - i + 1) Mod 2 = 0) Then
If (myTokens(i) = 1) Then
numberToWords = " UN MIL "
Else
If (Val(Right(CStr(myTokens(i)), 1)) = 1) Then
numberToWords = Replace(numberToWords, "UNO", "UN MIL", , 1)
Else: numberToWords = numberToWords & " MIL "
End If
End If
End If
End If
Next i

If (Val(Right(CStr(myTokens(UBound(myTokens))), 1)) = 1) Then
numberToWords = Replace(numberToWords, "UNO", "UN", , 1)
End If

numberToWords = "( " & numberToWords & " PESOS " & myDecimal & "/100 M.N. )"

End Function

Private Function convertTokens(myTokenX As Integer) As String

myHundreds = Array(" CIENTO ", " DOSCIENTOS ", " TRESCIENTOS ", " CUATROCIENTOS ", " QUINIENTOS " _
, " SEISCIENTOS ", " SETECIENTOS ", " OCHOCIENTOS ", " NOVECIENTOS ")

Select Case myTokenX
Case 0 To 100
convertTokens = convertTens(myTokenX)
Case 101 To 1000
If (myTokenX Mod 100 > 0) Then
convertTokens = myHundreds(Fix(myTokenX / 100) - 1) & " " & convertTens(Val(Right(CStr(myTokenX), Len(CStr(myTokenX)) - 1)))
Else: convertTokens = myHundreds(Fix(myTokenX / 100))
End If
Case Else
convertTokens = ""
End Select

End Function

Private Function convertTens(myTenNum As Integer) As String
myUnits = Array("CERO", "UNO", "DOS", "TRES", "CUATRO", "CINCO", "SEIS", "SIETE", "OCHO", "NUEVE" _
, "DIEZ", "ONCE", "DOCE", "TRECE", "CATORCE", "QUINCE", "DIECISEIS", "DIECISIETE" _
, "DIECIOCHO", "DIECINUEVE", "VEINTE", "VEINTIUNO", "VEINTIDOS", "VEINTITRES", "VEINTICUATRO" _
, "VEINTICINCO", "VEINTISEIS", "VEINTISIETE", "VEINTIOCHO", "VEINTINUEVE")
myTens = Array("DIEZ", "VEINTE", "TREINTA", "CUARENTA", "CINCUENTA", "SESENTA", "SETENTA", "OCHENTA", "NOVENTA", "CIEN")

Select Case myTenNum
Case 0 To 29
convertTens = myUnits(myTenNum)
Case 30 To 100
If (myTenNum Mod 10 > 0) Then
convertTens = myTens(Fix(myTenNum / 10) - 1) & " Y " & myUnits((myTenNum Mod 10))
Else: convertTens = myTens(Fix(myTenNum / 10) - 1)
End If
Case Else
convertTens = " "
End Select

End Function
: arghh:

Me redondea 500.12 a 600.12 escrito Visual Basic! Que error tiene?



Necesitás estar Registrado para dejar comentarios en Me redondea 500.12 a 600.12 escrito Visual Basic! Que error tiene?

Información del Post