|
-
Sep 2nd, 2012, 05:27 PM
#1
Thread Starter
Member
[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,
-
Sep 2nd, 2012, 05:41 PM
#2
Re: HELP!! Assistance with Code for a program
You'll be wanting a DateTimePicker then.
-
Sep 2nd, 2012, 05:43 PM
#3
Thread Starter
Member
Re: HELP!! Assistance with Code for a program
Would this be built under the button as a mouse click option?
-
Sep 2nd, 2012, 05:52 PM
#4
Thread Starter
Member
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."
??
-
Sep 2nd, 2012, 05:54 PM
#5
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.
-
Sep 2nd, 2012, 05:58 PM
#6
Thread Starter
Member
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.
-
Sep 2nd, 2012, 06:07 PM
#7
Thread Starter
Member
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...
-
Sep 2nd, 2012, 06:11 PM
#8
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
-
Sep 2nd, 2012, 06:17 PM
#9
Thread Starter
Member
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!
-
Sep 2nd, 2012, 06:23 PM
#10
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)
-
Sep 2nd, 2012, 06:42 PM
#11
Thread Starter
Member
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
-
Sep 2nd, 2012, 06:56 PM
#12
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
-
Sep 2nd, 2012, 07:18 PM
#13
Thread Starter
Member
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
-
Sep 2nd, 2012, 07:27 PM
#14
Re: HELP!! Assistance with Code for a program
What the type of mtbPhone?
-
Sep 2nd, 2012, 07:32 PM
#15
Thread Starter
Member
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.
-
Sep 2nd, 2012, 07:37 PM
#16
Re: HELP!! Assistance with Code for a program
Replace ListBox1.Items.Add("Phone Number: " & mtbPhone) with ListBox1.Items.Add("Phone Number: " & mtbPhone.Text)
-
Sep 2nd, 2012, 08:01 PM
#17
Thread Starter
Member
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)
-
Sep 2nd, 2012, 08:21 PM
#18
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))
-
Sep 2nd, 2012, 08:32 PM
#19
Thread Starter
Member
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.
-
Sep 2nd, 2012, 08:36 PM
#20
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)))
-
Sep 2nd, 2012, 08:50 PM
#21
Thread Starter
Member
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)))
-
Sep 2nd, 2012, 09:06 PM
#22
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)), "$###.##"))
-
Sep 2nd, 2012, 09:16 PM
#23
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|