Results 1 to 7 of 7

Thread: How to divide numbers

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    How to divide numbers

    Hi guys does anybody know how i can make it divide the numbers put in text1 and text 2?

    for example

    text 1 = 100
    text 2 = 4

    when command1 is pressed it then divides text1 by text2


    any ideas?

    thanks
    Jamie

  2. #2
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: How to divide numbers

    Code:
    Dim dblResult As Double
    dblResult = Val(Text1.Text) / Val(Text2.Text)



  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Re: How to divide numbers

    fantastic thank you, by anychance do you know how i can make it choose the number to divide it by automatically?

    Basically i have 2 dtpicker boxes and a user selects 2 diffrent dates, is it possible to make it divide it by the number of different days?

    For example dtpicker1 = 08/04/2012 and dtpicker2 = 10/04/2012

    it will know to divide it by 2 as thats the day difference?

    Thanks
    Jamie

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: How to divide numbers

    Use the DateDiff function to find out the amount of days

  5. #5
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: How to divide numbers

    Try this
    Code:
        Dim dblResult As Double
        dblResult = Val(Text1.Text) / DateDiff("d", "08/04/2012", "10/04/2012") ' Replace dates with dtpicker1 & dtpicker2



  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Re: How to divide numbers

    Hi mate,

    For some reason the code you provided is not returning any values, so it is just displaying empty results and not actually showing any numbers.

    Any ideas?

  7. #7
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: How to divide numbers

    The returning value is stored in the variable dblResult, so you have to show it in a control like Text box or Label, e.g.

    Text2.Text = CStr(dblResult)



Posting Permissions

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



Click Here to Expand Forum to Full Width