Announcement

Collapse
No announcement yet.

Visual Basic noob

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Visual Basic noob

    We have a regular need to calculate a customers selling price based on the cost to them to return a specified gross margin. The mathematically challenged in the office struggle with this so I decided, as you do, to download Visual Basic Express and create a windows application for them to use.

    Amazingly, 1 hour later (considering my last programming experience was 25 years ago and only managed to get my name to scroll across the screen) I have it working but the results are showing to 9 decimal places!

    The code I have created so far is:

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
    RESULTS.Text = Val(COSTPRICE.Text) / Val(1 - (PERCENTAGE.Text / 100))
    
    End Sub
    Using 2 text boxes for the input and 1 text box for the result.

    How can I get it to return to 2 decimal places? I have seen Format$('n', 'Currency') but no idea how to implement... or is there a better solution?

    TIA

    Jonty


    Bikster
    SellerDeck Designs and Responsive Themes

    #2
    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
    RESULTS.Text = Math.Round(Val(COSTPRICE.Text) / Val(1 - (PERCENTAGE.Text / 100)), 2)
    
    End Sub
    Format$(n,Currency) would give you a result inluding the currency symbol defined in the user settings, so US users would see $ and UK £ etc.

    Math.Round will give you just the figures.
    Bill
    www.egyptianwonders.co.uk
    Text directoryWorldwide Actinic(TM) shops
    BC Ness Solutions Support services, custom software
    Registered Microsoft™ Partner (ISV)
    VoIP UK: 0131 208 0605
    Located: Alexandria, EGYPT

    Comment


      #3
      You'd probably be quicker and easier using a 'goal seek' in excel. If you have a field that needs to show 33% for example, you give it the two (or more) fields it needs to use to work this out and it will adjust a given cell so that 33% ends up in the given cell. I have an excel spreadsheet already setup if you want it, which is for working these out, it also does a forward or reverse vat calculation.

      Comment


        #4
        Originally posted by wjcampbe
        Math.Round will give you just the figures.
        That's just the ticket, cheers Bill

        This forum never ceases to amaze.


        Bikster
        SellerDeck Designs and Responsive Themes

        Comment


          #5
          Originally posted by leehack
          You'd probably be quicker and easier using a 'goal seek' in excel.
          Yeah, but it's me don't forget I have loads of sheets set up for other calcs but fancied trying something completely new for a change.. hence Visual Basic.. nothing like a completely alien application to test the brain cells.

          I now have a nice little standalone windows application which does exactly what it says on the tin.


          Bikster
          SellerDeck Designs and Responsive Themes

          Comment

          Working...
          X