array help

Please help me understand how arrays work.

Page 1 of 1

7 Replies - 1374 Views - Last Post: 14 April 2009 - 09:39 AM Rate Topic: -----

#1 funclown1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 26-March 09

array help

Posted 26 March 2009 - 10:49 AM

My teachers gave me a worksheet on 2d arrays, but he never explained as to how 2d arrays work. I am not asking for the coding or anything related to the project. I am just wondering if you could simply help me understand how arrays work. I will put the discription of the program below along with a copy of the table i had to recreate.


Crate an application that will allow the user to select a manufacturer and vehicle type using combo box or list box controls and will get and display a vehicle model from a two-dimensional string array based on the user’s input. Use the table below to create the two-dimensional array. (The shaded columns are headings only and are used in the combo or list boxes. The data for the array is not shaded.)

Attached File(s)



Is This A Good Question/Topic? 0
  • +

#3 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2262
  • View blog
  • Posts: 9,466
  • Joined: 29-May 08

Re: array help

Posted 26 March 2009 - 11:31 AM

Arrray Tutorial
Was This Post Helpful? 1
  • +
  • -

#4 funclown1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 26-March 09

Re: array help

Posted 27 March 2009 - 08:26 AM

Thank you, AdamSpeight2008, I really appreciate the help. You are a cool guy. Really thank you so much...it helps a lot.
Was This Post Helpful? 0
  • +
  • -

#5 funclown1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 26-March 09

Re: array help

Posted 06 April 2009 - 10:45 AM

okay this is what i have so far... but i keep getting an error.

Public Class Form1
	Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

	Public Sub New()
		MyBase.New()

		'This call is required by the Windows Form Designer.
		InitializeComponent()

		'Add any initialization after the InitializeComponent() call

	End Sub

	'Form overrides dispose to clean up the component list.
	Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
		If disposing Then
			If Not (components Is Nothing) Then
				components.Dispose()
			End If
		End If
		MyBase.Dispose(disposing)
	End Sub

	'Required by the Windows Form Designer
	Private components As System.ComponentModel.IContainer

	'NOTE: The following procedure is required by the Windows Form Designer
	'It can be modified using the Windows Form Designer.  
	'Do not modify it using the code editor.
	Friend WithEvents btnQuit As System.Windows.Forms.Button
	Friend WithEvents btnSM As System.Windows.Forms.Button
	Friend WithEvents cboManufacturer As System.Windows.Forms.ComboBox
	Friend WithEvents cboVType As System.Windows.Forms.ComboBox
	<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
		Me.cboManufacturer = New System.Windows.Forms.ComboBox
		Me.btnQuit = New System.Windows.Forms.Button
		Me.btnSM = New System.Windows.Forms.Button
		Me.cboVType = New System.Windows.Forms.ComboBox
		Me.SuspendLayout()
		'
		'cboManufacturer
		'
		Me.cboManufacturer.Items.AddRange(New Object() {"Ford", "Chevy", "Honda", "Dodge"})
		Me.cboManufacturer.Location = New System.Drawing.Point(16, 24)
		Me.cboManufacturer.Name = "cboManufacturer"
		Me.cboManufacturer.Size = New System.Drawing.Size(120, 21)
		Me.cboManufacturer.TabIndex = 0
		Me.cboManufacturer.Text = "Select Manufacturer"
		'
		'btnQuit
		'
		Me.btnQuit.Location = New System.Drawing.Point(208, 232)
		Me.btnQuit.Name = "btnQuit"
		Me.btnQuit.TabIndex = 2
		Me.btnQuit.Text = "Quit"
		'
		'btnSM
		'
		Me.btnSM.Location = New System.Drawing.Point(16, 224)
		Me.btnSM.Name = "btnSM"
		Me.btnSM.TabIndex = 3
		Me.btnSM.Text = "Show Model"
		'
		'cboVType
		'
		Me.cboVType.Items.AddRange(New Object() {"Sedan", "Coupe", "Truck", "Van", "Suv"})
		Me.cboVType.Location = New System.Drawing.Point(160, 24)
		Me.cboVType.Name = "cboVType"
		Me.cboVType.Size = New System.Drawing.Size(120, 21)
		Me.cboVType.TabIndex = 4
		Me.cboVType.Text = "Select Model Type"
		'
		'Form1
		'
		Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
		Me.ClientSize = New System.Drawing.Size(292, 266)
		Me.Controls.Add(Me.cboVType)
		Me.Controls.Add(Me.btnSM)
		Me.Controls.Add(Me.btnQuit)
		Me.Controls.Add(Me.cboManufacturer)
		Me.Name = "Form1"
		Me.Text = "Form1"
		Me.ResumeLayout(False)

	End Sub

