Solved

formatting a string in VB.Net (tostring)

Posted on 2010-08-16
5
670 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: 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

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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

728 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