Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8634945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:50:57+00:00 2026-06-12T09:50:57+00:00

I am doing my homework for my visual basic class. I have most of

  • 0

I am doing my homework for my visual basic class. I have most of the code written and everything seems to be working well except for my If Not statement that catches the exception when the loop does not find what it is looking for. Anyone see a problem with the way the code looks. The file is loaded in using the browse button already and it works find when I enter information that the loop can find.

Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As   
System.EventArgs)

Handles btnSearch.Click
    'event level variables
    Dim Found As Boolean
    Dim Counter As Integer

    'looks for entry match
    If rdoAbbrev.Checked = True Then
        Do Until Found Or Counter > 257
            If Country(Counter).Abbreviation.ToUpper = txtAbbrev.Text.ToUpper Then
                Found = True
                txtCountry.Text = Country(Counter).Names
            Else
                Counter += 1
            End If
        Loop
    Else
        Do Until Found Or Counter > 257
            If Country(Counter).Names.ToUpper = txtCountry.Text.ToUpper Then
                Found = True
                txtAbbrev.Text = Country(Counter).Abbreviation
            Else
                Counter += 1
            End If
        Loop
        If Not Found Then
            MessageBox.Show("This is not a valid entry.", "NO MATCH FOUND", MessageBoxButtons.OK)
            If rdoAbbrev.Checked = True Then
                txtAbbrev.Text = ""
                txtAbbrev.Focus()
            Else
                txtCountry.Text = ""
                txtCountry.Focus()

            End If
        End If
    End If
    'match not found response

    'reset variables
    Counter = 0
    Found = False
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:50:58+00:00Added an answer on June 12, 2026 at 9:50 am

    You If Not Found block only occurs if rdoAbbrev.Checked = True. Is that what you intended? If not, then that block of code should either be located outside of the first If block (below it) or you should have a second If block after the first While loop.

    EDIT
    It looks like Country is an array. You should probably use Counter >= Country.Length.

    Arrays in VB.NET are 0-based. Meaning that the first item is located at Country(0), the second item is at Country(1), etc. If there are 100 elements in the array, then the last element is located at Country(99). Country(100) does not exist and will cause an Exception if you try to access it.

    I’m not sure what the requirements of your homework are, but usually to iterate over the elements of a collection (array, list, etc), you would use a For loop. You can jettison from the loop early with the Exit command.

    For Counter As Integer = 0 To Country.Length - 1
         '...Country(Counter)
         If Found Then Exit For
    Next
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

well I'm doing this homework but I'm still not viewing the fault... When I
newbie doing Java homework here. I have one class named Album which contains the
I am doing homework but I have problem with non-RestFul routes. My spec is:
I am doing a homework assignment for my summer OO class and we need
I am doing a homework assignment for my summer OO class and we need
I'm doing some homework and while I have some experience with SML, Haskell has
I'm doing a homework project that requires this: Below you will find the code
Me and my friend having a problem while doing a homework assignment. We have
This is NOT a homework question, actually I am doing this for fun. Here
As question states, I am doing homework which have 2 variables BOOK, and MAGAZINE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.