Results 1 to 23 of 23

Thread: [RESOLVED] HELP!! Assistance with Code for a program

  1. #1
    Member
    Join Date
    Sep 12
    Posts
    35

    Resolved [RESOLVED] HELP!! Assistance with Code for a program

    I need to create a code that will do as follows:

    When a user clicks the Display button in my form it will need to prompt the user to enter in the date of the services. Store the information into a variable called service_date. Display the date and the date the invoice is due (30 days from the date entered) in the listbox I have already created. Store the due date in a variable called due_date.

    Thanks,

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,533

    Re: HELP!! Assistance with Code for a program

    You'll be wanting a DateTimePicker then.

  3. #3
    Member
    Join Date
    Sep 12
    Posts
    35

    Re: HELP!! Assistance with Code for a program

    Would this be built under the button as a mouse click option?

  4. #4
    Member
    Join Date
    Sep 12
    Posts
    35

    Re: HELP!! Assistance with Code for a program

    This is the code I am trying to use. Let me know if I am way off:

    I would put this code under the button Display mouse click option:

    Private Sub btnDisplay_Click (...) Handles btnDisplay.Click
    Dim Service_Date As String
    Prompt = "Date of Service."

    ??

  5. #5
    Frenzied Member
    Join Date
    Sep 06
    Posts
    1,255

    Re: HELP!! Assistance with Code for a program

    Try this
    Code:
        Private Sub cmdDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDisplay.Click
            Dim strDate As String = InputBox("Please enter the date of the service.")
            If strDate <> "" Then
                Dim service_date As Date = CDate(strDate)
                Dim due_date As Date = service_date.AddDays(30)
                ListBox1.Items.Add(service_date)
                ListBox1.Items.Add(due_date)
            End If
        End Sub
    You may design a form contain DateTimePicker control to let the user choose the date instead of input it via the ugly InputBox.

  6. #6
    Member
    Join Date
    Sep 12
    Posts
    35

    Re: HELP!! Assistance with Code for a program

    I just looked on you tube at the datetimepicker and that is not what I am trying to do. Basically I need to click my display button I created and a enter service date box should pop up requesting the user to enter the current day as the service date, and after that both the service date and 30 days out should appear in my list box.

  7. #7
    Member
    Join Date
    Sep 12
    Posts
    35

    Re: HELP!! Assistance with Code for a program

    4X2Y I got an error code with: cmdDisplay.Click

    says: Handles Clause required a WithEvents Variable defined in the containing type or one of its base types.

    Is that asking me to create the variable service_date or due_date? I have to create variables for both to store the data...

  8. #8
    Frenzied Member
    Join Date
    Sep 06
    Posts
    1,255

    Re: HELP!! Assistance with Code for a program

    I named the button here as cmdDisplay, so just take the code and put it under your button's click event
    Code:
            Dim strDate As String = InputBox("Please enter the date of the service.")
            If strDate <> "" Then
                Dim service_date As Date = CDate(strDate)
                Dim due_date As Date = service_date.AddDays(30)
                ListBox1.Items.Add(service_date)
                ListBox1.Items.Add(due_date)
            End If

  9. #9
    Member
    Join Date
    Sep 12
    Posts
    35

    Re: HELP!! Assistance with Code for a program

    Holy goodness It worked, however when the date appears it should have Service Date: and Invoice Date: that appears before the actual dates.What do I alter to get that to appear..Dang you rock!

  10. #10
    Frenzied Member
    Join Date
    Sep 06
    Posts
    1,255

    Re: HELP!! Assistance with Code for a program

    If i understood well, just re-arrange the command ListBox1.Items.Add to meet the date order you want, e.g.
    Code:
    ListBox1.Items.Add(service_date)
                ListBox1.Items.Add(due_date)
    or
    Code:
    ListBox1.Items.Add(due_date)
                ListBox1.Items.Add(service_date)

  11. #11
    Member
    Join Date
    Sep 12
    Posts
    35

    Re: HELP!! Assistance with Code for a program

    My list box should look like the following when I click the Display Bill Button:


    Label Name from the Form Text Box Information (information the customer puts in)

    Customer: (TextBox1)
    Phone Number: (mtbPhone)
    Service Date: (date entered from clicking the display button in the form of 1/1/2012)
    Invoice Due: (date entered 30 days from the service date entered)
    Labor Cost: ($35.00 an hour for labor x number of hours entered into the TextBox2)
    Parts and Supplies Cost: (5% sales tax added on to the TextBox3 entry)
    Total Cost: (The total cost between the Labor Cost and Parts and Supplies)

    I used the information for my text boxes...But that is how my list box is supposed to look when I click the display bill button

  12. #12
    Frenzied Member
    Join Date
    Sep 06
    Posts
    1,255

    Re: HELP!! Assistance with Code for a program

    Where is the problem! just add items to the listbox in the same order you want they look, e.g.
    Code:
            Dim strDate As String = InputBox("Please enter the date of the service.")
            If strDate <> "" Then
                Dim service_date As Date = CDate(strDate)
                Dim due_date As Date = service_date.AddDays(30)
    
                ListBox1.Items.Clear() ' Delete this line if you want to append new inputs to previous inputs.
                ListBox1.Items.Add("Customer: " & TextBox1.Text)
                ListBox1.Items.Add("Phone Number: " & mtbPhone)
                ListBox1.Items.Add("Service Date: " & service_date.ToString("dd/mm/yyyy"))
                ListBox1.Items.Add("Invoice Due: " & due_date.ToString("dd/mm/yyyy"))
                ' Add as many as item you need.
            End If

  13. #13
    Member
    Join Date
    Sep 12
    Posts
    35

    Re: HELP!! Assistance with Code for a program

    This is a masked text box, and the format is not putting the telephone number in the list box:
    ListBox1.Items.Add("Phone Number: " & mtbPhone)
    It returned an error saying the & was wrong so I changed it to look like:
    lstBill.Items.Add("Phone Number: ") ')', mtbPhone)

    There is no error now, but the only thing that will populate is the Phone Number words, with no phone number

  14. #14
    Frenzied Member
    Join Date
    Sep 06
    Posts
    1,255

    Re: HELP!! Assistance with Code for a program

    What the type of mtbPhone?

  15. #15
    Member
    Join Date
    Sep 12
    Posts
    35

    Re: HELP!! Assistance with Code for a program

    Its a masked text box, and the name of it is mtbPhone. The text box allows the following format for the phone number 000-0000. In the text box I put in the phone number 333-0000 for example, but the code above isn't allowing the information to be input into the list box when the display button is clicked.

  16. #16
    Frenzied Member
    Join Date
    Sep 06
    Posts
    1,255

    Re: HELP!! Assistance with Code for a program

    Replace ListBox1.Items.Add("Phone Number: " & mtbPhone) with ListBox1.Items.Add("Phone Number: " & mtbPhone.Text)

  17. #17
    Member
    Join Date
    Sep 12
    Posts
    35

    Re: HELP!! Assistance with Code for a program

    the .text is what is killing me on the codes. That surely worked:

    to get TextBox2 to show in the list box: There has to be an equation that charges $35.00 for labor, and will multiply the $35.00 with what the person will put into the TextBox2:

    lstBill.Items.Add("Labor Cost: " & TextBox2.Text)(35*TextBox2.txt)

  18. #18
    Frenzied Member
    Join Date
    Sep 06
    Posts
    1,255

    Re: HELP!! Assistance with Code for a program

    Convert TextBox2.Text to proper type before multiply, e.g. lstBill.Items.Add("Labor Cost: " & 35 * CSng(TextBox2.Text))

  19. #19
    Member
    Join Date
    Sep 12
    Posts
    35

    Re: HELP!! Assistance with Code for a program

    To get the totals of both the Labor Cost and the Parts and Labor:

    lstBill.Items.Add("Total Cost: " & 35 * CSng(TextBox2.Text)) & + 0.5 * CSng(TextBox3.Text))

    Does that look right? I am getting an error saying end of statement required, but in the end I need it to total the amounts in the list generated from the text boxes.

  20. #20
    Frenzied Member
    Join Date
    Sep 06
    Posts
    1,255

    Re: HELP!! Assistance with Code for a program

    Try this
    Code:
    lstBill.Items.Add("Total Cost: " & (35 * CSng(TextBox2.Text)) + (0.5 * CSng(TextBox3.Text)))

  21. #21
    Member
    Join Date
    Sep 12
    Posts
    35

    Re: HELP!! Assistance with Code for a program

    For the customer name, how can I ensure that the name converts to all uppercase when displayed in the list box?

    lstBill.Items.Add("Customer: " & TextBox1.Text)

    How can I use the currency when dealing with these three lines:
    Currency must look like: $000.00

    lstBill.Items.Add("Labor Cost: " & 35 * CSng(TextBox2.Text))
    lstBill.Items.Add("Parts and Supply Cost: " & 0.5 * CSng(TextBox3.Text))
    lstBill.Items.Add("Total Cost: " & (35 * CSng(TextBox2.Text)) + (0.5 * CSng(TextBox3.Text)))

  22. #22
    Frenzied Member
    Join Date
    Sep 06
    Posts
    1,255

    Re: HELP!! Assistance with Code for a program

    You need to read more about Format function
    Code:
    lstBill.Items.Add("Total Cost: " & Format((35 * CSng(TextBox1.Text)) + (0.5 * CSng(TextBox2.Text)), "$###.##"))

  23. #23
    Member
    Join Date
    Sep 12
    Posts
    35

    Re: HELP!! Assistance with Code for a program

    THe above code would not work. When trying to run the program it gave;

    A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll

    I opened the exception helper and Conversion from string Amanda Lee to type single is not valid

    ??

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •