|
-
Feb 3rd, 2018, 05:27 AM
#6
Re: Derive from the generic List class
I don't know how you're suppose to display the items in the basket to verify they are there.
Also, I don't understand the hierarchy of your program.
You have a login button and textboxes, but are those on a separate login form compared to your main form?
The reason I ask is because if the user successfully logins in you do a "Me.Close" which will close the current form that the code is running in, so I assume you must have another main form that had a button that presented the login form.
Going with that assumption, I created a quick test where the main form (form1) had a button to show the login form, and another button to simply print out items in the basket using Debug.Print (prints to the Immediate Window or Output Window depending on your IDE option).
Code:
Public Class Form1
Private Sub btnLogin_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnLogin.Click
LoginForm.ShowDialog()
End Sub
Private Sub btnShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShow.Click
For Each item As GroceryItem In Main.basket
Debug.Print("{0}, {1}, {2}", item.ScanNumber.ToString, item.BrandName, item.Price.ToString)
Next
End Sub
And in the login code, added items to the basket along the lines that Sitten Spynne mentioned.
Code:
Public Class LoginForm
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Try
Login(txtUsername.Text, txtPassword.Text)
Catch ex As Exception 'LoginException
MessageBox.Show("Incorrect password.")
End Try
If Main.blnLoggedIn Then
MessageBox.Show("Thank you for logging in, " & txtUsername.Text, "Logged In.")
Me.Close()
End If
Dim anItem As GroceryItem
anItem = New GroceryItem(1, "Apple Acres", 0.25)
Main.basket.Add(anItem)
anItem = New GroceryItem(2, "Banana Barn", 0.49)
Main.basket.Add(anItem)
End Sub
End Class
I didn't create the "LoginException" value, so just commented it out rather than deal with it.
I also probably would have put the test code that adds items to the basket inside the If block where the user successfully logged in, because this will add items even if Main.blnLoggedIn is false since it is outside the block.
Once the login form is closed, and assuming the lines that add items to the basket were executed, on the main form if you press the "show" button, you should see the items printed out, verifying that the code did successfully add items to the basket.
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
|