Solved

formatting a string in VB.Net (tostring)

Posted on 2010-08-16
5
663 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

914 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now