Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

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

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
0
yogeshk
Asked:
yogeshk
1 Solution
 
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
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.

 
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

Featured Post

Technology Partners: 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!

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