Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Small Issue, Needs Urgent help

Small Issue, Needs Urgent help

Scheduled Pinned Locked Moved Visual Basic
helptutorialcomsalesquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shawndeprey
    wrote on last edited by
    #1

    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 issue 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

    C F 2 Replies Last reply
    0
    • S shawndeprey

      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 issue 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

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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.

      S 1 Reply Last reply
      0
      • C Christian Graus

        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.

        S Offline
        S Offline
        shawndeprey
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • S shawndeprey

          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 issue 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

          F Offline
          F Offline
          Fernando Soto
          wrote on last edited by
          #4

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

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

          S 1 Reply Last reply
          0
          • F Fernando Soto

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

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

            S Offline
            S Offline
            shawndeprey
            wrote on last edited by
            #5

            PERFECT!!! I changed to font to Courier New and presto! Thanks Bunches Fernando. :-D

            F 1 Reply Last reply
            0
            • S shawndeprey

              PERFECT!!! I changed to font to Courier New and presto! Thanks Bunches Fernando. :-D

              F Offline
              F Offline
              Fernando Soto
              wrote on last edited by
              #6

              Not a problem, glad I was able to help. :thumbsup:

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups