Simple Edit Box Validation???

I need to create some simple TextBox validation. I will need 
to limit the length to a fixed number of characters. I also 
need to restrict the data entered two different ways:
(a) Numeric Only
(b) AlphaBetic or Numeric Only (hexadecimal numbers), with 
conversion to uppercase.

Initially these fields can simply refuse to take data of the 
wrong type. Later on it might be nice to have some sort of 
message to the user, or possibly some ToolTip text, or 
context sensitive help.

Can anyone help me with this? 


0
NoSpam8358 (375)
6/26/2007 11:13:36 PM
vc.mfc 33608 articles. 0 followers. Follow

2 Replies
479 Views

Similar Articles

[PageSpeed] 47

>I need to create some simple TextBox validation. I will need 
>to limit the length to a fixed number of characters.

CEdit::SetLimitText (EM_SETLIMITTEXT)

>I also 
>need to restrict the data entered two different ways:
>(a) Numeric Only
>(b) AlphaBetic or Numeric Only (hexadecimal numbers), with 
>conversion to uppercase.

Here's an example of a derived edit control class that handles the
EN_UPDATE notification message. The EN_UPDATE message is useful to
handle as it caters for both normal entry and clipboard paste
operations.

void CHexEdit::OnUpdate() 
{
	CString str;
	
	GetWindowText( str );

	/* Access the string buffer directly */
	LPSTR pBuff = str.GetBuffer( 10 );

	bool bProblem = false;

	for ( int indx = 0; indx < str.GetLength(); indx++ )
	{
		char nChar = pBuff[indx];

		if ( ( ( nChar >= '0' ) && ( nChar <= '9') ) ||
			( ( nChar >= 'A' ) && ( nChar <= 'F' ) ) ||
			( ( nChar >= 'a' ) && ( nChar <= 'f' ) ) )
		{
		}
		else
		{
			bProblem = true;
			break;
		}
	}

	str.ReleaseBuffer();

	if ( bProblem )
	{
		int start, end;

		/* Find the current caret position */
		GetSel( start, end );

		/* Restore the last good text that was entered */
		SetWindowText( m_LastGood );

		/* Restore the caret */
		SetSel( start-1, end-1, true );

		/* Let the user know */
		MessageBeep( MB_OK );
	}
	else
	{
		/* Store the last good entry string in a
		 * member variable of the Hex edit class
		 */
		m_LastGood = str;
	}
}

Dave
0
davidl7375 (2060)
6/26/2007 11:45:03 PM
You may find one of these meets your needs:

http://www.codeproject.com/editctrl/maskededit.asp
http://www.codeproject.com/editctrl/validatingedit.asp

Tom

"Peter Olcott" <NoSpam@SeeScreen.com> wrote in message 
news:P5hgi.9463$s57.4316@newsfe07.phx...
>I need to create some simple TextBox validation. I will need to limit the 
>length to a fixed number of characters. I also need to restrict the data 
>entered two different ways:
> (a) Numeric Only
> (b) AlphaBetic or Numeric Only (hexadecimal numbers), with conversion to 
> uppercase.
>
> Initially these fields can simply refuse to take data of the wrong type. 
> Later on it might be nice to have some sort of message to the user, or 
> possibly some ToolTip text, or context sensitive help.
>
> Can anyone help me with this?
> 

0
tom.nospam (3240)
6/27/2007 1:32:51 PM
Reply:

Similar Artilces:

AutoComplete from Validation List
I need to add a column to a worksheet that shows the Country of Orgi for a product and that county's assigned computer code (Ex. Unite States - 10001). I have a list of counties and correspoding codes bu the list to so long (300 countries) that I would like to be able t type in "United" and have the cell auto complete the rest. Otherwise have to scroll through a drop down menu of over 300 entries. Any suggestions would be appreciated. Thanks -- Message posted from http://www.ExcelForum.com Debra Dalgleish shows a way to use two data|validation cells. The first cell can s...

