Structure statement

Application displays both name and price to the product ID entered by

Page 1 of 1

12 Replies - 930 Views - Last Post: 21 July 2008 - 11:41 AM Rate Topic: -----

#1 LadyWolf  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 197
  • Joined: 25-June 08

Structure statement

Post icon  Posted 20 July 2008 - 09:47 AM

Think I'm on the right track, not sure. Working on getting the 'name' to appear when display button is clicked. Here's the code I have at the moment:


Option Explicit On
Option Strict On

Public Class MainForm

	Structure Item
		Public id As String
		Public price As Integer
		Public name As String

	End Structure


	Private Sub xExitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xExitButton.Click
		Me.Close()
	End Sub

	Private Sub xIdTextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles xIdTextBox.Enter
		Me.xIdTextBox.SelectAll()
	End Sub

	Private Sub xIdTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles xIdTextBox.TextChanged
		Me.xPriceLabel.Text = String.Empty
	End Sub


	Private Sub xDisplayButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xDisplayButton.Click
		'displays the price and name associated with the
		'product ID entered by the user

		Dim searchFor As String
		Dim subscript As Integer
		Dim name As String

		'declare an array of structure variables

		Dim gifts(4) As Item

		'assign product IDs, prices, and name to the array

		gifts(0).id = "BX35"
		gifts(0).price = 13
		gifts(0).name = "Necklace"
		gifts(1).id = "CR20"
		gifts(1).price = 10
		gifts(1).name = "Bracelet"
		gifts(2).id = "FE15"
		gifts(2).price = 12
		gifts(2).name = "Jewelry box"
		gifts(3).id = "KW10"
		gifts(3).price = 24
		gifts(3).name = "Doll"
		gifts(4).id = "MM67"
		gifts(4).price = 4
		gifts(4).name = "Ring"

		'assigns the product ID to a variable 
		searchFor = Me.xIdTextBox.Text

		'search the ids array for the product ID
		'continue searching until there are
		'no more array elements to search or
		'the product ID is found

		Do Until subscript = gifts.Length _
			OrElse searchFor = gifts(subscript).id
			subscript = subscript + 1

		Loop

		'determine whether the product ID
		'was found in the ids array

		If subscript < gifts.Length Then

			Me.xPriceLabel.Text = _
			gifts(subscript).price.ToString("C0")

		Else

			MessageBox.Show("Invalid product ID", _
			"Treasures Gift Shop", _
			MessageBoxButtons.OK, _
			MessageBoxIcon.Information)

		End If

	End Sub

	Private Sub xNameLabel_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles xNameLabel.TextChanged
		Me.xNameLabel.Text = String.Empty
	End Sub
End Class



Is This A Good Question/Topic? 0
  • +

Replies To: Structure statement

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4332
  • View blog
  • Posts: 12,127
  • Joined: 18-April 07

Re: Structure statement

Posted 20 July 2008 - 10:28 AM

Yeah so far so good. The only recommendation I have is that in your structure that you make price a double or decimal instead of an integer. After all, prices have cent values.

Just remember that once you locate your item, all you will need is to reference the array's subscript for that item and go ".name" to display it.

MessageBox.Show("Name is: " & display(1).name)

'or

TextBox1.Text = display(1).name



I am going to assume you will automate some of this later when it comes to creating objects for your array. Instead of manually loading data have the user enter data or read in from the file. Can you imagine doing hard code for thousands of items?

Anyways, good job. :^:
Was This Post Helpful? 1
  • +
  • -

#3 LadyWolf  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 197
  • Joined: 25-June 08

Re: Structure statement

Posted 20 July 2008 - 01:48 PM

:D Thanks for the thumbs up. Not sure I understand the advice your giving though, but I'll try to work it how I think you mean :) Thank-You
Was This Post Helpful? 0
  • +
  • -

#4 LadyWolf  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 197
  • Joined: 25-June 08

Re: Structure statement

Posted 20 July 2008 - 05:39 PM

mmmmmmm Still working this, I'm back to the code from earlier again, but here's a screenshot of the interface...

Attached File(s)

  • Attached File  Doc1.doc (117.5K)
    Number of downloads: 42

Was This Post Helpful? 0
  • +
  • -

#5 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2251
  • View blog
  • Posts: 9,435
  • Joined: 29-May 08

Re: Structure statement

Posted 20 July 2008 - 06:11 PM


Option Explicit On
Option Strict On

Public Class MainForm

	Structure Item
		Public id As String
		Public price As Integer
		Public name As String

	End Structure


	Private Sub xExitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xExitButton.Click
		Me.Close()
	End Sub

	Private Sub xIdTextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles xIdTextBox.Enter
		Me.xIdTextBox.SelectAll()
	End Sub

	Private Sub xIdTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles xIdTextBox.TextChanged
		Me.xPriceLabel.Text = String.Empty
	End Sub


	Private Sub xDisplayButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xDisplayButton.Click
		'displays the price and name associated with the
		'product ID entered by the user

		Dim searchFor As String
		Dim subscript As Integer
		Dim name As String

		'declare an array of structure variables

		Dim gifts(4) As Item

		'assign product IDs, prices, and name to the array

		gifts(0).id = "BX35"
		gifts(0).price = 13
		gifts(0).name = "Necklace"
		gifts(1).id = "CR20"
		gifts(1).price = 10
		gifts(1).name = "Bracelet"
		gifts(2).id = "FE15"
		gifts(2).price = 12
		gifts(2).name = "Jewelry box"
		gifts(3).id = "KW10"
		gifts(3).price = 24
		gifts(3).name = "Doll"
		gifts(4).id = "MM67"
		gifts(4).price = 4
		gifts(4).name = "Ring"

		'assigns the product ID to a variable 
		searchFor = Me.xIdTextBox.Text

		'search the ids array for the product ID
		'continue searching until there are
		'no more array elements to search or
		'the product ID is found

		Do Until subscript = gifts.Length _
			OrElse searchFor = gifts(subscript).id
			subscript = subscript + 1

		Loop

		'determine whether the product ID
		'was found in the ids array

		If subscript < gifts.Length Then

			Me.xPriceLabel.Text = gifts(subscript).price.ToString("C0")
Me.xPriceLabel.Text = gifts(subscript).name '<- inserted line
		Else

			MessageBox.Show("Invalid product ID", _
			"Treasures Gift Shop", _
			MessageBoxButtons.OK, _
			MessageBoxIcon.Information)

		End If

	End Sub

	Private Sub xNameLabel_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles xNameLabel.TextChanged
		Me.xNameLabel.Text = String.Empty
	End Sub
End Class


This post has been edited by AdamSpeight2008: 20 July 2008 - 06:12 PM

Was This Post Helpful? 1
  • +
  • -

#6 LadyWolf  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 197
  • Joined: 25-June 08

Re: Structure statement

Posted 20 July 2008 - 06:18 PM

View PostAdamSpeight2008, on 20 Jul, 2008 - 09:11 PM, said:


Option Explicit On
Option Strict On

Public Class MainForm

	Structure Item
		Public id As String
		Public price As Integer
		Public name As String

	End Structure


	Private Sub xExitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xExitButton.Click
		Me.Close()
	End Sub

	Private Sub xIdTextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles xIdTextBox.Enter
		Me.xIdTextBox.SelectAll()
	End Sub

	Private Sub xIdTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles xIdTextBox.TextChanged
		Me.xPriceLabel.Text = String.Empty
	End Sub


	Private Sub xDisplayButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xDisplayButton.Click
		'displays the price and name associated with the
		'product ID entered by the user

		Dim searchFor As String
		Dim subscript As Integer
		Dim name As String

		'declare an array of structure variables

		Dim gifts(4) As Item

		'assign product IDs, prices, and name to the array

		gifts(0).id = "BX35"
		gifts(0).price = 13
		gifts(0).name = "Necklace"
		gifts(1).id = "CR20"
		gifts(1).price = 10
		gifts(1).name = "Bracelet"
		gifts(2).id = "FE15"
		gifts(2).price = 12
		gifts(2).name = "Jewelry box"
		gifts(3).id = "KW10"
		gifts(3).price = 24
		gifts(3).name = "Doll"
		gifts(4).id = "MM67"
		gifts(4).price = 4
		gifts(4).name = "Ring"

		'assigns the product ID to a variable 
		searchFor = Me.xIdTextBox.Text

		'search the ids array for the product ID
		'continue searching until there are
		'no more array elements to search or
		'the product ID is found

		Do Until subscript = gifts.Length _
			OrElse searchFor = gifts(subscript).id
			subscript = subscript + 1

		Loop

		'determine whether the product ID
		'was found in the ids array

		If subscript < gifts.Length Then

			Me.xPriceLabel.Text = gifts(subscript).price.ToString("C0")
Me.xPriceLabel.Text = gifts(subscript).name '<- inserted line
		Else

			MessageBox.Show("Invalid product ID", _
			"Treasures Gift Shop", _
			MessageBoxButtons.OK, _
			MessageBoxIcon.Information)

		End If

	End Sub

	Private Sub xNameLabel_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles xNameLabel.TextChanged
		Me.xNameLabel.Text = String.Empty
	End Sub
End Class




mmmmmm lol sorta Now the name 'Necklace showed up in the price text box....I did that a few times now :blink:
Was This Post Helpful? 0
  • +
  • -

#7 LadyWolf  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 197
  • Joined: 25-June 08

Re: Structure statement

Posted 20 July 2008 - 06:32 PM


Option Explicit On
Option Strict On

Public Class MainForm

	Structure Item
		Public id As String
		Public price As Integer
		Public name As String

	End Structure


	Private Sub xExitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xExitButton.Click
		Me.Close()
	End Sub

	Private Sub xIdTextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles xIdTextBox.Enter
		Me.xIdTextBox.SelectAll()
	End Sub

	Private Sub xIdTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles xIdTextBox.TextChanged
		Me.xPriceLabel.Text = String.Empty
	End Sub


	Private Sub xDisplayButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xDisplayButton.Click
		'displays the price and name associated with the
		'product ID entered by the user

		Dim searchFor As String
		Dim subscript As Integer
		Dim name As String

		'declare an array of structure variables

		Dim gifts(4) As Item

		'assign product IDs, prices, and name to the array

		gifts(0).id = "BX35"
		gifts(0).price = 13
		gifts(0).name = "Necklace"
		gifts(1).id = "CR20"
		gifts(1).price = 10
		gifts(1).name = "Bracelet"
		gifts(2).id = "FE15"
		gifts(2).price = 12
		gifts(2).name = "Jewelry box"
		gifts(3).id = "KW10"
		gifts(3).price = 24
		gifts(3).name = "Doll"
		gifts(4).id = "MM67"
		gifts(4).price = 4
		gifts(4).name = "Ring"

		'assigns the product ID to a variable 
		searchFor = Me.xIdTextBox.Text

		'search the ids array for the product ID
		'continue searching until there are
		'no more array elements to search or
		'the product ID is found

		Do Until subscript = gifts.Length _
			OrElse searchFor = gifts(subscript).id
			subscript = subscript + 1

		Loop

		'determine whether the product ID
		'was found in the ids array

		If subscript < gifts.Length Then

			Me.xPriceLabel.Text = _
			gifts(subscript).price.ToString("C0")
			Me.xNameLabel.Text = gifts(subscript).name<---This is the right name for the label 

		Else

			MessageBox.Show("Invalid product ID", _
			"Treasures Gift Shop", _
			MessageBoxButtons.OK, _
			MessageBoxIcon.Information)

		End If

	End Sub

	Private Sub xNameLabel_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles xNameLabel.TextChanged
		Me.xNameLabel.Text = String.Empty
	End Sub
End Class


This post has been edited by LadyWolf: 20 July 2008 - 06:33 PM

Was This Post Helpful? 0
  • +
  • -

#8 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2251
  • View blog
  • Posts: 9,435
  • Joined: 29-May 08

Re: Structure statement

Posted 20 July 2008 - 06:40 PM

Doh!
Was This Post Helpful? 0
  • +
  • -

#9 LadyWolf  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 197
  • Joined: 25-June 08

Re: Structure statement

Posted 20 July 2008 - 06:45 PM

View PostAdamSpeight2008, on 20 Jul, 2008 - 09:40 PM, said:

Doh!


:wub: I'm getting tired, so I hope I didn't misunderstand you or offend you in some way..If I did, I'm sorry, that was not my intentions

This post has been edited by LadyWolf: 20 July 2008 - 08:10 PM

Was This Post Helpful? 0
  • +
  • -

#10 LadyWolf  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 197
  • Joined: 25-June 08

Re: Structure statement

Posted 20 July 2008 - 08:14 PM

Guess I'm getting too tired, and I'm getting frustrated. Here's the code I have now:


Option Explicit On
Option Strict On

Public Class MainForm

	Structure Item
		Public id As String
		Public price As Integer
		Public name As String

	End Structure


	Private Sub xExitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xExitButton.Click
		Me.Close()
	End Sub

	Private Sub xIdTextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles xIdTextBox.Enter
		Me.xIdTextBox.SelectAll()
	End Sub

	Private Sub xIdTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles xIdTextBox.TextChanged
		Me.xPriceLabel.Text = String.Empty
	End Sub


	Private Sub xDisplayButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xDisplayButton.Click
		'displays the price and name associated with the
		'product ID entered by the user

		Dim searchFor As String
		Dim subscript As Integer
		Dim name As String

		'declare an array of structure variables

		Dim gifts(4) As Item

		'assign product IDs, prices, and name to the array

		gifts(0).id = "BX35"
		gifts(0).price = 13
		gifts(0).name = "Necklace"
		gifts(1).id = "CR20"
		gifts(1).price = 10
		gifts(1).name = "Bracelet"
		gifts(2).id = "FE15"
		gifts(2).price = 12
		gifts(2).name = "Jewelry box"
		gifts(3).id = "KW10"
		gifts(3).price = 24
		gifts(3).name = "Doll"
		gifts(4).id = "MM67"
		gifts(4).price = 4
		gifts(4).name = "Ring"

		'assigns the product ID to a variable 
		searchFor = Me.xIdTextBox.Text

		'assigns name of product to a variable
		name = Me.xNameLabel.Text

		'search the ids array for the product ID
		'continue searching until there are
		'no more array elements to search or
		'the product ID is found

		Do Until subscript = gifts.Length _
			OrElse searchFor = gifts(subscript).id
			subscript = subscript + 1

		Loop

		'determine whether the product ID
		'was found in the ids array

		If subscript < gifts.Length Then

			Me.xPriceLabel.Text = _
			gifts(subscript).price.ToString("C0")
			Me.xNameLabel.Text = gifts(subscript).name<--This isn't working...

		Else

			MessageBox.Show("Invalid product ID", _
			"Treasures Gift Shop", _
			MessageBoxButtons.OK, _
			MessageBoxIcon.Information)

		End If

	End Sub

	Private Sub xNameLabel_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles xNameLabel.TextChanged
		Me.xNameLabel.Text = String.Empty
	End Sub
End Class


This post has been edited by LadyWolf: 20 July 2008 - 08:16 PM

Was This Post Helpful? 0
  • +
  • -

#11 LadyWolf  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 197
  • Joined: 25-June 08

Re: Structure statement

Posted 21 July 2008 - 11:11 AM

:^: yay I got it finally!


Option Explicit On
Option Strict On

Public Class MainForm

	Structure Item
		Public id As String
		Public price As Integer
		Public name As String

	End Structure


	Private Sub xExitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xExitButton.Click
		Me.Close()
	End Sub

	Private Sub xIdTextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles xIdTextBox.Enter
		Me.xIdTextBox.SelectAll()
	End Sub

	Private Sub xIdTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles xIdTextBox.TextChanged
		Me.xPriceLabel.Text = String.Empty
		Me.xNameLabel.Text = String.Empty<---This was the problem, when it was at the bottom of the code..Don't know why I put it there..
	End Sub


	Private Sub xDisplayButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xDisplayButton.Click
		'displays the price and name associated with the
		'product ID entered by the user

		Dim searchFor As String
		Dim subscript As Integer
		Dim name1 As String

		'declare an array of structure variables

		Dim gifts(4) As Item

		'assign product IDs, prices, and name to the array

		gifts(0).id = "BX35"
		gifts(0).price = 13
		gifts(0).name = "Necklace"
		gifts(1).id = "CR20"
		gifts(1).price = 10
		gifts(1).name = "Bracelet"
		gifts(2).id = "FE15"
		gifts(2).price = 12
		gifts(2).name = "Jewelry box"
		gifts(3).id = "KW10"
		gifts(3).price = 24
		gifts(3).name = "Doll"
		gifts(4).id = "MM67"
		gifts(4).price = 4
		gifts(4).name = "Ring"

		'assigns the product ID to a variable 
		searchFor = Me.xIdTextBox.Text

		'assigns name of product to a variable
		name1 = Me.xNameLabel.Text

		'search the ids array for the product ID
		'continue searching until there are
		'no more array elements to search or
		'the product ID is found

		Do Until subscript = gifts.Length _
			OrElse searchFor = gifts(subscript).id
			subscript = subscript + 1


		Loop

		'determine whether the product ID
		'was found in the ids array

		If subscript < gifts.Length Then

			Me.xPriceLabel.Text = _
			gifts(subscript).price.ToString("C0")

			Me.xNameLabel.Text = gifts(subscript).name

		Else

			MessageBox.Show("Invalid product ID", _
			"Treasures Gift Shop", _
			MessageBoxButtons.OK, _
			MessageBoxIcon.Information)

		End If

	End Sub
End Class



Thanks for the help Martyr2 and Adam, I appreciate it :wub:
Was This Post Helpful? 0
  • +
  • -

#12 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2251
  • View blog
  • Posts: 9,435
  • Joined: 29-May 08

Re: Structure statement

Posted 21 July 2008 - 11:18 AM

View PostLadyWolf, on 21 Jul, 2008 - 07:11 PM, said:

:^: yay I got it finally!

Thanks for the help Martyr2 and Adam, I appreciate it :wub:


Your getting the hang of it now. :^:
Was This Post Helpful? 0
  • +
  • -

#13 LadyWolf  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 197
  • Joined: 25-June 08

Re: Structure statement

Posted 21 July 2008 - 11:41 AM

View PostAdamSpeight2008, on 21 Jul, 2008 - 02:18 PM, said:

View PostLadyWolf, on 21 Jul, 2008 - 07:11 PM, said:

:^: yay I got it finally!

Thanks for the help Martyr2 and Adam, I appreciate it :wub:


Your getting the hang of it now. :^:


Thanks :wub: I'm trying to anyways, just when I get tired I don't think very well lol

View PostAdamSpeight2008, on 21 Jul, 2008 - 02:18 PM, said:

View PostLadyWolf, on 21 Jul, 2008 - 07:11 PM, said:

:^: yay I got it finally!

Thanks for the help Martyr2 and Adam, I appreciate it :wub:


Your getting the hang of it now. :^:


Thanks :wub: I'm trying to anyways, just when I get tired I don't think very well lol
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1