[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 710
  • Last Modified:

Masked Text Box and multi-length numbers only

Help please!
I am using a Masked Text Box in VB.NET. I need to make it so that it only accepts numbers but digit count can be of any length with no decimal value.
Currently I have the mask set as ######0. When I set the text value equal the field value, which is a money format from a data set, the result has 4 zeros to the right of the number with no decimal. The number will always be a whole dollar amount and I dont want the cents to show.
The difficulty arises probably because I am moving through a collection of controls on the form setting text property to the value without formatting and not validating.

Thanks Mark
0
etsellinc
Asked:
etsellinc
  • 4
  • 4
  • 2
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
I have always hate the MaskedTextbox.

you should consider:
-a numeric up down control
-a custom control (http://www.emoreau.com/Entries/Articles/2003/03/Creating-your-own-Windows-Custom-Control.aspx)
0
 
technofileCommented:
If you are pulling a money value out of a database and setting the maskededitbox from that I would do
maskededitbox.text = Cint(datatable.Rows(i).Item(0))
or
maskededitbox.text = Cint(datatable.Rows(i).Item(0).ToString)
0
 
technofileCommented:
Also you need to change your mask to 00000000
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
etsellincAuthor Commented:
To technofile:
Some the Mask Text boxes in the collection are setup for a date and the database field placed in date time. Therefore converting the data field to INT prior to inserting into the Masked Text Bax would not work. Although there may be a way to make this work by returning an INT within the query.

To emoreau:
The Up/Down control might be a solution. I'll try that.

To All:
The object of this discussion is to minimize the amount of programming necessary to complete the task. It's easy to revert back to the old fashion methods.

Mark

0
 
etsellincAuthor Commented:
To emoreau:

The Numeric Up/Down works great! Is there a way to hide the Up Down Arrows?

Mark
0
 
technofileCommented:
I was talking about for the maskededitbox in question not all your boxes just the one that is for money, you obiously have diffent masks in different maskededitboxes for the other values right?
0
 
Éric MoreauSenior .Net ConsultantCommented:
0
 
etsellincAuthor Commented:
To technofile:

I go through the collection of objects on the form assigning there values according to the field name described in the tag of the object. I do know what kind of object it is but don't know the type of data that is being placed in it. For the Masked Text Box the data could be a Phone Number, Date or a Number. I would have to write code the check the data type of the dataset field to make a determination.
0
 
etsellincAuthor Commented:
To emoreau:

Thanks for the suggestion of the modified control. I don't think I'll use it though because of distribution difficulties. I'll live with the arrow being visible.

You would think that M$ would be smart enough to create a "numeric box" or add the show/hide of the arrows on the Up/Down box. Shame on M$!

Thanks for all the help.

Mark
0
 
technofileCommented:
Oh I see what you are doing, that makes more sense now, lol. Yea probably a up/down would work as long as they dont need to change it a lot. However if they are going to need to change all this information a lot it might be worth the effort of determining datatype so you can set up masks.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 4
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now