Excel Edit F2 button changed for Mac???
Switched to Microsofts version of Excel for Mac. Can anyone tell me what keystroke allows me to edit a cell? Before I switched to a Mac it was the F2 button. Please help. Thank you. See the answers in the m.p.mac.office.excel newsgroup. In article <1176582208.958694.269620@q75g2000hsh.googlegroups.com>, ssears@indy.tds.net wrote: > Switched to Microsofts version of Excel for Mac. Can anyone tell me > what keystroke allows me to edit a cell? Before I switched to a Mac > it was the F2 button. Please help. Thank you. ...

Simple graph
I have a chart with zip codes and a population rate. ZIP RATE 80001 2.34 80002 1.23 80003 1.23 I want to make a chart that has the rate on the x axis and the number of times that rate occurs on the y axis. | | | * | | * |_________________________________ | | 1.23 2.34 Thank you. I will assume the ZIP and RATE stuff is in A1:B200 (labels in row 1) Label in G1 to read RATE (but leave it empty for now), label in H2 to read COUNT Make a list of rates in G2:G20 (say) In H2 =COUNTIF($B$2:$B$200,G2) Copy down the row Select H1:G20 and make a...

Simple help with implementing Outlook-like GUI
Hi All. I am an experienced unix programmer who sometimes has to do something in the windows world, and always has newbie-questions. Basically I want to write an application program that looks like outlook in that it has nice icons down the left hand side that choose the content of the main area in the right hand side. So I started the MFC App wizard, and got me a SDI program with a CLeftFrame (CTreeView) and a CMainFrame (CFrameWnd). Then I prepared the following snippet of code to draw the buttons: // Create a pushbutton CBitmapButton* pmyButton; pmyButton = new CB...

Simple Simple Simple
Just started Excel (again) and need to make an easy speadsheet fo calculating square inches. Column A: Height Column B: Legnth Column C: Total Tags per 16 x 24 Column D: Cost per tag Figures I know: each sheet cost me $9.98. each sheet is 16 x 24 inches What I want to do is enter the Height, enter the Length and have th total (sum) be entered into columns C and D. I can't believe I forgot how to enter formulas. Any help will b appreciated. Thank you, Crai -- Message posted from http://www.ExcelForum.com Hi Craig, One Way, might be better ways but this'll work: List the colou...

Using Symbols (&/-) in In Two Dependent Drop Down Boxes. Can't get the VLOOKUP to work!!!
Hey all, I have a category list of products and then a list of brand names for each product. So, I set up a series of drop down boxes (using Data Validation) for the categories and then a second series dependent which category you pick in the first, for the brand names. HERE IS MY PROBLEM: When I set up the category list I had to create them as One-Word-Names. I tried to set up a lookup table with the real category names (multiple words and symbols), but I can't seem to get the first drop down box to reference the lookup without then screwing up the Data Validation of the second (depende...

Allow User to Edit Ranges
Any better way to input the range for a 30 spreadsheet??? a8:j20 , m8:p20 , r8:s20 a22:j34 , m22:p34 , m22:p34 a36:j48 , m36:p48 , m36:p48 a50:j62 , m50:p62 , m50:p62 a64:j76 , m64:p76 , m64:p76 a78:j90 , m78:p90 , m78:p90 a92:j104 , m92:p104 , m92:p104 and so on .... Hi, Are you asking how to assign 30 different user to the ranges you listed or are you saying you want to give one or more users access to all 30 ranges? Or are you talking about 30 spreadsheet? -- If this helps, please click the Yes button. Cheers, Shane Devenshire "crapit" wrote: > Any better w...

Simple hack to get $500 to your home. 06-05-10
Simple hack to get $500 to your home at http://uknews.tk Due to high security risks,i have hidden the cheque link in an image. in that website on left side below search box, click on image and enter your name and address where you want to receive your cheque.please dont tell to anyone. ...

Edit Packing List
Question, Some of the guys in my shipping department are complaining that the packing list is to hard to read. Between the items, the notes on it, and whatever else. I want to make the line item highlighted on the packing list so that it is easier to see the items that need to be packed. So the line with the actual item code, I want it to be highlighted in light grey so it is easier to see, and will hopefully make for less errors. Thanks, Nick Nick, It might be easiest if you modified the FONT for that line and just made it BOLD. An example below <FONT name="myFont"...

Combo box getting hidden
I have a problem with the same CView class I asked about the other day... Its a CView class with an extensive OnDraw method (Gantt-based resource loading chart). I have a few controls in the corner - a plus and minus CButton, a CStatic text (my font problem the other day) and a CComboBox. I also have a horizontal and vertical CScrollBar. These controls are class members (no resource associated) and are all .Create() in my ::Create method. Following an OnDraw(), everything is drawn properly, except my combo box. I assume it is a z-order problem, but I don't know how to bring it forw...

re: End survey if two boxes ticked
Hi, I have created a form in access to be sent out by email. In the survey if a respondant ticks two boxes (Q1 never, Q2 nothing) I want to terminate the survey and the email come back to me. Can someone advise on what to do? Thanks F0zz ...

Opening file with Word 2007 for editing
i am building my own website (intranet). One of the options i would like to use is opening an HTM-file with Word 2007 for editing. The opening of the file starts by pressing an interactive button on a webpage. Anyone knows an answer how to do this? I think it must be a line in the button properties link. You need to ask in a Word newsgroup, not FrontPage. -- Tom [Pepper] Willett Microsoft MVP - FrontPage Since 1997 --------------------------- "Nico" <Nico@discussions.microsoft.com> wrote in message news:E64ADD69-2009-44D8-870E-4CB21BDCD08D@microsoft.com... :i...

Check Box Error
I have an Access form for entering a new order. There are 4 options for the turnaround of the order. This is a form we have been using for at least 4 years without problems. The user selects one of the turnaround options using the check box options. Yesterday, mysteriously, when the user opens the form, ALL 4 check boxes are checked and the user cannot uncheck the box. We have 10 users of this Access application but only 2 users are experiencing this problem. We tried to load new versions of the applications for the 2 users, loading older versions of the application for the 2 users - bu...

Calendar in Cell Validation
I want to implement a cell validation such that when the user attempts to input a date, a "list" box-like functionality pops up that has a calendar and the user may then choose the date by picking with the mouse How would I implement this? Thanks Jerry Try the following Web site. http://www.fontstuff.com/vba/vbatut07.htm This site's author covers this in a tutorial, but also provides downloads. Mark <jerry.ranch@pioneer.com> wrote in message news:2r9t51pjmumjk7rjpopo7fuamg81gqkljq@4ax.com... >I want to implement a cell validation such that when the user attempts &g...

Simple Query Wizard hangs
I am using Access 2003 When I initiate the "Simple Query Wizard", I am presented with the first screen - "What fields do you want in your query" When I click on the pulldown list to select a table, I get the following message: "The expression On Get Focus you entered as the event property setting produced the following error: the text you entered isn't an item in the list * the expression may not result in the name of a macro, the name of a user-defined function, or [Event Procedure]. * There may have been an error evaluating the function, event, or macro&q...

List Box Selection to Run report
Hi I have a list box in which there are 10 fields shown. I wish for the user to make selections (multiple if required) and then for them to run a report. I have the following code (mainly extracted from Martin Greens website) which is allowing the report to run but my criteria is not being used in the record selection. There is no other criteria in the reports query so I am looking for help as to why I am not able to run the report correctly displaying the users selections Private Sub cmdRunReport_Click() Dim db As DAO.Database Dim varItem As Variant Dim strCriteria As Str...

Xch2k (SB edition) LOG and IFS question
Dear, Even I did the full backup with the Exchange server, the LOG and IFS extension file still in the MDBDATA folder. How to purch? Thanks!! -david I'm not sure what you are referring to regarding the IFS extension file. Please explain. As far as your full backup, how did you perform the backup? It must be done using an exchange-aware backup program (such as NTbackup run from a computer with minimum the Exchange management tools installed). It must also be a full *online* backup, with all Exchange services running and all databases mounted. -- Ben Winzenz Exchange MVP M...

