Validation of text box

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
yogeshkAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

yogeshkAuthor Commented:
i will appeaciate if anyone give me the results urgent. Thanks . This site is really powerful.
0
Ryan ChongCommented:
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
supunrCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

supunrCommented:
btw, give all the textboxes the same name and different indexes, this way you only need to write one function to validate data.  
0
ananthuCommented:
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
CleanupPingCommented:
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
GPrentice00Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.