473,405 Members | 2,154 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,405 software developers and data experts.

Cuxstom Format Masked Text Box

I have a masked text box that needs to be formatted as

Three letters a period three numbers

ABC.123

in VB.net Visual Studio 2005

any help would be greatly appreciated.

CoachBarker
Jul 24 '07 #1
8 2529
TRScheel
638 Expert 512MB
I have a masked text box that needs to be formatted as

Three letters a period three numbers

ABC.123

in VB.net Visual Studio 2005

any help would be greatly appreciated.

CoachBarker
Why not just have two textboxes that only allow 3 characters, have one that accepts alpha characters, the other only numbers, and seperate them by a label that has only the '.' in it.

[TEXTBOX1].[TEXTBOX2]
Jul 24 '07 #2
Why not just have two textboxes that only allow 3 characters, have one that accepts alpha characters, the other only numbers, and seperate them by a label that has only the '.' in it.

[TEXTBOX1].[TEXTBOX2]

The text box is used to list the Name of a Course that is being stored in database. Don't want to go to the extreme of concatenating the string to pass it to the data base
Jul 24 '07 #3
Plater
7,872 Expert 4TB
Is this a web or windows application?
Windows is easy with the maskedtextbox, web is a bit more tricky
Jul 24 '07 #4
TRScheel
638 Expert 512MB
The text box is used to list the Name of a Course that is being stored in database. Don't want to go to the extreme of concatenating the string to pass it to the data base
Well there are two other methods I have for you then. Either:

A) Catch each letter coming and going from the textbox, and if it doesnt fit the pattern, dissallow it (or inform the user somehow). Something like:

Expand|Select|Wrap|Line Numbers
  1. void TextBox1_TextChanged(object sender, EventArgs e)
  2. {
  3.     for (int i = 0; i < 3 && i < ((TextBox)sender).Text.Length; i++)
  4.     {
  5.         if (!IsAlpha(((TextBox)sender).Text[i]))
  6.         {
  7.             InformUserOfBadCharacter(i);
  8.         }
  9.     }
  10.  
  11.     if (((TextBox)sender).Text.Length > 3)
  12.     {
  13.         if (((TextBox)sender).Text[3] != '.')
  14.         {
  15.             InformUserOfBadCharacter(3);
  16.         }
  17.     }
  18.  
  19.     for (int i = 4; i < 7 && i < ((TextBox)sender).Text.Length; i++)
  20.     {
  21.         if (!IsNumeric(((TextBox)sender).Text[i]))
  22.         {
  23.             InformUserOfBadCharacter(i);
  24.         }
  25.     }
  26. }
  27.  
  28. static bool IsAlpha(char test)
  29. {
  30.     return (test >= 65 && test <= 90) || (test >= 97 && test <= 122);
  31. }
  32.  
  33. static bool IsNumeric(char test)
  34. {
  35.     return test >= 48 && test <= 57;
  36. }
  37.  

or

B) Create a property that fakes the two text box's values in the example I gave above. Something like:

Expand|Select|Wrap|Line Numbers
  1. public string CourseName
  2. {
  3.     get { return string.Format("{0}.{1}", TextBox1.Text, TextBox2.Text); }
  4. }
  5.  
Setting it would run through the same difficulties as method A. You would need to make sure the value is of valid size, and then of valid input. If not, I would probably throw an exception to be handled else where.
Jul 24 '07 #5
Is this a web or windows application?
Windows is easy with the maskedtextbox, web is a bit more tricky
This is a windows application.
Jul 24 '07 #6
Plater
7,872 Expert 4TB
This is a windows application.
Well then good news!
http://msdn2.microsoft.com/en-us/lib...edtextbox.aspx

The MaskedTextBox is your friend
Jul 24 '07 #7
TRScheel
638 Expert 512MB
Well then good news!
http://msdn2.microsoft.com/en-us/lib...edtextbox.aspx

The MaskedTextBox is your friend
Never used the masktextbox, but I suppose that with this he could use:

Expand|Select|Wrap|Line Numbers
  1. MyMaskedTextBox.Mask = "LLL.000";
  2.  
Jul 24 '07 #8
Never used the masktextbox, but I suppose that with this he could use:

Expand|Select|Wrap|Line Numbers
  1. MyMaskedTextBox.Mask = "LLL.000";
  2.  
Thank you all for your help I ended up formatting it this way
>LLL.000 and the greter than sign means that the letters are all captilized

Thanks
CoachBarker
Jul 24 '07 #9

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

Similar topics

6
by: Charles A. Lackman | last post by:
Hello, I an trying to get away from using a Date Time Picker and would like to know how to make a textbox format to a date, i.e. 6604 would be converted to 06/06/04 and if the user type in...
6
by: dyw55a | last post by:
How to implement mm/dd/yyyy format for textbox? I have text box with format mm/dd/yyyy. Now I want the cursor i generated whenever user highlight this textbox and whatever user inpu replace one...
2
by: orekinbck | last post by:
Hi There I have spent alot of time trying to get a masked text box to validate e-mails, but with no success. Mainly because I can't figure out how to account for the wide variety of different...
1
by: metridevkk | last post by:
Hi, I need to use a Masked Edit Control in my ASPX page. In VS.Net, I added the reference to MSMask.dll for my application & also added the MaskEdBox to the Toolbox. After adding the control to...
3
by: Panos | last post by:
Hi all, I can't clear a Masked edit control. I use it to input dates, so I have defined the mask as "##/##/####". I use the the well known meb.mask="" meb.text="" , but nothing happens. Does...
7
by: DazedAndConfused | last post by:
Curently I manualy code keypress edits. i.e. allow only 3 digits before decimal and two digits after decimal in .NET. Is there an easy solution to mask text boxes? The MSMASK32.OCX from vb6...
3
by: nt8jbwu02 | last post by:
I would like to allow a user to enter an ip address (quad octet format: www.xxx.yyy.zzz) in a combo box and then add it to the list when they have completed the entry. How can I do this? The...
1
by: Jeff Williams | last post by:
I want to use the masked text box to do the following 1. to allow a 4 digit number to be entered - mask 0000 2. to allow currency value to be entered - mask 0,000,000.00 in example 1 when I...
2
mafaisal
by: mafaisal | last post by:
Hello Experts I am Using MaskedText Box For Entering Date And I Use MAsk is Shortdate My Question is How To Validate This MaskedtextBoxt if it is Valid Date or Not I try Using IsDate But That is...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.