4 Replies - 3293 Views - Last Post: 03 December 2009 - 01:42 PM Rate Topic: -----

#1 Braber01  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 247
  • Joined: 29-November 08

Four Columns of data in a 2d Array or Structure Array?

Posted 02 December 2009 - 09:40 AM

Hey Here's the data I'm trying to work with
Spark Plugs
column 1: PR214,PR223,PR224,PR246,PR247,PR248,PR324,PR326,PR444
Brands:
column 2: MR43T,R43,R43N,R46N,R46TS,R46TX,S46,SR46E,47L
column 3: RBL8,RJ6,RN4,RN8,RBL17Y,RBL12-6,J11,XEJ8,H12
column 4L 14K22,14K24,14K30,14K32,14K33,14K35,14K38,14K40,14K44

Here is what i came up with for my code so far

Public Class frmMain
Private strSpark() As String = {"PR214","PR223","PR224","PR246","PR247","PR248","PR324", "PR326","PR444"}

Private strBrands As String(,) = { { } }
End Class


This post has been edited by Braber01: 02 December 2009 - 09:41 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Four Columns of data in a 2d Array or Structure Array?

#2 crepitus  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 85
  • View blog
  • Posts: 383
  • Joined: 08-September 09

Re: Four Columns of data in a 2d Array or Structure Array?

Posted 02 December 2009 - 10:16 AM

You want to think about what would go in one row. Presumably each row has details of one particular spark plug, and the product codes of various brands of that plug. You can create a structure or class to represent a row. You then just need a 1D collection of instances of that class.

Simple classes like this occur all the time. They are very simple to write, especially with code snippets (type in prop, tab, tab and you have a property...)

Public Class SparkPlugInfo

	Private m_name As String
	Public Property Name() As String
		Get
			Return m_name
		End Get
		Set(ByVal value As String)
			m_name = value
		End Set
	End Property

	Private m_brandA As String
	Public Property BrandA() As String
		Get
			Return m_brandA
		End Get
		Set(ByVal value As String)
			m_brandA = value
		End Set
	End Property

	Private m_brandB As String
	Public Property BrandB() As String
		Get
			Return m_brandB
		End Get
		Set(ByVal value As String)
			m_brandB = value
		End Set
	End Property

	Private m_brandC As String
	Public Property BrandC() As String
		Get
			Return m_brandC
		End Get
		Set(ByVal value As String)
			m_brandC = value
		End Set
	End Property

	Public Sub New(ByVal name As String, ByVal brandA As String, ByVal brandB As String, ByVal brandC As String)
		m_name = name
		m_brandA = brandA
		m_brandB = brandB
		m_brandC = brandC
	End Sub

End Class


You can then simply store them in a List(Of SparkPlug)

Public Class Form1

	Friend lv As New ListView With {.Dock = DockStyle.Fill, .View = View.Details}

	Sub New()
		InitializeComponent()
		' You can use the ide for the listview, this is
		' just so you can copy and paste to try it out.
		lv.Columns.Add("Name")
		lv.Columns.Add("BrandA")
		lv.Columns.Add("BrandB")
		lv.Columns.Add("BrandC")
		Me.Controls.Add(lv)
	End Sub

	Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
		' So here's a 1D collection of SparkPlugInfo which can hold all the information.
		Dim plugs As New List(Of SparkPlugInfo)
		' I'm going to create some with random strings for the data.
		For i As Integer = 1 To 10
			plugs.Add(New SparkPlugInfo(IO.Path.GetRandomFileName, IO.Path.GetRandomFileName, IO.Path.GetRandomFileName, IO.Path.GetRandomFileName))
		Next
		' Linq to make some listviewitems.
		Dim lvis = From plug In plugs Select New ListViewItem(New String() {plug.Name, plug.BrandA, plug.BrandB, plug.BrandC})
		lv.Items.AddRange(lvis.ToArray)
	End Sub

End Class

This post has been edited by crepitus: 03 December 2009 - 06:47 PM

Was This Post Helpful? 0
  • +
  • -

#3 Braber01  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 247
  • Joined: 29-November 08

Re: Four Columns of data in a 2d Array or Structure Array?

Posted 02 December 2009 - 10:32 AM

Thanks but that wasn't really my assgnment my assignment was to create an application that a user should be able to enter a part and a brand and create a table lookup . here is the acual text from the case study textbook

VB Auto Sells its own brand of spark plugs. To Cross-refance to major brands, it keeps a table of equivalent part numbers. Vb Auto wants to Coumputerize the process of looking up part numbers in oerder to improve it's customer servace. The user should be able to enter the part number and the brand and look up the corresponding VBauto part number you may allo the user to select the brand ( Brand A, Brand C, or Brand X) form a List or from radio Buttons. You can shoose from two approches for the lookup table, Store the part numbers either in a 2 dimensional table or in an array of a structure. In eather case use the part number and brand enterd by the user; look up and display the vb Auto part number
Was This Post Helpful? 0
  • +
  • -

#4 Braber01  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 247
  • Joined: 29-November 08

Re: Four Columns of data in a 2d Array or Structure Array?

Posted 03 December 2009 - 12:14 PM

but I wanna Thank you for Teaching me how to Add a Control to a From via Code rather than drag and drop
Was This Post Helpful? 0
  • +
  • -

#5 Braber01  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 247
  • Joined: 29-November 08

Re: Four Columns of data in a 2d Array or Structure Array?

Posted 03 December 2009 - 01:42 PM

BREAKTHROUGH!!!! I have figured it out all by my self I feel really really really proud of my self plus I find 2D Arrays Confusing
here is what i came up with
Private sparkPlugs(,) As String = {{"VB Auto", "Brand A", "Brand C", "Brand X"}, _
									   {"PR214", "MR43T", "RBL8", "14K22"}, _
									   {"PR223", "R43", "RJ6", "14K24"}, _
									   {"PR224", "R43N", "RN4", "14K30"}, _
									   {"PR346", "R46N", "RN8", "14K32"}, _
									   {"PR247", "R4TS", "RBL17Y", "14K33"}, _
									   {"PR248", "R46TX", "RBL12-6", "14K35"}, _
									   {"PR324", "S46", "J11", "14K38"}, _
									   {"PR326", "SR46E", "XEJ6", "14K40"}, _
									   {"PR444", "47L", "H12", "14K44"}}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1