#End Region
	Dim Manufacturer() As String 
	Dim VType(,) As String
	Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboManufacturer.SelectedIndexChanged
		Manufacturer(0) = cboManufacturer.SelectedIndex.Equals(0)

		Manufacturer(1) = cboManufacturer.SelectedIndex.Equals(1)

		Manufacturer(2) = cboManufacturer.SelectedIndex.Equals(2)

		Manufacturer(3) = cboManufacturer.SelectedIndex.Equals(3)



	End Sub

	Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click
		Close()
	End Sub

	Private Sub btnSM_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSM.Click


	End Sub


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

	End Sub

	Private Sub cboVType_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboVType.SelectedIndexChanged
		VType(0, C) = cboVType.SelectedIndex.Equals(0)
		VType(1, 0) = cboVType.SelectedIndex.Equals(1)
		VType(2, 0) = cboVType.SelectedIndex.Equals(2)
		VType(3, 0) = cboVType.SelectedIndex.Equals(3)
		VType(4, 0) = cboVType.SelectedIndex.Equals(5)
	End Sub
End Class



Was This Post Helpful? 0
  • +
  • -

#6 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: array help

Posted 06 April 2009 - 10:54 AM

What error are you getting? That would be a great starting point :)
Was This Post Helpful? 0
  • +
  • -

#7 funclown1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 26-March 09

Re: array help

Posted 06 April 2009 - 10:59 AM

Sorry about that...the error says,

An unhandled exception of type 'System.NullReferenceException' occurred in Array Worksheet Application.exe

Additional information: Object reference not set to an instance of an object.
Was This Post Helpful? 0
  • +
  • -

#8 prabh  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 3
  • View blog
  • Posts: 381
  • Joined: 27-December 08

Re: array help

Posted 06 April 2009 - 11:38 AM

View Postfunclown1, on 6 Apr, 2009 - 09:59 AM, said:

Sorry about that...the error says,

An unhandled exception of type 'System.NullReferenceException' occurred in Array Worksheet Application.exe

Additional information: Object reference not set to an instance of an object.

the place where you declare array also declare its size for example of 2d array
dim myarray(3)(3) as array

sorry i answered it without reading your code
but will work for this error
Was This Post Helpful? 0
  • +
  • -

#9 funclown1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 26-March 09

Re: array help

Posted 14 April 2009 - 09:39 AM

ok ive got most of it to work...i just cant get it to switch from 1 type of car picture to another...here is my code so far. I also added in the pictures in using so far.

