473,387 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

VB6: formatting textbox (#,###.##) in every LostFocus

montzter
Hi evryone,

I'm having trouble in formatting the inputed data in the text box so that everytime user lost focus it will adjust its value to contain the format (#,####.##). ie user will input 1111.1 it will immediately be converted to 1,111.10 as its value.

I've tried using this code in every lost focus:
textbox.text = round(val(textbox.text)), 2)

but the problem with this is I am not getting the comma and if the user enters an exact integer value (means without decimal) it will remain as is.... I've also tried changing the text box property data format to number and checked the box to separate thousands in coma, but its not working.

Can anybody help me.

Thanks
Oct 29 '07 #1
5 13404
Dököll
2,364 Expert 2GB
... I'm having trouble in formatting the inputed data in the text box ...
Go to Projects + Components + MS Masked Edit Control, see what that does...

I should perhaps mention you may need to add maskedtextboxes in place of the ones you now have. Perhaps there is another way of achieving this through regular textboxes, but I would go with masked ones :-)

In a bit!
Oct 29 '07 #2
Killer42
8,435 Expert 8TB
A few things come to mind...
  • Try using "0" rather than "#" in the format to force a digit to be included. For example, I think Format(number, "#,###.00") might work.
  • The code you posted doesn't actually use the Format() function.
  • The problem with this sort of approach is that you will probably need to strip out the comma(s) in the GotFocus event, and trust the user not to type them. I don't think the Val() function accepts them. You could also create your own function which combines the comma-stripping and string->number conversion. So instead of just using Val() you'd use something like TextBox.Text = StringToNumber(TextBox.Text) which would handle removing commas and converting to a number.
  • The Round() function rounds a number up or down to the specified number of places. It has nothing to do with formatting the number for display. If you "round" 5.00 to two places, you still have 5.00, which is exactly the same number as 5.0, or 5.000000000.
  • I believe the DataFormat property only applies to displaying a database field in the textbox. Are you doing this?
  • I'm curious - where was the "separate thousands in coma" checkbox that you checked? I'm not familiar with it.
  • Have you considered using a Masked Edit control instead of a textbox? It gives you much better control over the format.
Well, I hope that is some help.
Oct 29 '07 #3
You guys do reply fast!!! I thought I can get the reply in a day or two!!!
anyway I have tried the first reply and I will go with it. Value of the maskedbox.text remains unchanged even if there were already commas being entered. this is cool compnent..


Thanks for pointing me to the right direction.
Oct 29 '07 #4
A few things come to mind...
Wow you have a lot of ideas but sound too complicated for me. I go with your last bullet. Actually I am using a database. There's no problem with the data in the database, it's just that the user wants it in this format to be displayed. So got a problem with the textbox.

Thanks again for the help.
Oct 29 '07 #5
Killer42
8,435 Expert 8TB
Glad we could help. :)

As for the quick response, you were just lucky to catch a couple of us at the right time. It can sometimes take quite a bit longer.
Oct 29 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Robert W. | last post by:
I'm developing a WinForms app and have a slight problem that I hope someone can help me with. There are a series of textboxes that the user can enter information into. The text in these boxes is...
1
by: Carlo | last post by:
Hi How do I get textbox text to be formatted on the fly as entering. I have a textbox which will hold numerics larger than a million which I want to autoformat i.e FormatNumber, so that it makes...
5
by: Jack | last post by:
Hell I have a few text boxes on my form and I need in one to allow only numbers and on the other only letters how to enforce that you can't enter numbers in a letters textbox and... Jack
7
by: Localbar | last post by:
Hi all, In my form have more then 10 textbox. I would like to make all textbox when lostfocus backcolor is white, when gotfocus backcolor is yellow. But I don't want to write same code in the...
18
by: obrienkev | last post by:
Hi, I have a multiline TextBox. Text contained in the TextBox will be stored in a SQL Server Database. How do I format the textBox correctly for database entry? e.g. How do I ensure that new...
0
by: massx | last post by:
I have a project iv'e been racking my brain on for a while heres the basics i have a textbox that gets populated with mp3's in an xml playlist that looks like this.. <?xml version='1.0'...
6
by: Andy B | last post by:
I need to take the value of a textbox and format it in a more readable date. How do you do this? I tried textbox.text.tostring("date format string") but the compiler doesnt like that idea... any...
12
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
I want to plant an Easter Egg in our software. We have a TextBox that is multiline and used to display all sorts of messages on the screen for our operators based on database queries and such. ...
3
by: dougancil | last post by:
I have a web page that will be supplying data to a sql query and I want my users to type in dates as mm/dd/yyyy but my sql query needs the dates as yyyy/dd/mm. How can I reformat the textbox.text to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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...
0
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...

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.