I'm trying to right a program with Multidimensional Arrays.
These are the instructions for the program:
The Valley Boulevard (VB) Auto Center management is pleased with your progress in developing their system. They require you to develop a new feature for their system.
Main Form. The main form for this project is shown below. VB Auto sells its own brand of spark plugs. In order to allow system users to cross-reference to major brands, the firm keeps a table of equivalent part numbers. You are to computerize the process of looking up part numbers in order to improve customer service.
Requirements. Name the project VBAutoLab8 + YourLastName – for example, if your last name is Bock, name the project VBAutoLab8Bock.
System Startup. The system will start up with the Their Part Number textbox blank (this currently displays RJ6) and NO Brand selected by default (none of the radio buttons are checked). Likewise, the Our VB Part Number display label (this currently displays the value PR223) for output will be blank. On startup, the cursor (focus) should be set to the textbox. The tab order should be Their Part Number textbox, Brand radio buttons, Lookup button, Clear button, then Exit button.
Lookup button – system operation. The system user will:
Enter the competitor's part number for that brand into the input textbox that is provided on the form shown above.
Select the brand by clicking one of the radio buttons.
Click the Lookup button - the system should display the equivalent VB Part Number to the output label shown above.
The lookup should work even if Their Part Number is NOT entered in capital letters.
Your code must use a search technique taught in the chapter, not simply a long series of IF statements. The program code for the lookup procedure must use a condition-controlled loop.
Display an appropriate error message such as “Reenter Their Part Number and Check Brand” if the lookup fails to find a match. Also display the OK button and Critical Error icon as part of the message box.
Clear button. When this button is clicked, clear the brand radio button selection so that none of the radio buttons are selected, clear the textbox and output display label, and set the focus back to the textbox.
Exit button. When this button is clicked, end the application.
Data Storage. Store the part numbers in a two-dimensional table (array). The data for the system may be loaded during the Form_Load event or you may wish to declare the array as a module-level array. Using the module-level array is probably easier as the approach will be similar to that used at the end of the Chapter 8 notes for the multi-dimensional array. The data for this application are given in the following table. Do not store the header row (Brand A, Brand C, etc) in the table as this is not part of the data.
I was able to create the table and set up the form part. But I can't actually figure out what code I'm suppose to use to make it execute properly. I've tried different methods and I just don't know how to call the index number and make the proper part show up in the VBAuto box!
HELP?!
Thank you for any and all help in advance!
3 answers
"I've tried different methods and I just don't know how to call the index number and make the proper part show up in the VBAuto box!"
If you post what you've tried, we can help you get on the right track. Without seeing your attempts, we don't know where you've got a problem.
Alternatively, you can tell us the symptoms, and we'll help you find the right direction.
Public SparkPlugsString(,) As String = {{"VBAutoPart", "Brand A", "Brand C", "Brand X"},
{"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"}}
Private Property VerticalPrintLocationSingle As Object
Public Sub LookupButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LookupButton.Click
Dim PartIndexInteger As Integer
Dim BrandIndexInteger As Integer
BrandIndexInteger = BrandBox.SelectedIndex
PartIndexInteger = PartBox.SelectedIndex
If PartIndexInteger <> -1 And BrandIndexInteger <> -1 Then
VBAutoTextBox.Text =
SparkPlugsString(PartIndexInteger, BrandIndexInteger).ToString("")
Else
MessageBox.Show("Select the Part and Brand.", "Information Missing", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
End If
End Sub
End Class
This is pretty much what I have.. But I just can't figure it out :-/
I'm a pretty big beginner at this... I tried looking up tutorials (thank you very much for that by the way) and couldn't find what I was looking for...
You will need to search the table for the competitive part number, if there is a match, you will display your own brand's part number. That's the idea.
In practice, you need a for loop to go through all the parts until you find the competitive part number. Then return your own brand.
In more sophisticated systems, the search will not be a sequential search, but more like a binary search on a sorted list or index. For now, with less than 500 parts, efficiency is not a problem.
You must have learned about sequential search and multi-dimensional arrays.
Give it a try, and post what you have. Your current code shows the search of only one item, without searching through the who array. So perhaps you might even have syntax error.