6 Replies - 8731 Views - Last Post: 18 December 2012 - 04:57 PM Rate Topic: -----

#1 karenmckee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 17-December 12

problem getting result from multidimentional array

Posted 17 December 2012 - 05:03 AM

I am trying to read from a list box AND a text box to find out if a string ins in a 2 dimensional array. If it is, I want to choose that row and column index 0 for my result. One of my errors is that my index is out of bounds and I can't read the proper array index. I typically get (0,0) as a result, if I get one. I have been playing with the code for days and I can't get it. I understand how to get the information from either 2 list boxes or 2 text boxes, but I am not sure where my disconnect is. Thank you.


public Class PartsForm1
    Dim PartNumber(,) As String = {{"PR214", "MR43T", "RBL8", "14K22"},
        {"PR223", "R43", "RJ6", "14K24"},
        {"PR224", "R43N", "RN4", "14K30"},
        {"PR246", "R46N", "RN8", "14K32"},
        {"PR247", "R46TS", "RBL17Y", "14K33"},
        {"PR248", "R46TX", "RBL12-6", "14K35"},
        {"PR324", "S46", "J11", "14K38"},
        {"PR326", "SR46E", "XEJ8", "14K40"},
        {"PR444", "47L", "H12", "14K44"}}
    Dim BrandString As String() = {"VB AUTO", "Brand A", "Brand C", "Brand X"}
    Private Sub ExitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitButton.Click
        Me.Close()
    End Sub
    Private Sub VBAutoPartButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VBAutoPartButton.Click
        Dim PartIndexInteger As Integer
        Dim IndexInteger As Integer = 0
        Dim PartFoundBoolean As Boolean = False
        Dim BrandIndexInteger As Integer

        For BrandNameIndexInteger As Integer = 0 To 2 Step 1
            BrandIndexInteger = BrandNameListBox.SelectedIndex

            For PartIndexInteger = 0 To 8 Step 1
                Do Until PartFoundBoolean
                    If PartNumberTextBox.Text.ToUpper() = PartNumber(BrandIndexInteger, IndexInteger) Then
                        PartIndexInteger = IndexInteger
                        PartFoundBoolean = True
                        ResultsLabel.Text = PartNumber(0, PartIndexInteger)
                    Else
                        IndexInteger += 1
                    End If
                Loop
            Next PartIndexInteger
        Next BrandNameIndexInteger
    End Sub


This post has been edited by modi123_1: 17 December 2012 - 08:04 AM
Reason for edit:: fixed botched code tag


Is This A Good Question/Topic? 0
  • +

Replies To: problem getting result from multidimentional array

#2 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,797
  • Joined: 26-March 09

Re: problem getting result from multidimentional array

Posted 18 December 2012 - 04:02 AM

Hi Karen,

Welcome to the forum.

This is actually .Net code, so technically, you're in the wrong forum. That being said, I'll see if I can move things along whilst a mod comes along to move the post.

I'm slightly confused by your description.

Can you tell me what you have in your listbox and what will be entered in the textbox?
Was This Post Helpful? 0
  • +
  • -

#3 karenmckee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 17-December 12

Re: problem getting result from multidimentional array

Posted 18 December 2012 - 04:24 AM

Thank you. I apologize. In the list box is three strings. It's the same as the array of brandStrings except for the first one is missing, as that is what I am trying to print out- the row number number that matches that is typed into the text box at the column 0.In the text boxes are supposedly what is in the array. I know that I don't even have a message box to tell the user it's not correct if it doesn't match- I am just trying to get it to work if it does. Thank you.
Was This Post Helpful? 0
  • +
  • -

#4 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,797
  • Joined: 26-March 09

Re: problem getting result from multidimentional array

Posted 18 December 2012 - 06:36 AM

OK, still not too clear....

Listbox contains "Brand A, Brand C, Brand X"?

User will type a part number into the text box from your array?

So for example, if I select Brand C and type in "J11" into the text box, the result will be "PR324"?

Am I understanding that correctly?
Was This Post Helpful? 0
  • +
  • -

#5 karenmckee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 17-December 12

Re: problem getting result from multidimentional array

Posted 18 December 2012 - 12:43 PM

Yes, that it what I am trying to say! Thank you!
Was This Post Helpful? 0
  • +
  • -

#6 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,797
  • Joined: 26-March 09

Re: problem getting result from multidimentional array

Posted 18 December 2012 - 01:35 PM

As you already providing one index of the array through the list box, I would think that you only need one loop as a look up. Off the top of my head, I think your array indices are the wrong way around, should be (RecordNumber, Brand).

So, for example (bear in mind I'm not a VB.Net programmer, so this isn't proven code and I haven't declared any variables either):

' I'm making the assumption that the list is 0 based, so you need to add 1 to map to your Brands, as index 0 is VB-AUTO, which is the one to look for.
intBrandIndex = BrandNameListBox.SelectedIndex + 1

' Loop through the full array
For intLoop = 0 to 8 ' For a variable size array, you could use UBOUND(PartNumber) instead of 8
  ' Check if we have a match in the relevent column
  If PartNumberTextBox.Text.ToUpper() = PartNumber(intLoop,intBrandIndex) Then
    ResultsLabel.Text = PartNumber(intLoop,0)
    exit for
  end If

Next intLoop


Hope that helps a little.

This post has been edited by maj3091: 18 December 2012 - 01:37 PM

Was This Post Helpful? 1
  • +
  • -

#7 karenmckee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 17-December 12

Re: problem getting result from multidimentional array

Posted 18 December 2012 - 04:57 PM

Thank you SO much! It was for an assignment for school, which is over, but I am still going over the code in my head! It was the only assignment that I didn't get, so it's getting to me! I AM going to make this work! Anyway, thank you SO much for taking the time to help me, even though I am in the wrong forum! I truly appreciate that! :bigsmile:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1