1 Replies - 394 Views - Last Post: 22 November 2012 - 11:38 AM Rate Topic: -----

#1 Drewburr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 22-November 12

Problem using For Next loop to sort radio-button selections

Posted 22 November 2012 - 11:25 AM

I am doing a class project where I provide a list of trails in my area that match the radio-box and check-box selections I have provided on the first form. I think I am on the right track but have been having troubles getting the correct selections to display on the second form. Here are the arrays I have created;

 
    'Declaring dimensions of array that contains all trail info
    '(Name, Out & Back, Loop, Advanced, Moderate, Easy, Dog, Bike, Fish, Paved, Distance) Those are parameters of array.
    Friend Traillist(,) As String = _
        {{"Sam Braxton", "0", "1", "0", "1", "0", "1", "1", "0", "0", "3.4"}, _
        {"Crazy Canyon", "1", "0", "0", "1", "0", "1", "1", "0", "0", "2.9"}, _
        {"Meadow Loop", "0", "1", "0", "0", "1", "1", "1", "0", "0", "2.2"}, _
        {"Patty Canyon Southside", "0", "1", "0", "0", "1", "1", "1", "0", "0", "2.4"}}

    Dim TrailNumber As Integer = 4
    'Array created to compare radiobutton and checkbox selections to Traillist
    Friend Controllist(,) As String = _
        {{"0", "0", "0", "0", "0", "0", "0", "0", "0"}}
    Dim controlnumber As Integer = 1
    Friend displaystring As String  


These are the arrays I have created to compare the info. I have set each radio-button and check-box to change a value to the controllist. I am matching out/back through paved. An example is as follows;

  Private Sub OutBackRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OutBackRadioButton.CheckedChanged
        If OutBackRadioButton.Checked Then
            Controllist(0, 0) = CStr("1")
        Else
            Controllist(0, 0) = CStr("0")
        End If
    End Sub

    Private Sub LoopRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoopRadioButton.CheckedChanged
        If LoopRadioButton.Checked Then
            Controllist(0, 1) = CStr("1")
        Else
            Controllist(0, 1) = CStr("0")
        End If
    End Sub  
And so on, through (paved check-box)

Now comes my question, sorry for the long build up, but I wanted to show my thought process. The following piece of code is not displaying the correct selections in the form2 listbox. I have changed it many different ways and think I am on the wrong track with the ForNext Loops, but am not sure how. Here is the code;

 Friend Sub SearchButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchButton.Click
        Dim rowindex, colindex, controlindex As Integer

       'Go through control list and match to traillist then display trail name
        For controlindex = 0 To 8
            For rowindex = 0 To TrailNumber - 1
                For colindex = 1 To 9

                    If controlindex = Traillist(rowindex, colindex) Then
                        displaystring += (Traillist(rowindex, 0))
                    End If
                Next
            Next
        Next
        Form2.SearchListBox.Items.Add(displaystring)
        Form2.ShowDialog()

    End Sub 


I would greatly appreciate an suggestions on where I am going wrong. Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Problem using For Next loop to sort radio-button selections

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5432
  • View blog
  • Posts: 11,643
  • Joined: 02-June 10

Re: Problem using For Next loop to sort radio-button selections

Posted 22 November 2012 - 11:38 AM

I think you should stop. You're doing this all with an array and a lot of brute force?
VB.NET is an Object Oriented language. You should do this in an Object Oriented way.

Make a class for Trail and give it parameters for Name, OutBack, Loop, Advanced and so on.

Taking a proper OOP approach is going to save you countless hours later.
Let's say you want to save and load these trails: Just serialize them. Let's say you want to add a photo as the map: Just add an Image property.
Let's say you want to add a URL link to the campground site: Just add a property.

There are tutorials for both properties and objects in my signature block.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1