want to create a message box to appear on open
I want to be able to have a Message appearing the first time o open a worksheet in an excel document or even have appear when the document opensinitially. can this be done easily and removed easily? Private Sub Workbook_Open() 'Place this code in the ThisWorkbook object MsgBox "Insert your message here", vbInformation, "Insert your message box title here" End Sub "Fionajpower" wrote: > I want to be able to have a Message appearing the first time o open a > worksheet in an excel document or even have appear when the document > opensinitially....

I Need a Simple Sales Software
Hello, I am looking for software to keep track of my prospects, customers, and the notes of the sales process. I spend about one hour a day on sales and marketing, so I prefer a simple and inexpensive software. Maximizer, Outlook, Act, and Goldmine seem made for the full-time professional salesperson. Please let me know if what I am looking for exists. Best Regards, T.I. ...

combo box filters on continuous form
Access03/WinXP On a subform, I am using two combo boxes for data selection. The first combo box allows the user to select a Primary category; the AfterUpdate property sets the RowSource for the second combo box where the user will select a Secondary category. In the AfterUpdate of the second combo box, I am using Me.Refresh and Me.Requery. This works without issue. The problem is that on selection of the Primary category where any previous records in the continuous form do not match the Primary category of the current record "lose" the data of the Secondary combo box. I ...

Make it more simple or intuitive to do simple things
I appreciate the fact that applications are becoming more versatile and able to do things that we hardly thought possible in the past but I feel that in this added complexity you are losing sight of the need to do simple things easily without resorting to trial and error or consulting "help" which often anyhow doesn't lead one straight to the solution! An example is how to produce a chart with a series of months i.e Jan Feb Mar etc appearing on the X axis. This is no doubt something that resulted naturally in the first versions of Excel charts or in a competitor's ea...

CommandbarCombo box change event not firing in VISIO
Hi I'm creating a Toolbar in Visio with CommandbarCombo box using VS 2003.The combobox should display the tooltip on change of each item in the list. I have handled changeevent but still event is not fired. Here is the code attached for the referecne: ******************************** CommandBar oStandardBar = null; private Hashtable hashTable = new Hashtable(); public static int iPrgId = 0; CommandBarComboBox cmbSecurityClass = null; Object oMissing = System.Reflection.Missing.Value; oStandardBar = (oVisio.ActiveDocument.Application.CommandBars as CommandBars).Add("IAMToolbar&q...

Simple public folder permission problem
I have a public task list folder. However even though I have given everyone "Author" priviledges and full control of the directory, users cannot update the tasks (although they can create new ones). The changes to tasks get reset to their original values. Where should I look to fix this problem? Brian How did you grant Author Access, via Outlook or ESM? What do you meanyou gave them full control of the directory? "Brian Taylor" <taylorb@newsgroups.nospam> wrote in message news:e2hwumGrEHA.1160@tk2msftngp13.phx.gbl... > I have a public task list folder. Ho...

What is simple text?
When creating a custom list that includes a column of accounting formated data, I get an error message that 'fields without simple text will be ignored'. The result is all other data except the accounting formatted data. Help!!!! I suppose it means without the currency symbol and thousands delimiters. On Fri, 8 Apr 2005 11:01:04 -0700, TexMas <TexMas@discussions.microsoft.com> wrote: >When creating a custom list that includes a column of accounting formated >data, I get an error message that 'fields without simple text will be >ignored'. The result is ...

Populating a list box
I am trying to populate a list box with data from an Access table. I added the list box field to a Great Plains form (and to the VB project) and am trying to get the VBA code to work. The code to open the Access table works fine but the AddItem method code bombs and returns Run-time error 438. Object doesn't support this property or method. Here's the code: Do Until rstSalAdjCode.EOF cboReason.AddItem (rstSalAdjCode(0)) 'Code bombs on this line rstSalAdjCode.MoveNext Loop Anyone know what I'm doing wrong here? Thanks. You cannot add items to a gplist bo...