Question Product Finder

rburton

New member
Joined
May 30, 2010
Messages
1
Programming Experience
Beginner
I have been looking over things, and since google to me is not helping but giving me a headach, I wanted to see if someone here can help.

I am trying to get this application to search two list box's but when i run the application it freezes up when I search from a second List box. And it still selects from the first boxx as well as the second one. I am getting frustrated with this project, yes it is for a class. I am learning this all over. Any help will be appreciated.

Here is the code.
VB.NET:
Option Explicit On
Option Strict On
Option Infer Off

Public Class ShipWithUs
    Private Sub zipTextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles zipTextBox.Enter

        Select Case zipListBox1.SelectedIndex
            Case 0
                shippingText.Text = "$15"
            Case 1
                shippingText.Text = "$15"
            Case 2
                shippingText.Text = "$15"
            Case 3
                shippingText.Text = "$15"
            Case 4
                shippingText.Text = "$15"
            Case 5
                shippingText.Text = "$15"
            Case 6
                shippingText.Text = "$15"
            Case 7
                shippingText.Text = "$15"
        End Select
        Select Case zipListBox2.SelectedIndex
            Case 0
                shippingText.Text = "$20"
            Case 1
                shippingText.Text = "$20"
            Case 2
                shippingText.Text = "$20"
            Case 3
                shippingText.Text = "$20"
            Case 4
                shippingText.Text = "$20"
        End Select

    End Sub
    Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
        Me.Close()
    End Sub

    Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


        ' fills the list box 1 with values
        zipListBox1.Items.Add("60611")
        zipListBox1.Items.Add("60234")
        zipListBox1.Items.Add("56789")
        zipListBox1.Items.Add("23467")
        zipListBox1.Items.Add("60543")
        zipListBox1.Items.Add("60561")
        zipListBox1.Items.Add("55905")
        zipListBox1.Items.Add("89567")
        zipListBox2.Items.Add("50978")
        zipListBox2.Items.Add("78432")
        zipListBox2.Items.Add("98432")
        zipListBox2.Items.Add("97654")
        zipListBox2.Items.Add("20245")

    End Sub

    Private Sub displayshippingButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles displayshippingButton.Click
        'determines whether a list box contains a specific ID
        Dim isFound As Boolean
        Dim index As Integer
        Dim numberofitems As Integer
        Dim id As String = String.Empty

        'assign id and number of list box items to variables
        id = zipTextBox.Text.ToUpper
        numberofitems = zipListBox1.Items.Count
        numberofitems = zipListBox2.Items.Count

        'search the list box, stopping either after the
        'last item or when the item is found
        Do While index < numberofitems AndAlso isfound = False
            If id = zipListBox1.Items(index).ToString.ToUpper Then
                isFound = True
            Else
                If id = zipListBox2.Items(index).ToString.ToUpper Then
                    isFound = True
                End If
            End If

            index = index + 0

        Loop
        If isFound = True Then
            zipListBox1.SelectedIndex = index
            zipListBox2.SelectedIndex = index

        Else
            zipListBox1.SelectedIndex = -1
            MessageBox.Show("Not Found", "Product Finder", _
            MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
        zipTextBox.SelectAll()

        Select Case zipListBox1.SelectedIndex
            Case 0
                shippingText.Text = "$15"
            Case 1
                shippingText.Text = "$15"
            Case 2
                shippingText.Text = "$15"
            Case 3
                shippingText.Text = "$15"
            Case 4
                shippingText.Text = "$15"
            Case 5
                shippingText.Text = "$15"
            Case 6
                shippingText.Text = "$15"
            Case 7
                shippingText.Text = "$15"
        End Select
        Select Case zipListBox2.SelectedIndex
            Case 0
                shippingText.Text = "$20"
            Case 1
                shippingText.Text = "$20"
            Case 2
                shippingText.Text = "$20"
            Case 3
                shippingText.Text = "$20"
            Case 4
                shippingText.Text = "$20"
        End Select
        Me.zipTextBox.Focus()
    End Sub
End Class
 
Last edited by a moderator:
A freeze suggests an infinite loop, so that should be the first place you look. Try placing a breakpoint on the first line of any loop (F9) and then run the project. When execution breaks at that line you can step one line at a time (F10) and into methods (F11) to see exactly what state your app is in. You can use the Autos, Locals and Watch windows and more to determine the value of any expression at any time. Before each step, ask yourself what you expect to happen. After the step, check to see whether what you expected actually did happen. If it didn't, you've found an issue, which you can work on fixing.
 
Back
Top