Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27403

Code working but not the way I want

$
0
0
I have the following code and if I run program and enter digits into the text boxes outwith min/max array then I get the message box unsuccessful. If I type digits within the range I get message successful. If I type the digit in word format I get the message that it is successfully entered. I have a tryparse there so I do not understand why it is accepting word format. What am I missing, please?

Also, if I change the word format by back spacing to number outwith range and click the verify button it still tells me I successfully entered!

Niki

Code:

Public Class Form1

    Private Sub btnVerify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVerify.Click
        'Declare Variables and arrays
        Dim intMinimum() As Integer = {7, 5, 0, 0, 6, 3, 4} 'Holds Minimum range.
        Dim intMaximum() As Integer = {9, 7, 4, 9, 9, 6, 8} 'Holds Maximum range.
        Dim strTextboxes() As String = {txtOne.Text, txtTwo.Text, txtThree.Text,
                                    txtFour.Text, txtFive.Text, txtSix.Text, txtSeven.Text}
        Dim intNumber As Integer
        Dim blnRange As Boolean = True
        Dim intCount As Integer

        For intCount = 0 To 6
            If Integer.TryParse(strTextboxes(intCount), intNumber) Then
                If intNumber >= intMinimum(intCount) And intNumber <= intMaximum(intCount) Then

                    blnRange = True
                Else
                    blnRange = False
                End If
            End If
        Next

        If blnRange = True Then
            MessageBox.Show("You have successfully entered a valid Pin")
        Else
            blnRange = False
            MessageBox.Show("you have entered an incorrect Pin")
        End If
    End Sub


Viewing all articles
Browse latest Browse all 27403

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>