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
Structure statement with an module-level array, and list boxLoad event needs to read txt file, and store item numbers and prices i
31 Replies - 5078 Views - Last Post: 18 August 2008 - 09:46 AM
#1
Structure statement with an module-level array, and list box
Posted 23 July 2008 - 02:02 AM
Replies To: Structure statement with an module-level array, and list box
#2
Re: Structure statement with an module-level array, and list box
Posted 23 July 2008 - 11:02 AM
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.
#3
Re: Structure statement with an module-level array, and list box
Posted 23 July 2008 - 11:09 AM
#4
Re: Structure statement with an module-level array, and list box
Posted 23 July 2008 - 11:15 AM
itemprice = Me.xPriceLabel.Text
#5
Re: Structure statement with an module-level array, and list box
Posted 23 July 2008 - 11:30 AM
#6
Re: Structure statement with an module-level array, and list box
Posted 23 July 2008 - 01:16 PM
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
#7
Re: Structure statement with an module-level array, and list box
Posted 23 July 2008 - 02:03 PM
LadyWolf, on 23 Jul, 2008 - 03:16 PM, said:
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
#8
Re: Structure statement with an module-level array, and list box
Posted 23 July 2008 - 02:17 PM
#9
Re: Structure statement with an module-level array, and list box
Posted 23 July 2008 - 02:22 PM
Should be something like this:
Dim value As String = My.Computer.FileSystem.ReadAllText("itemInfo.txt")
#10
Re: Structure statement with an module-level array, and list box
Posted 23 July 2008 - 02:36 PM
[beingobtusetoday]Yep(again). What Jayman said.[/beingobtusetoday]
To jayman9:
Thanks for taking my back today.
#11
Re: Structure statement with an module-level array, and list box
Posted 25 July 2008 - 09:28 AM
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
jayman9, on 23 Jul, 2008 - 05:22 PM, said:
Should be something like this:
Dim value As String = My.Computer.FileSystem.ReadAllText("itemInfo.txt")
I've put all kinds of values and nothing...
#12
Re: Structure statement with an module-level array, and list box
Posted 25 July 2008 - 09:41 AM
djkitt, on 23 Jul, 2008 - 05:36 PM, said:
[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
#13
Re: Structure statement with an module-level array, and list box
Posted 25 July 2008 - 10:29 AM
LadyWolf, on 25 Jul, 2008 - 11:41 AM, said:
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
#14
Re: Structure statement with an module-level array, and list box
Posted 25 July 2008 - 10:33 AM
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
#15
Re: Structure statement with an module-level array, and list box
Posted 27 July 2008 - 06:56 AM
djkitt, on 25 Jul, 2008 - 01:29 PM, said:
LadyWolf, on 25 Jul, 2008 - 11:41 AM, said:
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.
|
|

New Topic/Question
Reply




MultiQuote






|