+ Reply to Thread
Results 1 to 6 of 6

Calculate internet usage

  1. #1
    Registered User
    Join Date
    05-13-2009
    Location
    cambodia
    MS-Off Ver
    Excel 2003
    Posts
    2

    Exclamation Calculate internet usage

    Hello all,

    I am working on code to create calculation of internet usage at internet cafe. My code does not show well the total fee.

    Here is the following text box that i created in my form

    1- Start time
    2- End time
    3- Duration = End time - Start time
    4- Total Fee = Duration * hour fee

    Please help me to correct my code, I also enclosed it in this post.

    Thanks
    Attached Files Attached Files
    Last edited by boy_0708; 05-13-2009 at 10:51 AM.

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    re: Calculate internet usage

    Hi there,

    The basic problem is that you're trying to perform arithmetic calculations using string values. The following code seems to do what you require:

    Please Login or Register  to view this content.
    Note: in the highlighted line
    Please Login or Register  to view this content.
    your original code showed a * operator, but the operator you need is /.

    Hope this helps - please let me know how you get on.

    Regards,

    Greg M

  3. #3
    Registered User
    Join Date
    05-13-2009
    Location
    cambodia
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Calculate internet usage

    Hi Greg,

    Thanks so much for your help. By the way, I don't understand why you devise txtDuration with 1440 ? ex: TimeValue(txtDuration) <= 15 / 1440

    Is there another way to convert txtDuration to only number of minutes ?

    Thanks again.

    Regards,

  4. #4
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: Calculate internet usage

    Hi again,

    Any time value in Excel lies in the range 0 to 1 - e.g.:
    06:00 = 0.25
    12:00 = 0.50
    18:00 = 0.75
    This means that the time value for one hour is 1 / 24 (the number of hours in a day) and the time value for one minute is 1 / 1440 (the total number of minutes in a day).

    Your textbox txtDuration contains a string, e.g. "00:36", so you cannot perform any arithmetic calculations with it. You convert it to an arithmetic value by using the "TimeValue" function which gives a value of 0.0025. This value is greater than 30 / 1440 and less than 60 / 1440, so it corresponds to the duration range 30 - 60 minutes.

    I think the following code might be a bit neater than the previous version (although it does exactly the same thing!):
    Please Login or Register  to view this content.
    I hope this is of some assistance to you - please let me know if you need any other information.

    Regards,

    Greg M

  5. #5
    Registered User
    Join Date
    12-18-2012
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: Calculate internet usage

    Hey !!

    Need help !!

    I downloaded this calculator...but got a blank excel sheet

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Calculate internet usage

    Saurabh,

    This is an old thread, so its better if you create a new thread for yourself.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1