Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 136,178 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,995 people online right now. Registration is fast and FREE... Join Now!




using validation

 
Reply to this topicStart new topic

using validation

Panaboy
30 Sep, 2007 - 05:17 PM
Post #1

New D.I.C Head
*

Joined: 18 Apr, 2007
Posts: 3


My Contributions
CODE

Private Sub BtnGrade_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnGrade.Click
        Dim s1, s2, s3, s4, s5 As Integer
        Dim grade As String
        Dim average As Double
        Dim isconverted As Boolean
        isconverted = Integer.TryParse(TxtS1.Text, s1)
        isconverted = Integer.TryParse(TxtS2.Text, s2)
        isconverted = Integer.TryParse(TxtS3.Text, s3)
        isconverted = Integer.TryParse(TxtS4.Text, s4)
        isconverted = Integer.TryParse(TxtS5.Text, s5)
        If isconverted = True Then
            average = (s1 + s2 + s3 + s4 + s5) / 5
            grade = LblGrade.Text

            Select Case average
                Case Is <= 70
                    grade = "Tiger"
                Case 70 To 74
                    grade = "Pro"
                Case 75 To 90
                    grade = "Want to Be"
                Case Is >= 90
                    grade = "Duffer"
            End Select

            LblGrade.Text = grade.ToString()
        Else
            MessageBox.Show("Wrong Information entered", "Quizz4", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly)
        End If
    End Sub


    Private Sub BtnClear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnClear.Click
        TxtS1.Text = ""
        TxtS2.Text = ""
        TxtS3.Text = ""
        TxtS4.Text = ""
        TxtS5.Text = ""
        LblGrade.Text = ""
    End Sub
End Class


Hello, this is my problem: need to validated allthis texboxes so it display a message box when no numeric value is inserted in one of the texboxes.
Do i need to use the isnumeric Method, for each of the texboxes..
thnaks

*ALWAYS use code blocks smile.gif

This post has been edited by PsychoCoder: 30 Sep, 2007 - 05:20 PM
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Using Validation
30 Sep, 2007 - 05:21 PM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,983



Thanked: 125 times
Dream Kudos: 8625
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
You have your IsConveted boolean value, if it's false then theres no numeric value, also, this is a VB.Net question so I'm moving it to the VB.NET forum smile.gif
User is offlineProfile CardPM
+Quote Post

m2s87
RE: Using Validation
30 Sep, 2007 - 10:51 PM
Post #3

D.I.C Regular
Group Icon

Joined: 28 Nov, 2006
Posts: 390



Thanked: 1 times
Dream Kudos: 1225
My Contributions
QUOTE(PsychoCoder @ 1 Oct, 2007 - 04:21 AM) *

You have your IsConveted boolean value, if it's false then theres no numeric value, also, this is a VB.Net question so I'm moving it to the VB.NET forum smile.gif

He means, you should change the use of isconverted, like:
CODE

...
Dim sum As byte=0
if val(TxtS1.Text)<>0 sum +=1
if val(TxtS2.Text)<>0 sum +=1
if val(TxtS3.Text)<>0 sum +=1
if val(TxtS4.Text)<>0 sum +=1
if val(TxtS5.Text)<>0 sum +=1
If sum > 1 Then
...

User is offlineProfile CardPM
+Quote Post

Jayman
RE: Using Validation
1 Oct, 2007 - 12:34 AM
Post #4

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,926



Thanked: 42 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
You could also, in much less code, just put your code in a try/catch to handle NumberFormatException.
CODE

Try
     'your code here to parse values
Catch ex As NumberFormatException
     Console.WriteLine("your message to user")
End Try

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 12:59AM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month