Solved

formatting a string in VB.Net (tostring)

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

20 Experts available now in Live!

Get 1:1 Help Now