Small Issue, Needs Urgent help
-
Alright so I am just starting to learn VB and ran into a snag. This assignment is due tomorrow and I cannot format this correctly. In the image bellow, The top running program is my program which is run by the code in the background. The bottom running program is my teachers example of how things SHOULD work. All the formulas and math is correct so no issue there. The two obvious problems is the formatting and decimal placement. I cannot for the life of me figure out how to get the numbers to round to the nearest tenth. As for the formatting I cannot get everything to line up correctly like my teachers. Can anybody help me fix these small issues? I really appreciate any help I can get. Thank you. Also the source Code is placed below the image link
Private Sub btnBill_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBill.Click Dim frmStr As String = "{0,-10}{1,30:N}" Dim cust, d1 As String Dim a, b, sum1, sum2, sum3, sum4 As Double a = CDbl(txtHour.Text) b = CDbl(txtPart.Text) sum1 = a * 35 sum2 = b * 0.05 sum3 = b + sum2 sum4 = sum1 + sum3 cust = txtCust.Text d1 = "$" lstOutput.Items.Clear() lstOutput.Items.Add(String.Format(frmStr, "Customer", cust)) lstOutput.Items.Add(String.Format(frmStr, "Labor Cost", d1 & sum1)) lstOutput.Items.Add(String.Format(frmStr, "Parts Cost", d1 & sum3)) lstOutput.Items.Add(String.Format(frmStr, "Total Cost", d1 & sum4)) End Sub
-
Alright so I am just starting to learn VB and ran into a snag. This assignment is due tomorrow and I cannot format this correctly. In the image bellow, The top running program is my program which is run by the code in the background. The bottom running program is my teachers example of how things SHOULD work. All the formulas and math is correct so no issue there. The two obvious problems is the formatting and decimal placement. I cannot for the life of me figure out how to get the numbers to round to the nearest tenth. As for the formatting I cannot get everything to line up correctly like my teachers. Can anybody help me fix these small issues? I really appreciate any help I can get. Thank you. Also the source Code is placed below the image link
Private Sub btnBill_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBill.Click Dim frmStr As String = "{0,-10}{1,30:N}" Dim cust, d1 As String Dim a, b, sum1, sum2, sum3, sum4 As Double a = CDbl(txtHour.Text) b = CDbl(txtPart.Text) sum1 = a * 35 sum2 = b * 0.05 sum3 = b + sum2 sum4 = sum1 + sum3 cust = txtCust.Text d1 = "$" lstOutput.Items.Clear() lstOutput.Items.Add(String.Format(frmStr, "Customer", cust)) lstOutput.Items.Add(String.Format(frmStr, "Labor Cost", d1 & sum1)) lstOutput.Items.Add(String.Format(frmStr, "Parts Cost", d1 & sum3)) lstOutput.Items.Add(String.Format(frmStr, "Total Cost", d1 & sum4)) End Sub
You're on the right track. What you need to do, is read the documentation on format strings - you can specify the number of decimal places in your format string. And, I assume you can specify the alignment of items in the listview via a property.
Christian Graus Driven to the arms of OSX by Vista.
-
You're on the right track. What you need to do, is read the documentation on format strings - you can specify the number of decimal places in your format string. And, I assume you can specify the alignment of items in the listview via a property.
Christian Graus Driven to the arms of OSX by Vista.
I Figured as much for the decimal Places I just still don't know what property or even where to put it. As for the format, I don't know what property I would use or wear to put it either. Basically with these two I am stuck. Do you know the properties I would need to use and where to put them?
-
Alright so I am just starting to learn VB and ran into a snag. This assignment is due tomorrow and I cannot format this correctly. In the image bellow, The top running program is my program which is run by the code in the background. The bottom running program is my teachers example of how things SHOULD work. All the formulas and math is correct so no issue there. The two obvious problems is the formatting and decimal placement. I cannot for the life of me figure out how to get the numbers to round to the nearest tenth. As for the formatting I cannot get everything to line up correctly like my teachers. Can anybody help me fix these small issues? I really appreciate any help I can get. Thank you. Also the source Code is placed below the image link
Private Sub btnBill_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBill.Click Dim frmStr As String = "{0,-10}{1,30:N}" Dim cust, d1 As String Dim a, b, sum1, sum2, sum3, sum4 As Double a = CDbl(txtHour.Text) b = CDbl(txtPart.Text) sum1 = a * 35 sum2 = b * 0.05 sum3 = b + sum2 sum4 = sum1 + sum3 cust = txtCust.Text d1 = "$" lstOutput.Items.Clear() lstOutput.Items.Add(String.Format(frmStr, "Customer", cust)) lstOutput.Items.Add(String.Format(frmStr, "Labor Cost", d1 & sum1)) lstOutput.Items.Add(String.Format(frmStr, "Parts Cost", d1 & sum3)) lstOutput.Items.Add(String.Format(frmStr, "Total Cost", d1 & sum4)) End Sub
Hi shawndeprey; The code below will correctly format the strings. The other issue you will have is that the font assign to controls by default are not monospace font meaning that each character will have a different width and therefore will never line up. What you need to do is go to the property page for the control and change the font of that control to a monospace font. One such font is Consolas. Once you have made this and the code change it will line up.
' You need two format strings one that has all text
' One that has currency values at the end.
Dim headerStr As String = "{0,-10}{1,30}"
' The C in the format string formats the number in
' currency format, $999.99, no need to add $ to string
Dim frmStr As String = "{0,-10}{1,30:C}"
Dim cust As String
Dim a, b, sum1, sum2, sum3, sum4 As Double
a = CDbl(txtHour.Text)
b = CDbl(txtPart.Text)
sum1 = a * 35
sum2 = b * 0.05
sum3 = b + sum2
sum4 = sum1 + sum3
cust = txtCust.TextlstOutput.Items.Clear()
lstOutput.Items.Add(String.Format(headerStr, "Customer", cust))
lstOutput.Items.Add(String.Format(frmStr, "Labor Cost", sum1))
lstOutput.Items.Add(String.Format(frmStr, "Parts Cost", sum3))
lstOutput.Items.Add(String.Format(frmStr, "Total Cost", sum4))Fernando
-
Hi shawndeprey; The code below will correctly format the strings. The other issue you will have is that the font assign to controls by default are not monospace font meaning that each character will have a different width and therefore will never line up. What you need to do is go to the property page for the control and change the font of that control to a monospace font. One such font is Consolas. Once you have made this and the code change it will line up.
' You need two format strings one that has all text
' One that has currency values at the end.
Dim headerStr As String = "{0,-10}{1,30}"
' The C in the format string formats the number in
' currency format, $999.99, no need to add $ to string
Dim frmStr As String = "{0,-10}{1,30:C}"
Dim cust As String
Dim a, b, sum1, sum2, sum3, sum4 As Double
a = CDbl(txtHour.Text)
b = CDbl(txtPart.Text)
sum1 = a * 35
sum2 = b * 0.05
sum3 = b + sum2
sum4 = sum1 + sum3
cust = txtCust.TextlstOutput.Items.Clear()
lstOutput.Items.Add(String.Format(headerStr, "Customer", cust))
lstOutput.Items.Add(String.Format(frmStr, "Labor Cost", sum1))
lstOutput.Items.Add(String.Format(frmStr, "Parts Cost", sum3))
lstOutput.Items.Add(String.Format(frmStr, "Total Cost", sum4))Fernando
PERFECT!!! I changed to font to Courier New and presto! Thanks Bunches Fernando. :-D
-
PERFECT!!! I changed to font to Courier New and presto! Thanks Bunches Fernando. :-D
Not a problem, glad I was able to help. :thumbsup: