Solved

formatting a string in VB.Net (tostring)

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to wrap a merged cells of datagridview column in vs2010 (vb.net) 8 34
Disable extension 8 38
.NET 2008 VB and C# 6 27
parsing JSON help 1 9
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

772 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