?
Solved

Validation of text box

Posted on 2003-03-16
7
Medium Priority
?
124 Views
Last Modified: 2010-05-01
How do i make a validation of several test boxes, checking that all values enetered by the user is positive? i want a simple code . and if one is not positive, prompt a message and give focus to that particular text box.

Thanks
0
Comment
Question by:yogeshk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 

Author Comment

by:yogeshk
ID: 8149116
i will appeaciate if anyone give me the results urgent. Thanks . This site is really powerful.
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 8149146
if not isnumeric(text1) then text1 = val(text1)
If val(text1) >= 0 then
  msgbox "It's positive"
else
  msgbox "It's negative"
end if
0
 
LVL 11

Accepted Solution

by:
supunr earned 80 total points
ID: 8149176
Private sub Text1_Change(Index as Integer)
    if (Val(Text1(Index).Text) < 0) then
        MsgBox "Value Must be greater than 0"
    End if
End Sub

but better option might be for you to stop all the negative numbers completely using the following code.


Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
    Select Case KeyAscii
        case vbKey0 to vbKey9:
        case vbKeyDecimal:
        case vbKeyReturn, vbKeyEscape, vbKeyDelete, vbKeyBack:
          ' accept these keys.
        case else:
            KeyAscii = 0 ' disalbe key
    End Select

End Sub

Good Luck!
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:supunr
ID: 8149188
btw, give all the textboxes the same name and different indexes, this way you only need to write one function to validate data.  
0
 

Expert Comment

by:ananthu
ID: 8149199
Hi Yogesh,
Try This....

For Each Control In frmMain
        If TypeOf Control Is TextBox Then
            If Trim(Control.Text) = "" Then
                MsgBox "Field Cannot Be Empty"
                Control.SetFocus
                EmptyFlag = "Empty"
                Exit Sub
            Else
                EmptyFlag = "Full"
            End If
        End If
Next

In the Code instead of Trim(Control.Text) = "" do the eval for checking +veness.

Hope this helps,
Ananth.
0
 

Expert Comment

by:CleanupPing
ID: 8532251
Hi yogeshk,
This old question (QID 20552907) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
0
 
LVL 6

Expert Comment

by:GPrentice00
ID: 8956459
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

-->Accept supunr's comments as answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

GPrentice00
EE Cleanup Volunteer
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question