Results 1 to 9 of 9

Thread: Graphical User Interface Design

Hybrid View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2018
    Posts
    136

    Question Graphical User Interface Design

    There are some things Im having trouble with and some things I need to have checked to see if there correct..Im working step by step..

    My instructions are to:

    1. In the form’s Load event, display the login form modally and exit the application.

    2. 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.


    Here is my GroceryItemForm Code:

    Code:
    Public Class GroceryItemForm
        Private Sub GroceryItemForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load, BasketToolStripMenuItem.Click, MyBase.Click, btnAddToBasket.Click, AddToolStripMenuItem.Click
    
        End Sub
    
        Private Sub RichTextBox1_TextChanged(sender As Object, e As EventArgs) Handles txtDescription.TextChanged
    
        End Sub
    
        Private Sub txtScanNumber_TextChanged(sender As Object, e As EventArgs) Handles txtScanNumber.TextChanged
            txtScanNumber.Text =
         txtBrandName.Text.Substring(0, 3) & “1019”
        End Sub
    
        Private Sub cboAisle_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboAisle.SelectedIndexChanged
            [Enum].Parse(GetType(Aisle), cboAisle.Text)
        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
    
        End Sub
    End Class
    And here is my LoginForm Code:


    Code:
    Public Class LoginForm
        Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
            Try
                Login(txtUsername.Text, txtPassword.Text)
            Catch ex As 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
    
        End Sub
        Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
            Application.Exit()
        End Sub
    End Class

    I know its alot but im a beginner so Im learning how to do all of this along the way..Thanks for your help!
    Last edited by EmilyM1105; Feb 7th, 2018 at 12:00 AM.

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,988

    Re: Graphical User Interface Design

    #1) That's weird. Is that really all you are asked to do? I can understand why you didn't understand that. I would guess that what they want you to do is display the login form, and if the login fails, then exit the application....but that's not quite what it says. What it tells you to do is to display the login form using ShowDialog (that's what 'display modally' means), then exit the application regardless of what happens. That's just weird.

    2) Was there a picture? I forget what fields the grocery item had, but it sounds like you should have one control for each field. Use textboxes for strings the user types in, comboboxes or listboxes for selecting from a set of items, and NumericUpDown controls for entering numbers. Whatever the fields are in the GroceryItem class, you need one control for each of those items. Verifying that the controls contain values is different for different controls. For a textbox, you check that Textbox.Text <> "", for a list or combo box, you'd check that the SelectedIndex <> -1. For a NumericUpDown control, you'd check that .Value > 0.

    I thought you had done steps d, e, and f in one of the other threads. Creating an instance of a Grocery Item with something like:

    Dim newGroceryItem As New GroceryItem(the values from the controls go here)

    15) You've got the Load event handler also handling all the click events. You need the load event handler to JUST handle the load event, and the button click event handle the other events.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2018
    Posts
    136

    Re: Graphical User Interface Design

    ok so for Number 1 do i write it like this?

    Code:
    Public Function ShowDialog As LoginForm
    Me.Close()
    If thats right..where would I put that?


    And for Number 2..where would I put those values you said? Is there a specific control name it goes under? Thats what Im confused on


    Ok for Number 15 I updated my code..Now I have the GroceryItem Form only handling the load but for the click event what should be there?

    GroceryItem Form Code update:

    Code:
    Public Class GroceryItemForm
        Private Sub GroceryItemForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
        End Sub
    
        Private Sub RichTextBox1_TextChanged(sender As Object, e As EventArgs) Handles txtDescription.TextChanged
    
        End Sub
    
        Private Sub txtScanNumber_TextChanged(sender As Object, e As EventArgs) Handles txtScanNumber.TextChanged
            txtScanNumber.Text =
         txtBrandName.Text.Substring(0, 3) & “1019”
        End Sub
    
        Private Sub cboAisle_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboAisle.SelectedIndexChanged
            [Enum].Parse(GetType(Aisle), cboAisle.Text)
        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
    
        End Sub
    
        Private Sub btnAddToBasket_Click(sender As Object, e As EventArgs) Handles btnAddToBasket.Click
    
        End Sub
    End Class

    Also my instructions told me to add this but Aisle is giving me an error saying its not defined??

    Code:
    Private Sub cboAisle_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboAisle.SelectedIndexChanged
            [Enum].Parse(GetType(Aisle), cboAisle.Text)
        End Sub
    Last edited by EmilyM1105; Feb 6th, 2018 at 04:06 PM.

  4. #4
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: Graphical User Interface Design

    Assuming that you have a form named LoginForm, then in your form’s Load event you create a new instance of the LoginForm and call the ShowDialog method. You would want to use the Using statement since Forms implement iDisposable:
    Code:
    Using frmLogin As LoginForm = New LoginForm
        frmLogin.ShowDialog()
    End Using
    
    Me.Close()
    However, assuming that you haven't gone over Using statements, here is an alternative:
    Code:
    Dim frmLogin As LoginForm = New LoginForm
    frmLogin.ShowDialog()
    frmLogin.Dispose()
    
    Me.Close()
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2018
    Posts
    136

    Re: Graphical User Interface Design

    Quote Originally Posted by dday9 View Post
    Assuming that you have a form named LoginForm, then in your form’s Load event you create a new instance of the LoginForm and call the ShowDialog method. You would want to use the Using statement since Forms implement iDisposable:
    Code:
    Using frmLogin As LoginForm = New LoginForm
        frmLogin.ShowDialog()
    End Using
    
    Me.Close()
    However, assuming that you haven't gone over Using statements, here is an alternative:
    Code:
    Dim frmLogin As LoginForm = New LoginForm
    frmLogin.ShowDialog()
    frmLogin.Dispose()
    
    Me.Close()

    Where would I put the showdialog code? Would I put it in the Login Form or the Grocery Item Form?? I have both codes at the top

  6. #6
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Graphical User Interface Design

    Your instruction says
    "In the form’s Load event, display the login form modally and exit the application."
    Since you are displaying the login form, the code wouldn't be in the login form it would be in "the form", i.e. another form that is part of your project.
    Of course, if you show the login form modally from another form's Load event, you won't see the original form until after the login form exits.
    And since you exit the application before the Load event completes, you will most likely never see the startup form because the form isn't shown until after the Load Event handler completes.

    If you double click on your main form, the IDE should create a Load Event Sub for you and that is where you would put the requested code.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jan 2018
    Posts
    136

    Re: Graphical User Interface Design

    Quote Originally Posted by passel View Post
    Your instruction says
    "In the form’s Load event, display the login form modally and exit the application."
    Since you are displaying the login form, the code wouldn't be in the login form it would be in "the form", i.e. another form that is part of your project.
    Of course, if you show the login form modally from another form's Load event, you won't see the original form until after the login form exits.
    And since you exit the application before the Load event completes, you will most likely never see the startup form because the form isn't shown until after the Load Event handler completes.

    If you double click on your main form, the IDE should create a Load Event Sub for you and that is where you would put the requested code.
    ok so this section on my GroceryItemForm Code should look like this??

    Code:
    Public Class GroceryItemForm
        Private Sub GroceryItemForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Using frmLogin As LoginForm = New LoginForm
                frmLogin.ShowDialog()
            End Using
            Me.Close()
        End Sub
    Last edited by EmilyM1105; Feb 6th, 2018 at 04:53 PM.

  8. #8
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,711

    Re: Graphical User Interface Design

    As per the given instructions, yes.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jan 2018
    Posts
    136

    Re: Graphical User Interface Design

    Quote Originally Posted by dday9 View Post
    As per the given instructions, yes.
    Ok thankyou!!

    Do you know why I might be getting this error on my GroceryItem Form Code?? It says Aisle Type not defined??

    Code:
    Private Sub cboAisle_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboAisle.SelectedIndexChanged
            [Enum].Parse(GetType(Aisle), cboAisle.Text)
        End Sub

    Do I have to change the name? or am I supposed to add something under?

    On my GroceryItem Code I have this:

    Code:
    Public Property Aisle As String
            Get
                Return mAisle
            End Get
            Set(value As String)
                mAisle = value
            End Set
        End Property
    Does this relate to that part?

    These are my list of Aisles I have under the collection in my GroceryItem Form code..

    Bakery
    CannedGoods
    Drinks
    Deli
    DryGoods
    FrozenFoods
    Produce
    Last edited by EmilyM1105; Feb 6th, 2018 at 05:59 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
  •  



Click Here to Expand Forum to Full Width