Results 1 to 5 of 5

Thread: What is wrong with my if statement?

Hybrid View

  1. #1
    Addicted Member
    Join Date
    Aug 11
    Posts
    200

    What is wrong with my if statement?

    I feel kind of silly asking about an if statement but I am having an issue.

    I created a goto line form in my application and it works, I am just trying to set some perimeters so it prompts a messagebox stating that the line number they entered doesn't exist. Basically if the number is lower than 1 or higher then the line count. Here is the code, when I have if statements nested like that the error will only work for whichever is first(this case it is the less than 1). I need it to work for both.

    vb Code:
    1. Dim page As RadPageViewPage = AutoGamerMain.RadPageView1.SelectedPage
    2.         For Each txt As FastColoredTextBox In page.Controls.OfType(Of FastColoredTextBox)()
    3.             If LineNumberTxt.Text <= txt.LinesCount Then
    4.                 If LineNumberTxt.Text >= 1 Then
    5.                     txt.Focus()
    6.                     txt.Selection.Start = New Place(0, LineNumberTxt.Text - 1)
    7.                     txt.DoSelectionVisible()
    8.                     txt.Invalidate()
    9.                 Else
    10.                     MessageBox.Show("You have entered a line which does not exist. Perimeters are (1-" & txt.LinesCount & "). Please choose a new line.")
    11.                 End If
    12.             End If
    13.             Next

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,512

    Re: What is wrong with my if statement?

    if the number is lower than 1 or higher then the line count
    Seriously?

  3. #3
    Addicted Member
    Join Date
    Aug 11
    Posts
    200

    Re: What is wrong with my if statement?

    Quote Originally Posted by dunfiddlin View Post
    Seriously?
    Worded wrong. I'll change it around. It should work like this though? It needs to be both less than the lins count an higher or equal to 1.

  4. #4
    Addicted Member
    Join Date
    Aug 11
    Posts
    200

    Re: What is wrong with my if statement?

    Blame it on a long day.

    vb Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim page As RadPageViewPage = AutoGamerMain.RadPageView1.SelectedPage
    3.         For Each txt As FastColoredTextBox In page.Controls.OfType(Of FastColoredTextBox)()
    4.             If LineNumberTxt.Text >= txt.LinesCount Or LineNumberTxt.Text <= 1 Then
    5.                 MessageBox.Show("You have entered a line which does not exist. Perimeters are (1-" & txt.LinesCount & "). Please choose a new line.")
    6.             Else
    7.                 txt.Focus()
    8.                 txt.Selection.Start = New Place(0, LineNumberTxt.Text - 1)
    9.                 txt.DoSelectionVisible()
    10.                 txt.Invalidate()
    11.             End If
    12.         Next
    13.        End Sub

  5. #5
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,512

    Re: What is wrong with my if statement?

    If ln >= 1 AndAlso ln <= count 'the other way round

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •