Structure statement with an module-level array, and list box

Load event needs to read txt file, and store item numbers and prices i

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

31 Replies - 5781 Views - Last Post: 18 August 2008 - 09:46 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 with an module-level array, and list box

Post icon  Posted 23 July 2008 - 02:02 AM

Been working this one all day, not sure if I'm even on the right track anymore, lol. Here's the code I have at the moment, but I think I'll be starting over again soon.


Option Explicit On
Option Strict On

Public Class MainForm

	Structure Product
		Public itemnumber As String
		Public itemprice As Decimal

	End Structure

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

	Private Sub xNumbersListBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles xNumbersListBox.Enter
		'declare an module-level array that 
		'contains five Product structure variables

		Dim items(4) As Product

		items(0).itemnumber = "12AVX"
		items(0).itemprice = CDec(5.0)
		items(1).itemnumber = "23ABC"
		items(1).itemprice = CDec(8.97)
		items(2).itemnumber = "23TWT"
		items(2).itemprice = CDec(4.69)
		items(3).itemnumber = "34ZAB"
		items(3).itemprice = CDec(12.5)
		items(4).itemnumber = "91BAN"
		items(4).itemprice = CDec(34.67)

	End Sub

	Private Sub MainForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
		'reads the item number and prices
		'from the access file. Stores the
		'item numbers to the list box.

		Me.xNumbersListBox.Items.Add(itemInfo.txt)

	End Sub

	Private Sub xPriceLabel_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles xPriceLabel.Enter

		'user selects an item from the list box
		'the item's price appears in the xPriceLabel

		Dim itemprice As String

		itemprice = Me.xPriceLabel<--error here says that Windows.Forms.Label cannot be converted to string

	End Sub
End Class



Is This A Good Question/Topic? 0
  • +

Replies To: Structure statement with an module-level array, and list box

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Structure statement with an module-level array, and list box

Posted 23 July 2008 - 11:02 AM

Can you post a description of the problem that you are having?

Don't use the description field when posting a new topic to describe your problem, it only allows a fixed number of characters to be visible.
Was This Post Helpful? 0
  • +
  • -

#3 djkitt  Icon User is offline

  • D.I.C Head

Reputation: 29
  • View blog
  • Posts: 189
  • Joined: 22-May 08

Re: Structure statement with an module-level array, and list box

Posted 23 July 2008 - 11:09 AM

View PostLadyWolf, on 23 Jul, 2008 - 04:02 AM, said:



		itemprice = Me.xPriceLabel<--error here says that Windows.Forms.Label cannot be converted to string




So, try this:
		itemprice = Me.xPriceLabel.ToString



Hope this helps,
Was This Post Helpful? 0
  • +
  • -

#4 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Structure statement with an module-level array, and list box

Posted 23 July 2008 - 11:15 AM

Actually, it should be accessing the Text property.

itemprice = Me.xPriceLabel.Text

Was This Post Helpful? 1
  • +
  • -

#5 djkitt  Icon User is offline

  • D.I.C Head

Reputation: 29
  • View blog
  • Posts: 189
  • Joined: 22-May 08

Re: Structure statement with an module-level array, and list box

Posted 23 July 2008 - 11:30 AM

View Postjayman9, on 23 Jul, 2008 - 01:15 PM, said:

Actually, it should be accessing the Text property.

itemprice = Me.xPriceLabel.Text


[blush][wasntme][ididthatonpurpose]Uh, yep.[/ididthatonpurpose][/wasnt me][/blush]

This post has been edited by djkitt: 23 July 2008 - 11:33 AM

Was This Post Helpful? 0
  • +
  • -

#6 LadyWolf  Icon User is offline

  • D.I.C Head

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

Re: Structure statement with an module-level array, and list box

Posted 23 July 2008 - 01:16 PM

Thanks dj, not sure if it worked yet or not though..Now I'm working on this error..Here's where I'm at now, though I'm working on it as this is being posted..


Option Explicit On
Option Strict On

Public Class MainForm

	Structure Product
		Public itemnumber As String
		Public itemprice As Decimal

	End Structure

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

	Private Sub xNumbersListBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles xNumbersListBox.Enter
		'declare an module-level array that 
		'contains five Product structure variables

		Dim items(4) As Product

		items(0).itemnumber = "12AVX"
		items(0).itemprice = CDec(5.0)
		items(1).itemnumber = "23ABC"
		items(1).itemprice = CDec(8.97)
		items(2).itemnumber = "23TWT"
		items(2).itemprice = CDec(4.69)
		items(3).itemnumber = "34ZAB"
		items(3).itemprice = CDec(12.5)
		items(4).itemnumber = "91BAN"
		items(4).itemprice = CDec(34.67)

	End Sub

	Private Sub MainForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
		'reads the item number and prices
		'from the access file. Stores the
		'item numbers to the list box.

		My.Computer.FileSystem.WriteAllText(itemInfo.txt)<--error says'itemInfo.txt' with only itemInfo underlined..is not declared

	End Sub

	Private Sub xPriceLabel_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles xPriceLabel.Enter

		'user selects an item from the list box
		'the item's price appears in the xPriceLabel

		Dim itemprice As String

		itemprice = Me.xPriceLabel.Text

	End Sub
End Class



Same here...


Option Explicit On
Option Strict On

Public Class MainForm

	Structure Product
		Public itemnumber As String
		Public itemprice As Decimal

	End Structure

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

	Private Sub xNumbersListBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles xNumbersListBox.Enter
		'declare an module-level array that 
		'contains five Product structure variables

		Dim items(4) As Product

		items(0).itemnumber = "12AVX"
		items(0).itemprice = CDec(5.0)
		items(1).itemnumber = "23ABC"
		items(1).itemprice = CDec(8.97)
		items(2).itemnumber = "23TWT"
		items(2).itemprice = CDec(4.69)
		items(3).itemnumber = "34ZAB"
		items(3).itemprice = CDec(12.5)
		items(4).itemnumber = "91BAN"
		items(4).itemprice = CDec(34.67)

	End Sub

	Private Sub MainForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
		'reads the item number and prices
		'from the access file. Stores the
		'item numbers to the list box.

		My.Computer.FileSystem.ReadAllText(itemInfo.txt)

	End Sub

	Private Sub xPriceLabel_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles xPriceLabel.Enter

		'user selects an item from the list box
		'the item's price appears in the xPriceLabel

		Dim itemprice As String

		itemprice = Me.xPriceLabel.Text

	End Sub
End Class


Was This Post Helpful? 0
  • +
  • -

#7 djkitt  Icon User is offline

  • D.I.C Head

Reputation: 29
  • View blog
  • Posts: 189
  • Joined: 22-May 08

Re: Structure statement with an module-level array, and list box

Posted 23 July 2008 - 02:03 PM

View PostLadyWolf, on 23 Jul, 2008 - 03:16 PM, said:

Thanks dj, not sure if it worked yet or not though..Now I'm working on this error..Here's where I'm at now, though I'm working on it as this is being posted..


		My.Computer.FileSystem.WriteAllText(itemInfo.txt)<--error says'itemInfo.txt' with only itemInfo underlined..is not declared




Hey again,

I think maybe you want to put iteminfo.txt in quotes, like so:


	My.Computer.FileSystem.WriteAllText("itemInfo.txt")

	My.Computer.FileSystem.ReadAllText("itemInfo.txt")




A couple of things, though...

I think this file will default to your application directory. If you want it somewhere else you should add a path to your string.

You need a string variable to hold what is returned from ReadAllText.

Hope this helps,

This post has been edited by djkitt: 23 July 2008 - 02:25 PM

Was This Post Helpful? 1
  • +
  • -

#8 LadyWolf  Icon User is offline

  • D.I.C Head

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

Re: Structure statement with an module-level array, and list box

Posted 23 July 2008 - 02:17 PM

Not sure I understand what your saying, but I'll play with it after dinner.
Was This Post Helpful? 0
  • +
  • -

#9 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Structure statement with an module-level array, and list box

Posted 23 July 2008 - 02:22 PM

What he is saying is that the ReadAllText method returns a string. The string contains all the data read from the file.

Should be something like this:
Dim value As String = My.Computer.FileSystem.ReadAllText("itemInfo.txt")

Was This Post Helpful? 1
  • +
  • -

#10 djkitt  Icon User is offline

  • D.I.C Head

Reputation: 29
  • View blog
  • Posts: 189
  • Joined: 22-May 08

Re: Structure statement with an module-level array, and list box

Posted 23 July 2008 - 02:36 PM

To LadyWolf:

[beingobtusetoday]Yep(again). What Jayman said.[/beingobtusetoday]

To jayman9:
Thanks for taking my back today.
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 with an module-level array, and list box

Posted 25 July 2008 - 09:28 AM

While having server problems I continued to work on this, and nothing has worked yet. Here what I have at this time..


Option Explicit On
Option Strict On

Public Class MainForm

	Structure Product
		Public itemnumber As String
		Public itemprice As Decimal

	End Structure

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

	Private Sub xNumbersListBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles xNumbersListBox.Enter
		'declare an module-level array that 
		'contains five Product structure variables

		Dim items(4) As Product

		items(0).itemnumber = "12AVX"
		items(0).itemprice = CDec(5.0)
		items(1).itemnumber = "23ABC"
		items(1).itemprice = CDec(8.97)
		items(2).itemnumber = "23TWT"
		items(2).itemprice = CDec(4.69)
		items(3).itemnumber = "34ZAB"
		items(3).itemprice = CDec(12.5)
		items(4).itemnumber = "91BAN"
		items(4).itemprice = CDec(34.67)


	End Sub

	Private Sub MainForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
		'reads the item number and prices
		'from the access file. Stores the
		'item numbers to the list box.

		Dim itemnumber As String

		itemnumber = My.Computer.FileSystem.ReadAllText("itemInfo.txt")
		Me.xNumbersListBox.Text = ""


		End Sub

	Private Sub xPriceLabel_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles xPriceLabel.Enter

		'user selects an item from the list box
		'the item's price appears in the xPriceLabel

		Dim itemprice As String

		itemprice = Me.xPriceLabel.Text

	End Sub
End Class



View Postjayman9, on 23 Jul, 2008 - 05:22 PM, said:

What he is saying is that the ReadAllText method returns a string. The string contains all the data read from the file.

Should be something like this:
Dim value As String = My.Computer.FileSystem.ReadAllText("itemInfo.txt")


I've put all kinds of values and nothing...
Was This Post Helpful? 0
  • +
  • -

#12 LadyWolf  Icon User is offline

  • D.I.C Head

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

Re: Structure statement with an module-level array, and list box

Posted 25 July 2008 - 09:41 AM

View Postdjkitt, on 23 Jul, 2008 - 05:36 PM, said:

To LadyWolf:

[beingobtusetoday]Yep(again). What Jayman said.[/beingobtusetoday]

To jayman9:
Thanks for taking my back today.


I have worked very hard to try to learn VB, and I feel slightly offended being called obtuse :angry: I do try to figure whatever issues out on my own before posting here. I worked in the manufacturing field all my life, and at times I don't understand 'tech talk'. Other that that, I do appreciate the advice the both of you have given me, and I'll continue to try to figure it out.
Was This Post Helpful? 0
  • +
  • -

#13 djkitt  Icon User is offline

  • D.I.C Head

Reputation: 29
  • View blog
  • Posts: 189
  • Joined: 22-May 08

