Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Visual Basic Totals

Status
Not open for further replies.

jjc3397

Programmer
Dec 21, 2003
55
US
I have the following calculated fields that I want added together to get one total DebitDocTotal and CreditDocTotal.

I have the totals from one form that I want added together with totals from another form to get one total Debit and Credit that will be written out to a text file.

Me.MaskedDebitDocTotal.Text = CType(JVFORM.MaskedDebitDocTotal.Text, Decimal) + TotalDebit.Text
Me.MaskedCreditDocTotal.Text = CType(JVFORM.MaskedCreditDocTotal.Text, Decimal) + TotalCredit.Text



The Totals will be written out to a text file with this formatting:

DebitDocTotal = Microsoft.VisualBasic.Right("00000000000000" & Microsoft.VisualBasic.Left(Me.MaskedDebitDocTotal.Text.ToString, InStr(Me.MaskedDebitDocTotal.Text.ToString, ".") - 1) & _
Microsoft.VisualBasic.Right(Me.MaskedDebitDocTotal.Text.ToString, 2), 14)



CreditDocTotal = Microsoft.VisualBasic.Right("00000000000000" & Microsoft.VisualBasic.Left(Me.MaskedCreditDocTotal.Text.ToString, InStr(Me.MaskedCreditDocTotal.Text.ToString, ".") - 1) & _
Microsoft.VisualBasic.Right(Me.MaskedCreditDocTotal.Text.ToString, 2), 14)


1000.00 + 1000.00

would be written out as 00000000200000


I believe I have coded these incorrectly above. The formatting for DebitDocTotal and CreditDocTotal might be correct.

jjc3397
 
It's easier to use the String.PadLeft and String.PadRight functions.

For example:
Code:
Dim i As Integer = 5
Dim s As String = ""
s = i.ToString.PadLeft(5, "0")

The above code will result in "00005." If I wanted more zeros, I would simply adjust the first parameter in the PadLeft function.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top