-
Feb 8th, 2018, 01:26 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Errors that need fixing
I have two errors coming up on my form (the bold areas) and Im not sure how to fix them..am I missing something??
Here is my GroceryItemForm Code:
Code:
Public Class GroceryItemForm
Private Sub GroceryItemForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim GroceryItemForm As New LoginForm
GroceryItemForm.ShowDialog()
End Sub
Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
Application.Exit()
End Sub
Private Sub ViewToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ViewToolStripMenuItem.Click
'For Each item As GroceryItem In Basket
'item.Print()
'See GroceryItem.vb for Print() code
'Next
Dim bdf As New BasketDisplayForm
bdf.ShowDialog()
End Sub
Private Sub btnAddToBasket_Click(sender As Object, e As EventArgs) Handles btnAddToBasket.Click, AddToolStripMenuItem.Click
txtScanNumber.Text = txtBrandName.Text.Substring(0, 3) & "1019"
Dim newGroceryItem As New GroceryItem (ERROR BC30516)(txtScanNumber.Text, txtBrandName.Text, numPrice.Value, txtDescription.Text,
[Enum].Parse(GetType(Aisle), cboAisle.Text))
basket.Add(newGroceryItem)
End Sub
Public Sub ??? Error BC30203 identifier expected
txtScanNumber().Text = ""
txtBrandName.Text = ""
mPrice.Value = 0.0
txtDescription.Text = ""
cboAisle.SelectedIndex = -1
End Sub
Private Sub txtBrandName_TextChanged(sender As Object, e As EventArgs) Handles txtBrandName.TextChanged
End Sub
End Class
This is my GroceryItem Code:
Code:
Public Class GroceryItem
'Variables
Public _ScanNumber As Integer
Public _BrandName As String
Public _Description As String
Public _Price As Double
Public _Aisle As String
'Unique serial item number
Private mScanNumber As Integer
Public ReadOnly Property ScanNumber As Integer
Get
Return mScanNumber
End Get
End Property
'Item name
Private mBrandName As String
Public Property BrandName As String
Get
Return mBrandName
End Get
Set(value As String)
mBrandName = value
End Set
End Property
'Item description
Private mDescription As String
Public Property Description As String
Get
Return mDescription
End Get
Set(value As String)
mDescription = value
End Set
End Property
'Price amount
Private mPrice As Double
Public Property Price As Double
Get
Return mPrice
End Get
Set(value As Double)
If value > 0 Then
mPrice = value
End If
End Set
End Property
'Grocery store aisle
Private mAisle As String
Public Property Aisle As String
Get
Return mAisle
End Get
Set(value As String)
mAisle = value
End Set
End Property
'Constructors
Public Sub New(scanNumber As String)
Me.New(scanNumber, Nothing, 0)
End Sub
Public Sub New(ScanNumber As Integer, BrandName As String, price As Double, Aisle As String)
Me.mScanNumber = ScanNumber
Me.mBrandName = BrandName
Me.mPrice = price
Me.mAisle = Aisle
End Sub
Public Sub Print()
MessageBox.Show("Aisle: " & Me.Aisle.ToString & vbCrLf & "Scan Number: " &
ScanNumber & vbCrLf & "Brand Name: " & Me.BrandName)
End Sub
Public Function Values() As String
Return ScanNumber & "," & Me.BrandName & "," & Me.Price & "," &
Me.Description & "," & Me.Aisle.ToString & vbCrLf
End Function
End Class
Public Enum Aisle
Bakery
CannedGoods
Drinks
Deli
DryGoods
FrozenFoods
Produce
End Enum
This is my Main code:
Code:
Module Main
Friend blnLoggedIn As Boolean
Dim arrUsernames() As String = {"Admin", "Clerk", "Manager"}
Dim arrPasswords() As String = {"P@ssword", "pa$$word", "passw0rd"}
Dim userIndex As Integer
Friend basket As New GroceryBasket
And this is my GroceryBasket Code:
Code:
Public Class GroceryBasket
Inherits List(Of GroceryItem)
End Class
So those 2 errors are what im trying to figure out. My instructions were to :
12. In the form’s Load event, display the login form modally and exit the application.
13. In the Click event of the btnAddToBasket button,
perform the following steps:
a. Create a GroceryItem object using the values from the controls and add it to the basket variable. Note: Remember the basket variable is the
GroceryBasket collection.
b. Verify all controls except txtScanNumber contain a value.
c. Set the value of the txtScanNumber control using the following code:
txtScanNumber.Text = _
txtBrandName.Text.Substring(0, 3) & “1019”
d. Instantiate the GroceryItem class, using the control values.
e. Use the following expression to set the Aisle property. The expression converts the text into an Aisle enumeration.
[Enum].Parse(GetType(Aisle), cboAisle.Text)
f. Add the GroceryItem object to the basket variable.
14. In the Click event of the Exit menu item, end the application.
15. Have the btnAddToBasket_Click method handle the Click event of AddToolStripMenuItem as well.
16. In the Click event of the View menu item, display all of the items in the basket variable in an informational message box. You need only display the Aisle, ScanNumber and BrandName properties.
Thanks for the help!!
Last edited by EmilyM1105; Feb 8th, 2018 at 02:06 PM.
-
Feb 8th, 2018, 01:34 PM
#2
Re: Errors that need fixing
Code:
Dim newGroceryItem As New GroceryItem (ERROR BC30516)(txtScanNumber.Text, txtBrandName.Text, numPrice.Value, txtDescription.Text,
[Enum].Parse(GetType(Aisle), cboAisle.Text))
Code:
Public Sub New(MscanNumber As Integer, brandName As String, price As Double)
Me.mScanNumber = ScanNumber
Me.BrandName = brandName
Me.Price = price
Me.Aisle = Aisle
End Sub
The constructor for gorcery item only accepts 3 parameters... you're passing 6 it looks like...
Code:
Public Sub ??? Error BC30203 identifier expected
txtScanNumber().Text = ""
txtBrandName.Text = ""
numPrice.Value = 0.0
txtDescription.Text = ""
cboAisle.SelectedIndex = -1
End Sub
Ummm... yeah... you need to give the sub a name... you simply cannot have nameless subs... otherwise how would you call it?
-tg
-
Feb 8th, 2018, 01:52 PM
#3
Thread Starter
Addicted Member
Re: Errors that need fixing
Originally Posted by techgnome
Code:
Dim newGroceryItem As New GroceryItem (ERROR BC30516)(txtScanNumber.Text, txtBrandName.Text, numPrice.Value, txtDescription.Text,
[Enum].Parse(GetType(Aisle), cboAisle.Text))
Code:
Public Sub New(MscanNumber As Integer, brandName As String, price As Double)
Me.mScanNumber = ScanNumber
Me.BrandName = brandName
Me.Price = price
Me.Aisle = Aisle
End Sub
The constructor for gorcery item only accepts 3 parameters... you're passing 6 it looks like...
Code:
Public Sub ??? Error BC30203 identifier expected
txtScanNumber().Text = ""
txtBrandName.Text = ""
numPrice.Value = 0.0
txtDescription.Text = ""
cboAisle.SelectedIndex = -1
End Sub
Ummm... yeah... you need to give the sub a name... you simply cannot have nameless subs... otherwise how would you call it?
-tg
ok but everytime I change it it gives me more errors
-
Feb 8th, 2018, 02:04 PM
#4
Re: Errors that need fixing
So what do you change it to and what errors does it give? It is much easier to help when we know what is going on.
-
Feb 8th, 2018, 02:17 PM
#5
Thread Starter
Addicted Member
Re: Errors that need fixing
So what do you change it to and what errors does it give? It is much easier to help when we know what is going on.
I added Aisle to it but its still 4 parameters..Im still getting the error on this
Code:
Public Sub New(scanNumber As Integer, brandName As String, price As Double, Aisle As String)
Me.mScanNumber = scanNumber
Me.mBrandName = brandName
Me.mPrice = price
Me.mAisle = Aisle
End Sub
Code:
Private Sub btnAddToBasket_Click(sender As Object, e As EventArgs) Handles btnAddToBasket.Click, AddToolStripMenuItem.Click
txtScanNumber.Text = txtBrandName.Text.Substring(0, 3) & "1019"
Dim newGroceryItem As New GroceryItem(txtScanNumber.Text, txtBrandName.Text, numPrice.Value, txtDescription.Text,
[Enum].Parse(GetType(Aisle), cboAisle.Text))
basket.Add(newGroceryItem)
I dont get what else I need to add..??
-
Feb 8th, 2018, 02:26 PM
#6
Re: Errors that need fixing
If that is the Sub New for a GroceryItem it is expecting four parameters
Code:
Public Sub New(scanNumber As Integer, brandName As String, price As Double, Aisle As String)
The code that is calling it is passing in six parameters
Code:
Dim newGroceryItem As New GroceryItem(txtScanNumber.Text, txtBrandName.Text, numPrice.Value, txtDescription.Text,
[Enum].Parse(GetType(Aisle), cboAisle.Text))
If it is expecting four then you need to provide four, no more and no less.
Again, if you give us the error message rather than just a vague term like "the error" we can offer a lot more specific help.
-
Feb 8th, 2018, 03:59 PM
#7
Thread Starter
Addicted Member
Re: Errors that need fixing
Originally Posted by PlausiblyDamp
If that is the Sub New for a GroceryItem it is expecting four parameters
Code:
Public Sub New(scanNumber As Integer, brandName As String, price As Double, Aisle As String)
The code that is calling it is passing in six parameters
Code:
Dim newGroceryItem As New GroceryItem(txtScanNumber.Text, txtBrandName.Text, numPrice.Value, txtDescription.Text,
[Enum].Parse(GetType(Aisle), cboAisle.Text))
If it is expecting four then you need to provide four, no more and no less.
Again, if you give us the error message rather than just a vague term like "the error" we can offer a lot more specific help.
Well thats what Im trying to figure out though..
This line was part of the instructions..
Code:
[Enum].Parse(GetType(Aisle), cboAisle.Text
So do I need 4 or 6? which part is wrong
-
Feb 8th, 2018, 04:26 PM
#8
Re: Errors that need fixing
Actually, 5... I didn't read that close enough, and was counting commas... but I see that the cboAisle.Text is actually part of the Parse command there... Not sure what's going on there... but either way... you're still sending too much data to the constructor. At the moment you're sending ScanNumber, BrandName, Price, Description, and Aisle ... but the constructor is only asking for ScanNumber, BrandName, Price, and Aisle ... So you're trying to stuff 5 items into a bin meant for 4. One doesn't belong. So it either needs to come out, or you need to add to the constructor to accept the missing piece of data.
-tg
-
Feb 8th, 2018, 04:31 PM
#9
Re: Errors that need fixing
EDIT: I was writing as TG was, and now some of my reply is wrong (he corrected the six to five), but the rest is basically what he said with a slightly different take, so I'll leave it.
Both, quite possibly.
The constructor, as it is written, takes four parameters. If that were correct, then you can ONLY pass in four. Passing in any other number will cause an error, which is what you are seeing. Therefore, for it to work you MUST pass in four and ONLY four parameters. Unfortunately, it sure doesn't look like four is the right number to be passing in. After all, the GroceryItem class has FIVE properties, so why does it only take four arguments to the constructor?
It seems like it should take these arguments:
1) Scan Number
2) Brand Name
3) Description
4) Price
5) Aisle
Instead, it takes items 1, 2, 4, and 5, but leaves out the Description. Sure, you could add a description later, but I would say that the constructor is wrong and should be taking five items rather than four. I'm not sure where the six came from, I think people were misreading the convoluted parsing of the aisle. It appears that you are passing in five items, so fixing the constructor is the best solution. The parsing of Aisle sure seems wrong to me, but fix up the constructor first.
My usual boring signature: Nothing
-
Feb 8th, 2018, 05:03 PM
#10
Thread Starter
Addicted Member
Re: Errors that need fixing
EDIT: I was writing as TG was, and now some of my reply is wrong (he corrected the six to five), but the rest is basically what he said with a slightly different take, so I'll leave it.
Both, quite possibly.
The constructor, as it is written, takes four parameters. If that were correct, then you can ONLY pass in four. Passing in any other number will cause an error, which is what you are seeing. Therefore, for it to work you MUST pass in four and ONLY four parameters. Unfortunately, it sure doesn't look like four is the right number to be passing in. After all, the GroceryItem class has FIVE properties, so why does it only take four arguments to the constructor?
It seems like it should take these arguments:
1) Scan Number
2) Brand Name
3) Description
4) Price
5) Aisle
Instead, it takes items 1, 2, 4, and 5, but leaves out the Description. Sure, you could add a description later, but I would say that the constructor is wrong and should be taking five items rather than four. I'm not sure where the six came from, I think people were misreading the convoluted parsing of the aisle. It appears that you are passing in five items, so fixing the constructor is the best solution. The parsing of Aisle sure seems wrong to me, but fix up the constructor first.
Ok I fixed it but on my GroceryItemForm Im getting a different message on the same line again
The message says.. System.ArgumentException: 'Must specify valid information for parsing in the string.'
Here is my GroceryItemForm Code:
Code:
Public Class GroceryItemForm
Private Sub GroceryItemForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim GroceryItemForm As New LoginForm
GroceryItemForm.ShowDialog()
End Sub
Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
Application.Exit()
End Sub
Private Sub ViewToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ViewToolStripMenuItem.Click
'For Each item As GroceryItem In Basket
'item.Print()
'See GroceryItem.vb for Print() code
'Next
Dim bdf As New BasketDisplayForm
ShowDialog(bdf)
End Sub
Private Sub btnAddToBasket_Click(sender As Object, e As EventArgs) Handles btnAddToBasket.Click, AddToolStripMenuItem.Click
txtScanNumber.Text = txtBrandName.Text.Substring(0, 3) & "1019"
Dim newGroceryItem As New GroceryItem(txtScanNumber.Text, txtBrandName.Text, numPrice.Value, txtDescription.Text,
[Enum].Parse(GetType(Aisle), cboAisle.Text))
basket.Add(newGroceryItem)
End Sub
Public Sub clearForm()
txtScanNumber().Text = ""
txtBrandName.Text = ""
numPrice.Value = 0.0
txtDescription.Text = ""
cboAisle.SelectedIndex = -1
End Sub
End Class
Here is my GroceryItem Code:
Code:
Public Class GroceryItem
'Variables
Public _ScanNumber As String
Public _BrandName As String
Public _Description As String
Public _Price As Double
Public _Aisle As Aisle
'Unique serial item number
Public ReadOnly Property ScanNumber As String
Get
Return _ScanNumber
End Get
End Property
'Item name
Public Property BrandName As String
Get
Return _BrandName
End Get
Set(value As String)
_BrandName = value
End Set
End Property
'Item description
Public Property Description As String
Get
Return _Description
End Get
Set(value As String)
_Description = value
End Set
End Property
'Price amount
Public Property Price As Double
Get
Return _Price
End Get
Set(value As Double)
If value > 0 Then
_Price = value
End If
End Set
End Property
'Grocery store aisle
Public Property Aisle As Aisle
Get
Return _Aisle
End Get
Set(value As Aisle)
_Aisle = value
End Set
End Property
'Constructors
Public Sub New(scanNumber As String)
Me.New(scanNumber, Nothing, 0)
End Sub
Public Sub New(scanNumber As String, brandName As String, price As Double)
Me.New(scanNumber, Nothing, 0, Nothing, Aisle.Bakery)
End Sub
Public Sub New(scanNumber As String, brandName As String, price As Double, description As String,
aisle As Aisle)
Me._ScanNumber = scanNumber
Me._BrandName = brandName
Me._Price = price
Me._Description = description
Me._Aisle = aisle
End Sub
Public Sub Print()
MessageBox.Show("Aisle: " & Me.Aisle.ToString & vbCrLf & "Scan Number: " &
ScanNumber & vbCrLf & "Brand Name: " & Me.BrandName)
End Sub
Public Function Values() As String
Return _ScanNumber & "," & Me.BrandName & "," & Me.Price & "," &
Me.Description & "," & Me.Aisle.ToString & vbCrLf
End Function
End Class
Public Enum Aisle
Bakery
CannedGoods
Drinks
Deli
DryGoods
FrozenFoods
Produce
End Enum
Last edited by EmilyM1105; Feb 8th, 2018 at 05:36 PM.
-
Feb 8th, 2018, 05:58 PM
#11
Thread Starter
Addicted Member
Re: Errors that need fixing
Ok never mind I got that error to go away. All I did was..
Code:
Public Class GroceryItemForm
Private Sub GroceryItemForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim GroceryItemForm As New LoginForm
GroceryItemForm.ShowDialog()
End Sub
Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
Application.Exit()
End Sub
Private Sub ViewToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ViewToolStripMenuItem.Click
'For Each item As GroceryItem In Basket
'item.Print()
'See GroceryItem.vb for Print() code
'Next
Dim bdf As New BasketDisplayForm
ShowDialog(bdf)
End Sub
Private Sub btnAddToBasket_Click(sender As Object, e As EventArgs) Handles btnAddToBasket.Click, AddToolStripMenuItem.Click
txtScanNumber.Text = txtBrandName.Text.Substring(0, 3) & "1019"
Dim newGroceryItem As New GroceryItem(txtScanNumber.Text, txtBrandName.Text, numPrice.Value, txtDescription.Text,
[Enum].Parse(GetType(Aisle), cboAisle.Text))
basket.Add(newGroceryItem)
End Sub
Public Sub clearForm()
txtScanNumber().Text = ""
txtBrandName.Text = ""
numPrice.Value = 0.0
txtDescription.Text = ""
cboAisle.SelectedIndex = -1
End Sub
End Class
Can anyone tell me if I'm missing anything in my codes according to the directions up top?
Thanks for the help everyone!!
Last edited by EmilyM1105; Feb 8th, 2018 at 06:02 PM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|