Wrox Programmer Forums
|
Pro VB.NET 2002/2003 For advanced Visual Basic coders working .NET version 2002/2003. Beginning-level questions will be redirected to other forums, including Beginning VB.NET.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 27th, 2005, 03:41 AM
Authorized User
 
Join Date: Dec 2004
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to eelisMX
Default Formatting a number

Hi

Have a problem with formatting a number.
This code works fine:
Code:
Format(mbsize / 1048576, "#,###.## MB")
and format the number with thousand seperator and 2 decimals.

I'm having another number which can vary between 1 and billions (as Long), and I would like to format it with seperators every 3 digits, no decimals. All my trials returned question-mark (?) where the seperator suppose to be.

Any ideas... Thanks!

Eelis
 
Old January 27th, 2005, 06:01 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 142
Thanks: 0
Thanked 2 Times in 2 Posts
Default

The following seems to work:

Code:
Dim bsize As Long = 1128532467868.12
Dim size As String = Format(bsize, "#,###")
MessageBox.Show(size)


 
Old January 27th, 2005, 06:38 AM
Authorized User
 
Join Date: Dec 2004
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to eelisMX
Default

Thanks for the quick reply.

It works during debugging, but when I write the number to log file it still apears with the question mark (in the seperator place). kind of strange since the other formatted number is written to the file on the same time and is ok.
 
Old January 27th, 2005, 08:52 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 142
Thanks: 0
Thanked 2 Times in 2 Posts
Default

I've tried the following:

Code:
        Dim bsize As Double = 1128532467868.12
        Dim size As String = Format(bsize, "#,###")
        Dim e1 As New EventLog("Application")
        e1.Source = "AppTest"
        e1.WriteEntry(size)
        Dim sw As New System.IO.StreamWriter("C:\output.txt")
        sw.WriteLine(size)
        sw.Flush()
        sw.Close()
and the number appears ok in both the event log and in the output text file. How are you writing to the log file?

 
Old January 27th, 2005, 12:55 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

What program are you using to view the resultant log file?
 
Old January 28th, 2005, 04:23 AM
Authorized User
 
Join Date: Dec 2004
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to eelisMX
Default

Hi

Im writing using a StreamWriter and WriteLine just as you do in the example. The file is .log file and the text is appended every time its been open to write. I'm not using EventLog, rather send a string to the WriteLine method.

Code:
Dim writer = New StreamWriter(logFileName, True, System.Text.Encoding.ASCII)
writer.WriteLine("{0}", msg)
writer.Flush()
writer.Close()
writer = Nothing
Could it be because of the encoding?

At the moment I just open it with NotePad.
 
Old January 28th, 2005, 05:02 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 142
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Being that the encoding is the only thing that is different, I'd suggest that that is the case. Put it in unicode (just take off the final argument in your call to the constructor method of Steamwriter) and see if it's ok.

 
Old January 28th, 2005, 05:22 AM
Authorized User
 
Join Date: Dec 2004
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to eelisMX
Default

Problem solved!!

It was indeed the Encoding.ASCII argument.

Thanks for your time!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Number formatting / RegExp pierre.voisin Javascript 0 March 3rd, 2008 01:50 PM
Textbox Number Formatting pencilneck Visual Basic 2005 Basics 2 October 25th, 2007 03:46 PM
Problems with Number Formatting Roly Reefer Access 1 July 10th, 2005 02:00 PM
formatting number vkey XSLT 1 June 22nd, 2005 02:29 AM
formatting number dhol General .NET 2 February 24th, 2005 12:47 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.