Visual Basic Help

lil layzie

Gawd
Joined
Jan 7, 2004
Messages
755
This semester I'm taking an Intro To Visual Basic course and we have to use Microsoft Visual Studio 2005 to do all of our work.

I'm currently working on a project and I've done most of the coding but I'm kinda stuck at some parts. I was wondering if any one would like to help me. I would ask my professor but it's the weekend and I don't meet up with that class until Tuesday and he never responds to any emails.

Let me post my GUI and part of the code from my project.

project.jpg


-deleted 'cause it was making thread too long

Okay, I hope I can explain this as clearly as I can. I'm trying to code my Order Button to make it generate a message box confirming my order and listing the cpu type with the price and listing any optional hardware if the user decides to check them. Something like this :

confirm.jpg


I'm having trouble with the first part of my code. Its suppose to check and make sure that the user has entered all his information and checks which cpu type and payment type. If the user didn't do any of that, it will display an error message telling the user to display all the required fields. (By calling the private subs which I have not posted.) I was wondering how do I make the confirmation box not pop up when it asks the user to fill out all the require fields. (the red part of the code is where I'm having trouble placing it)

I hope I explained everything clearly. all this coding stuff is making my brain hurt.
 
Try adding a Return immedately after Call EmptyWarning()
 
Try adding a Return immedately after Call EmptyWarning()

That worked. Thanks so much. I'm new to this stuff so I didn't know it was that simple :eek:

edit-
now im stuck at another part.

help.jpg


How do I get the total from my form to my message box?

The code for my total is:
Code:
Private Function CalculateTotal() As Decimal

        ' declare varibles
        Const video As Decimal = 50D
        Const harddrive As Decimal = 70D
        Const memory As Decimal = 49D
        Const sound As Decimal = 15D
        Const modem As Decimal = 9.99D
        Dim total As Decimal
        Dim isConverted As Boolean

        isConverted = Decimal.TryParse(totalLabel.Text, total)

        ' determines which cpu option is selected
        If advanceRadioButton.Checked Then
            total = 280D
        ElseIf intermediateRadioButton.Checked Then
            total = 160D
        ElseIf basicRadioButton.Checked Then
            total = 99.5D
        Else
        End If


        ' determines which check boxes (if any) are selected
        If videoCheckBox.Checked Then
            total = total + video
        End If
        If harddriveCheckBox.Checked Then
            total = total + harddrive
        End If
        If memoryCheckBox.Checked Then
            total = total + memory
        End If
        If soundCheckBox.Checked Then
            total = total + sound
        End If
        If modemCheckBox.Checked Then
            total = total + modem
        End If

        ' calculate the total with 6% sales tax
        total = total * 0.06D + total

        ' displays the total
        totalLabel.Text = total.ToString("C2")

    End Function

And the code for my message box is:
Code:
Private Function getOrderForm() As String

        Dim OrderForm As String = "You have placed an order for" & vbNewLine

        If advanceRadioButton.Checked = True Then
            OrderForm = OrderForm & "Advance CPU ($280.00)" & vbNewLine
        ElseIf intermediateRadioButton.Checked Then
            OrderForm = OrderForm & "Intermediate CPU ($160.00)" & vbNewLine
        Else : basicRadioButton.Checked = True
            OrderForm = OrderForm & "Basic CPU ($99.50)" & vbNewLine
        End If

        If videoCheckBox.Checked Or _
        harddriveCheckBox.Checked Or _
        memoryCheckBox.Checked Or _
        soundCheckBox.Checked Or _
        modemCheckBox.Checked Then
            OrderForm = OrderForm & "with the following options:" & vbNewLine
        Else
        End If

        If videoCheckBox.Checked Then
            OrderForm = OrderForm & "   Video Card" & vbNewLine
        End If

        If harddriveCheckBox.Checked Then
            OrderForm = OrderForm & "   Hard Drive" & vbNewLine
        End If

        If memoryCheckBox.Checked Then
            OrderForm = OrderForm & "   Memory" & vbNewLine
        End If

        If soundCheckBox.Checked Then
            OrderForm = OrderForm & "   Sound Card" & vbNewLine
        End If

        If modemCheckBox.Checked Then
            OrderForm = OrderForm & "   Modem" & vbNewLine
        End If

        OrderForm = OrderForm & "Total price: "

        Return OrderForm
    End Function
 
You pass values into functions like this:

Private Function getOrderForm(ByVal strTotalPrice As String) As String

(I'm sure you'll be getting into this later in the class - i.e., passing objects/data into methods (functions) by value vs by reference)


Anyway, with this method signature, now you can just concatenate it on the end :)

OrderForm = OrderForm & "Total price: " & strTotalPrice


... and the last thing is now when you call that getOrderForm method you are required to pass in a string. i.e.,

getOrderForm(strTotalPrice);


..........

Or actually, I see you are using the UI controls for storing a lot of data. (not necessarily a best practice in the long term, but probably OK for this class)

In that case you might be able to just go:

OrderForm = OrderForm & "Total price: " & totalLabel.Text
 
thanks for the help.

yea I'm starting out so we haven't gotten that far into the coding but I'll keep in mind for future projects.

much appreciated!
 
Back
Top