473,508 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Format function

KJ
Hello,

Why does this not work?

txtMoney.Text.Format("#,##0.00")

If I type 100 in txtMoney, it returns #,##0.00

I have never gotten the format function to work in .NET.
Nov 20 '05 #1
10 8168
Hi,
Dim strMoney As String = "12345.34"

Me.Text = CType(strMoney, Decimal).ToString("#,##0.00")

Ken
--------------------
________________________________________
From: KJ [mailto:kl******@hotmail.com]
Sent: Tuesday, June 22, 2004 4:32 PM
To: microsoft.public.dotnet.languages.vb
Subject: Format function

Hello,

Why does this not work?

txtMoney.Text.Format("#,##0.00")

If I type 100 in txtMoney, it returns #,##0.00

I have never gotten the format function to work in .NET.

--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.3 - Release Date: 6/18/2004
Nov 20 '05 #2
On 22 Jun 2004 13:32:00 -0700, KJ wrote:
Hello,

Why does this not work?

txtMoney.Text.Format("#,##0.00")

If I type 100 in txtMoney, it returns #,##0.00

I have never gotten the format function to work in .NET.


Because the Format function is a member of the String class. txtMoney.Text
is a string and Format is a member of that class.

To use it, you should try:

txtMoney.Text = String.Format("#,##0.00", txtMoney.Text)
--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 20 '05 #3
* kl******@hotmail.com (KJ) scripsit:
Why does this not work?

txtMoney.Text.Format("#,##0.00")

If I type 100 in txtMoney, it returns #,##0.00


Try 'Strings.Format' instead.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #4
The formatting constants are different in .NET - although I was under the
impression the classic VB ones worked too.
However, IMO the .NET formatting is better - have a look at ToString() in
the MSDN. The [decimal object].ToString(<format>) is what you're after.
Your code should be along the lines of

CType(txtMoney.Text, Decimal).ToString("C")

I'm sure the resident experts in this group can explain the details of the
formatting functions :D
___________________________________
The Grim Reaper

"KJ" <kl******@hotmail.com> wrote in message
news:d8**************************@posting.google.c om...
Hello,

Why does this not work?

txtMoney.Text.Format("#,##0.00")

If I type 100 in txtMoney, it returns #,##0.00

I have never gotten the format function to work in .NET.

Nov 20 '05 #5
KJ,
As the others have suggested. txtMoney.Text.Format is really the shared
function String.Format, VB.NET allows you to called shared members on
instances of objects, as this example demostrates this can cause confused
results. To avoid these confused results I try to avoid calling shared
members on instances of objects (variables, properties, fields, parameters).

For details on using String.Format see:

http://msdn.microsoft.com/library/de...formatting.asp

http://msdn.microsoft.com/library/de...ormatTopic.asp
As Chris stated, you sample is the same as:

String.Format("#,##0.00")

There are two problems with this.
1. You are not using the value returned from the Format function.
2. You did not specify any placeholders in the format specifier.

Although the second is not important, the first surely is ;-)

Try something like:

Dim amount As Decimal

Dim str As String = String.Format("The total amount is {0:#,##0.00}",
amount)

Hope this helps
Jay

"KJ" <kl******@hotmail.com> wrote in message
news:d8**************************@posting.google.c om...
Hello,

Why does this not work?

txtMoney.Text.Format("#,##0.00")

If I type 100 in txtMoney, it returns #,##0.00

I have never gotten the format function to work in .NET.

Nov 20 '05 #6
Hi Ken,

I see this is a dotnet.language.vb MVP contest.

The opinion from a supperdummy, I find yours the nicest.

Cor
Dim strMoney As String = "12345.34"

Me.Text = CType(strMoney, Decimal).ToString("#,##0.00")

Nov 20 '05 #7
* "Cor Ligthert" <no**********@planet.nl> scripsit:
I see this is a dotnet.language.vb MVP contest.

The opinion from a supperdummy, I find yours the nicest.


I prefer 'CDec' in this situation ;-).
Me.Text = CType(strMoney, Decimal).ToString("#,##0.00")


--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #8
Hi Herfried,

I prefer 'CDec' in this situation ;-).
Me.Text = CType(strMoney, Decimal).ToString("#,##0.00")


Almost the same question was in the adonet newsgroup, this was my answer on
the question.

\\\
Maybe you have seen it already it seems that there was a contest in the
language.vb newsgroup yesterday evening (my time) about this question.

A google link to this one and than

I found the one from Ken the nicest, however a simple answer is that you
have first to convert the string to a decimal before you can use the mask.
///
However I was no compatitor in the contest.

:-)

Cor
Nov 20 '05 #9
KJ
Just to let everyone know

THIS WORKED!!!!! :)
Me.Text = CType(strMoney, Decimal).ToString("#,##0.00")
THIS DID NOT WORK!!!! :(
txtMoney.Text = String.Format("#,##0.00", txtMoney.Text)
Thanks for your help!
Nov 20 '05 #10
Ken,
THIS DID NOT WORK!!!! :(
txtMoney.Text = String.Format("#,##0.00", txtMoney.Text) Did you read my post, it explains why that one cannot work.

Hope this helps
Jay

"KJ" <kl******@hotmail.com> wrote in message
news:d8**************************@posting.google.c om... Just to let everyone know

THIS WORKED!!!!! :)
Me.Text = CType(strMoney, Decimal).ToString("#,##0.00")
THIS DID NOT WORK!!!! :(
txtMoney.Text = String.Format("#,##0.00", txtMoney.Text)
Thanks for your help!

Nov 20 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
12096
by: Melissa | last post by:
What specifically causes the Format event of a report's section to fire? Thanks! Melissa
3
4317
by: Jean | last post by:
Hi, I have a query that contains the following in the WHERE part of the query: WHERE....Format(IIf(nz()<>0,, IIf(nz()<>0,, IIf(nz()<>0,, ))),"0.0") AS Körperhöhe,....
6
2819
by: Stuart McGraw | last post by:
I am looking for a VBA "format" or "template" function, that is, a function that takes a format string and a varying number of arguments, and substitutes the argument values into the format string...
13
4323
by: Roy Hills | last post by:
I've seen two different function prototype formats used for ANSI C, and I'm unsure as to which is the correct or preferred one. 1st Format (this is what I use) type function(type, type, type);...
4
1831
by: Matt | last post by:
I'm trying to write a shared function that will convert all my phone numbers from format 1234567890 to (123) 456-7890. Here is my function that I wrote: Public Shared Function...
10
1883
by: Ron | last post by:
Hello, The following code works in a Form class module but not a standard module: Dim d1 As DateTime Format(d1, "MMMM") In a standard module I get a squigly line saying that an argument has...
16
4001
by: Al Reid | last post by:
First, I'm using vb2005. I have a string that is read from a barcode reader into a TextBox. The string is 6 characters long and represents a date (mmddyy). I want to display it to the user in a...
4
22025
by: sql guy123 | last post by:
HI, I'm pretty new to MS SQL, My problem is setting .... =Format$(Date(),"mm" & "/1/" & "YYYY") (Which is from my MS ACCESS database)
11
10540
by: shsandeep | last post by:
I used the following query to retrieve the date in dd-mon-yyyy format. db2 => SELECT RTRIM(CHAR(DAY(COVG_TYP_STRT_DT))) || '-' || RTRIM(MONTHNAME(COVG_TYP_STRT_DT)) || '-' ||...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7115
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7377
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7036
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7489
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5047
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4705
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1547
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.