:^:
Public Class Form1
	Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

	Public Sub New()
		MyBase.New()

		'This call is required by the Windows Form Designer.
		InitializeComponent()

		'Add any initialization after the InitializeComponent() call

	End Sub

	'Form overrides dispose to clean up the component list.
	Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
		If disposing Then
			If Not (components Is Nothing) Then
				components.Dispose()
			End If
		End If
		MyBase.Dispose(disposing)
	End Sub

	'Required by the Windows Form Designer
	Private components As System.ComponentModel.IContainer

	'NOTE: The following procedure is required by the Windows Form Designer
	'It can be modified using the Windows Form Designer.  
	'Do not modify it using the code editor.
	Friend WithEvents btnQuit As System.Windows.Forms.Button
	Friend WithEvents btnSM As System.Windows.Forms.Button
	Friend WithEvents cboManufacturer As System.Windows.Forms.ComboBox
	Friend WithEvents cboVType As System.Windows.Forms.ComboBox
	Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
	Friend WithEvents Label1 As System.Windows.Forms.Label
	<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
		Me.cboManufacturer = New System.Windows.Forms.ComboBox
		Me.btnQuit = New System.Windows.Forms.Button
		Me.btnSM = New System.Windows.Forms.Button
		Me.cboVType = New System.Windows.Forms.ComboBox
		Me.PictureBox1 = New System.Windows.Forms.PictureBox
		Me.Label1 = New System.Windows.Forms.Label
		Me.SuspendLayout()
		'
		'cboManufacturer
		'
		Me.cboManufacturer.Items.AddRange(New Object() {"Ford", "Chevy", "Honda", "Dodge"})
		Me.cboManufacturer.Location = New System.Drawing.Point(16, 24)
		Me.cboManufacturer.Name = "cboManufacturer"
		Me.cboManufacturer.Size = New System.Drawing.Size(120, 21)
		Me.cboManufacturer.TabIndex = 0
		Me.cboManufacturer.Text = "Select Manufacturer"
		'
		'btnQuit
		'
		Me.btnQuit.Location = New System.Drawing.Point(112, 224)
		Me.btnQuit.Name = "btnQuit"
		Me.btnQuit.TabIndex = 2
		Me.btnQuit.Text = "Quit"
		'
		'btnSM
		'
		Me.btnSM.Location = New System.Drawing.Point(16, 224)
		Me.btnSM.Name = "btnSM"
		Me.btnSM.TabIndex = 3
		Me.btnSM.Text = "Show Model"
		'
		'cboVType
		'
		Me.cboVType.Items.AddRange(New Object() {"Sedan", "Coupe", "Truck", "Van", "SUV"})
		Me.cboVType.Location = New System.Drawing.Point(160, 24)
		Me.cboVType.Name = "cboVType"
		Me.cboVType.Size = New System.Drawing.Size(120, 21)
		Me.cboVType.TabIndex = 4
		Me.cboVType.Text = "Select Model Type"
		'
		'PictureBox1
		'
		Me.PictureBox1.Location = New System.Drawing.Point(328, 16)
		Me.PictureBox1.Name = "PictureBox1"
		Me.PictureBox1.Size = New System.Drawing.Size(432, 216)
		Me.PictureBox1.TabIndex = 5
		Me.PictureBox1.TabStop = False
		'
		'Label1
		'
		Me.Label1.Font = New System.Drawing.Font("Times New Roman", 18.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
		Me.Label1.Location = New System.Drawing.Point(448, 256)
		Me.Label1.Name = "Label1"
		Me.Label1.Size = New System.Drawing.Size(184, 88)
		Me.Label1.TabIndex = 6
		Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
		'
		'Form1
		'
		Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
		Me.ClientSize = New System.Drawing.Size(768, 454)
		Me.Controls.Add(Me.Label1)
		Me.Controls.Add(Me.PictureBox1)
		Me.Controls.Add(Me.cboVType)
		Me.Controls.Add(Me.btnSM)
		Me.Controls.Add(Me.btnQuit)
		Me.Controls.Add(Me.cboManufacturer)
		Me.Name = "Form1"
		Me.Text = "Form1"
		Me.ResumeLayout(False)

	End Sub

#End Region
	Dim Manufacturer(3) As String
	Dim VType(4, 0) As String

	Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboManufacturer.SelectedIndexChanged
		Manufacturer(0) = cboManufacturer.SelectedIndex
		Manufacturer(1) = cboManufacturer.SelectedIndex
		Manufacturer(2) = cboManufacturer.SelectedIndex
		Manufacturer(3) = cboManufacturer.SelectedIndex

	End Sub

	Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click
		Close()
	End Sub

	Private Sub btnSM_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSM.Click

		If cboManufacturer.SelectedIndex = Manufacturer(0) And cboVType.SelectedIndex = VType(0, 0) Then
			PictureBox1.Enabled = True
			PictureBox1.Image = System.Drawing.Image.FromFile _
	  ("H:\Chart's VB Projects\Sem. 2\Chapter 7\Array Worksheet Application\bin\ford_taurus_sedan.jpg")
			Label1.Text = "Taurus"
		ElseIf cboManufacturer.SelectedIndex = Manufacturer(0) And cboVType.SelectedIndex = VType(1, 0) Then
			PictureBox1.Enabled = True
			PictureBox1.Image = System.Drawing.Image.FromFile _
	  ("H:\Chart's VB Projects\Sem. 2\Chapter 7\Array Worksheet Application\bin\ford-Mustang_Coupe.jpg")
			Label1.Text = "Mustang"
		ElseIf cboManufacturer.SelectedIndex = Manufacturer(0) And cboVType.SelectedIndex = VType(2, 0) Then
				PictureBox1.Enabled = True
				PictureBox1.Image = System.Drawing.Image.FromFile _
		  ("H:\Chart's VB Projects\Sem. 2\Chapter 7\Array Worksheet Application\bin\Ford-F-150_Truck.jpg")
				Label1.Text = "F-150"
			End If

			If cboManufacturer.SelectedIndex = Manufacturer(0) And cboVType.SelectedIndex = VType(3, 0) Then
				PictureBox1.Enabled = True
				PictureBox1.Image = System.Drawing.Image.FromFile _
		  ("H:\Chart's VB Projects\Sem. 2\Chapter 7\Array Worksheet Application\bin\Ford-Freestar_Van.jpg")
				Label1.Text = "Freestar"
			ElseIf cboManufacturer.SelectedIndex = Manufacturer(1) And cboVType.SelectedIndex = VType(4, 0) Then
				PictureBox1.Enabled = True
				PictureBox1.Image = System.Drawing.Image.FromFile _
		  ("H:\Chart's VB Projects\Sem. 2\Chapter 7\Array Worksheet Application\bin\Ford-Explorer_SUV.jpg")
				Label1.Text = "Explorer"
			End If

			'	 End If
			'		End If
			'	End If
			'End If
			' next manufacturer

			'  If cboManufacturer.SelectedIndex = Manufacturer(0, 1) And cboVType.SelectedIndex = VType(0, 0) Then
			'	  PictureBox1.Enabled = True
			'	  PictureBox1.Image = System.Drawing.Image.FromFile _
			'("H:\Chart's VB Projects\Sem. 2\Chapter 7\Array Worksheet Application\bin\ford_taurus_sedan.jpg")
			'	  Label1.Text = "Taurus"
			'  End If

			'  If cboManufacturer.SelectedIndex = Manufacturer(0, 1) And cboVType.SelectedIndex = VType(1, 0) Then
			'	  PictureBox1.Enabled = True
			'	  PictureBox1.Image = System.Drawing.Image.FromFile _
			'("H:\Chart's VB Projects\Sem. 2\Chapter 7\Array Worksheet Application\bin\ford-Mustang_Coupe.jpg")
			'	  Label1.Text = "Mustang"
			'  End If

			'  If cboManufacturer.SelectedIndex = Manufacturer(0, 1) And cboVType.SelectedIndex = VType(2, 0) Then
			'	  PictureBox1.Enabled = True
			'	  PictureBox1.Image = System.Drawing.Image.FromFile _
			'("H:\Chart's VB Projects\Sem. 2\Chapter 7\Array Worksheet Application\bin\Ford-F-150_Truck.jpg")
			'	  Label1.Text = "F-150"
			'  End If

			'  If cboManufacturer.SelectedIndex = Manufacturer(0, 1) And cboVType.SelectedIndex = VType(3, 0) Then
			'	  PictureBox1.Enabled = True
			'	  PictureBox1.Image = System.Drawing.Image.FromFile _
			'("H:\Chart's VB Projects\Sem. 2\Chapter 7\Array Worksheet Application\bin\Ford-Freestar_Van.jpg")
			'	  Label1.Text = "Freestar"
			'  End If

			'  If cboManufacturer.SelectedIndex = Manufacturer(0, 1) And cboVType.SelectedIndex = VType(4, 0) Then
			'	  PictureBox1.Enabled = True
			'	  PictureBox1.Image = System.Drawing.Image.FromFile _
			'("H:\Chart's VB Projects\Sem. 2\Chapter 7\Array Worksheet Application\bin\Ford-Explorer_SUV.jpg")
			'	  Label1.Text = "Explorer"
			'  End If


	End Sub


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

	End Sub

	Private Sub cboVType_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboVType.SelectedIndexChanged
		VType(0, 0) = cboVType.SelectedIndex
		VType(1, 0) = cboVType.SelectedIndex
		VType(2, 0) = cboVType.SelectedIndex
		VType(3, 0) = cboVType.SelectedIndex
		VType(4, 0) = cboVType.SelectedIndex
	End Sub
End Class

Attached image(s)

  • Attached Image
  • Attached Image
  • Attached Image
  • Attached Image
  • Attached Image
  • Attached Image

This post has been edited by funclown1: 14 April 2009 - 09:40 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1