Solved

formatting a string in VB.Net (tostring)

Posted on 2010-08-16
5
668 Views
Last Modified: 2013-11-27
In the code attached, I want to be able to format vchr.inv_amt to be dollars and cents.  In C#, I believe I can use vchr.inv_amt.ToString("##,##0.00"), but in VB.Net I am getting
"Overload resolution failed because no accesible 'ToString' accepts this number of arguments."

This sub routine is in an "Actions" class, not the main form.  Am I missing a namespace or is this just not how you do it in VB.Net?  If not, how is it done.

Thanks
Public Shared Sub FillVchrGrid(ByVal f As Form1)
        Try
            Dim ap3 As New Ap3DataContext(Globals.ConnString)

            Dim vchrs = From c In ap3.aptrxfil_sqls Select c

            For Each vchr In vchrs
                f.dgvVouchers.Rows.Add(vchr.batch_id, vchr.vchr_no, vchr.vend_no, vchr.inv_no, vchr.inv_amt.ToString(), vchr.ID.ToString())
            Next 'vchr

            For Each dr As DataGridViewRow In f.dgvVouchers.Rows
                For y As Integer = 0 To 4
                    dr.Cells(y).Style.BackColor = Color.LightGreen
                Next 'y
            Next 'datagridviewrow
        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try
    End Sub

Open in new window

0
Comment
Question by:g_johnson
5 Comments
 
LVL 3

Expert Comment

by:bdempster
ID: 33447410
0
 
LVL 18

Accepted Solution

by:
Anil Golamari earned 500 total points
ID: 33447413
http://www.codeproject.com/KB/string/vbnetformatcurrency.aspx (sample code)

// Private Function DoConvert(ByVal Str as String, ByVal DecPlc as Integer) as String
//      Return String.Format("{0:c" & DecPlc & "}",CDec(Str))
// End Function  

http://www.vbdotnetforums.com/localization-i18n-internationalization/14592-formatting-string-currency.html
0
 
LVL 11

Expert Comment

by:ladarling
ID: 33447440
If those are floating point types, you can simply use vchr.inv_amt.ToString("c")
 
0
 
LVL 4

Author Comment

by:g_johnson
ID: 33447463
.ToString("c") caused the same problem.  I ended up using format(vchr.inv_amt,"c") and that works.  Please see my next question because I need more detail on ToString
0
 
LVL 17

Expert Comment

by:nepaluz
ID: 33447494
try

FormatNumber(vchr.inv_amt.ToString(), 2)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question