Re: Structure statement with an module-level array, and list box

Posted 25 July 2008 - 10:29 AM

View PostLadyWolf, on 25 Jul, 2008 - 11:41 AM, said:

I have worked very hard to try to learn VB, and I feel slightly offended being called obtuse :angry:

LadyWolf,

So, I am extremely sorry. I was trying to indicate that *I* was being obtuse, not you. It looks like I did it again. I seemed to be having trouble communicating my thoughts yesterday.

Again, I am very sorry to have offended you and to have made you angry. It was certainly not my intention.

This post has been edited by djkitt: 25 July 2008 - 10:29 AM

Was This Post Helpful? 0
  • +
  • -

#14 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2267
  • View blog
  • Posts: 9,480
  • Joined: 29-May 08

Re: Structure statement with an module-level array, and list box

Posted 25 July 2008 - 10:33 AM

Hi Ladywolf,
I think some of the coding problems have been caused by where you defined the items array, I moved it out off a routine. See if this help.

Option Explicit On
Option Strict On

Public Class MainForm 

  Dim items() as Product ' Now available to all routines in MainForm



	Structure Product
		Public itemnumber As String
		Public itemprice As Decimal

	End Structure

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

	Private Sub xNumbersListBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles xNumbersListBox.Enter
		'declare an module-level array that 
		'contains five Product structure variables
redim items(4)
	'	Dim items(4) As Product  --> is only local to this routine

		items(0).itemnumber = "12AVX"
		items(0).itemprice = CDec(5.0)
		items(1).itemnumber = "23ABC"
		items(1).itemprice = CDec(8.97)
		items(2).itemnumber = "23TWT"
		items(2).itemprice = CDec(4.69)
		items(3).itemnumber = "34ZAB"
		items(3).itemprice = CDec(12.5)
		items(4).itemnumber = "91BAN"
		items(4).itemprice = CDec(34.67)


	End Sub

	Private Sub MainForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
		'reads the item number and prices
		'from the access file. Stores the
		'item numbers to the list box.

		Dim itemnumber As String
dim tmp() as string = My.Computer.FileSystem.ReadAllText("itemInfo.txt")
dim a as integer = ubound(tmp)
' read in a odd number of lines go back to last even line
if a mod 2=1 then a=a-1
redim items(a)
' build item list
for i as integer =0 to a step 2
 items(i).itemnumber=a(i)
 items(i).itemprice=a(i+1)
next i
		Me.xNumbersListBox.Text = ""


		End Sub

	Private Sub xPriceLabel_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles xPriceLabel.Enter

		'user selects an item from the list box
		'the item's price appears in the xPriceLabel

		Dim itemprice As String

		itemprice = Me.xPriceLabel.Text

	End Sub
End Class


This post has been edited by AdamSpeight2008: 25 July 2008 - 10:43 AM

Was This Post Helpful? 0
  • +
  • -

#15 LadyWolf  Icon User is offline

  • D.I.C Head

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

Re: Structure statement with an module-level array, and list box

Posted 27 July 2008 - 06:56 AM

View Postdjkitt, on 25 Jul, 2008 - 01:29 PM, said:

View PostLadyWolf, on 25 Jul, 2008 - 11:41 AM, said:

I have worked very hard to try to learn VB, and I feel slightly offended being called obtuse :angry:

LadyWolf,

So, I am extremely sorry. I was trying to indicate that *I* was being obtuse, not you. It looks like I did it again. I seemed to be having trouble communicating my thoughts yesterday.

Again, I am very sorry to have offended you and to have made you angry. It was certainly not my intention.


It's okay..it was just the way it showed on the forum, that's the thing about online communication...sometimes it's easy to misunderstand others. I'm new to DIC and hope to make friends and learn from others on this forum as this is a new career path for me, and then perhaps then I can help others also. Thank you for apologizing, and explaining what you meant by it, that means a lot to me.
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3