473,320 Members | 1,802 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Help with Function - converting a double num into a hh:mm:ss format

Here's a good one. I've been using an Excel spreadsheet for the past couple
of years to calculate a file's Estimated Download Time based off of a solid
50kbs connection (dial up). This is for a downloads page such as:

http://www.drpt.virginia.gov/downloa...cat.aspx?ID=12

The formula is basically this:
=(((C4*1000*8)/50000)/84600)*1.1

(Estimate is calculated on a modem dial up connection of 50Kbs and transfer
loss of 10% due to the modulation and demodulation that modems must perform
with a dial up connection.)

"C4" would be where I plug in the KB size such as "482" and it gives me a
estimated download time of 1:27 (mm:ss). The cell that returns this is
formatted as time.

Now, I'm trying to write a VB.NET (ASP) function that calculates this for me
when the record is automatically inserted in the table. The field that holds
this "EDT" is simply a text field and I've alway manually calculated this
with the Excel file and typed it in.
I've tried the Function below but not having a lot of luck. Not getting
errors...just no conversion seems to work. If I KEEP the
ToString("hh:mm:ss:), I literally get "hh:mm:ss: inserted into the database.
If I remove it and simply Return dblEDT, I get " 0.000128183026004728" for a
file size of 482KB.

Does any of this make sense? Any sugguestions?


Function CalculateDownloadTime(intFileSize As Integer) As String

' Estimate is calculated on a modem dial up connection of 50Kbs and transfer
loss
' of 10% due to the modulation and demodulation that modems must perform
with
' a dial up connection.

Dim dblEDT As Double

dblEDT = (((intFileSize)/50000)/84600)*1.1

Return dblEDT.ToString("hh:mm:ss")

End Function
Nov 19 '05 #1
2 2460
Not sure exactly where you are getting the 84600 from, but you can't use the
Double.ToString() to perform the type of formatting you want to accomplish.
You should just do it by hand.

Function CalculateDownloadTime(ByVal size As Integer) As String

Dim d As Double

d = (size * 8 / 50000) * 1.1

Dim s As String
s = CType(d / 3600, Integer).ToString("##':'").PadLeft(3, CType("0",
Char))
d = d Mod 3600
s = s + CType(d / 60, Integer).ToString("##':'").PadLeft(3, CType("0",
Char))
d = d Mod 60
s = s + CType(d, Integer).ToString("##")
Return s
End Function

bill

"D. Shane Fowlkes" <sh**********@h-o-t-m-a-i-l.com> wrote in message
news:Oj**************@TK2MSFTNGP11.phx.gbl...
Here's a good one. I've been using an Excel spreadsheet for the past couple of years to calculate a file's Estimated Download Time based off of a solid 50kbs connection (dial up). This is for a downloads page such as:

http://www.drpt.virginia.gov/downloa...cat.aspx?ID=12

The formula is basically this:
=(((C4*1000*8)/50000)/84600)*1.1

(Estimate is calculated on a modem dial up connection of 50Kbs and transfer loss of 10% due to the modulation and demodulation that modems must perform with a dial up connection.)

"C4" would be where I plug in the KB size such as "482" and it gives me a
estimated download time of 1:27 (mm:ss). The cell that returns this is
formatted as time.

Now, I'm trying to write a VB.NET (ASP) function that calculates this for me when the record is automatically inserted in the table. The field that holds this "EDT" is simply a text field and I've alway manually calculated this
with the Excel file and typed it in.
I've tried the Function below but not having a lot of luck. Not getting
errors...just no conversion seems to work. If I KEEP the
ToString("hh:mm:ss:), I literally get "hh:mm:ss: inserted into the database. If I remove it and simply Return dblEDT, I get " 0.000128183026004728" for a file size of 482KB.

Does any of this make sense? Any sugguestions?


Function CalculateDownloadTime(intFileSize As Integer) As String

' Estimate is calculated on a modem dial up connection of 50Kbs and transfer loss
' of 10% due to the modulation and demodulation that modems must perform
with
' a dial up connection.

Dim dblEDT As Double

dblEDT = (((intFileSize)/50000)/84600)*1.1

Return dblEDT.ToString("hh:mm:ss")

End Function

Nov 19 '05 #2
Thanks...I'll try your solution and see what happens. The 84600 is second
in a day. I needed this to figure out how seconds it took to download X bits
of data.


"William F. Robertson, Jr." <theman_at_fdrsucks.com> wrote in message
news:OA**************@TK2MSFTNGP10.phx.gbl...
Not sure exactly where you are getting the 84600 from, but you can't use
the
Double.ToString() to perform the type of formatting you want to
accomplish.
You should just do it by hand.

Function CalculateDownloadTime(ByVal size As Integer) As String

Dim d As Double

d = (size * 8 / 50000) * 1.1

Dim s As String
s = CType(d / 3600, Integer).ToString("##':'").PadLeft(3, CType("0",
Char))
d = d Mod 3600
s = s + CType(d / 60, Integer).ToString("##':'").PadLeft(3, CType("0",
Char))
d = d Mod 60
s = s + CType(d, Integer).ToString("##")
Return s
End Function

bill

"D. Shane Fowlkes" <sh**********@h-o-t-m-a-i-l.com> wrote in message
news:Oj**************@TK2MSFTNGP11.phx.gbl...
Here's a good one. I've been using an Excel spreadsheet for the past

couple
of years to calculate a file's Estimated Download Time based off of a

solid
50kbs connection (dial up). This is for a downloads page such as:

http://www.drpt.virginia.gov/downloa...cat.aspx?ID=12

The formula is basically this:
=(((C4*1000*8)/50000)/84600)*1.1

(Estimate is calculated on a modem dial up connection of 50Kbs and

transfer
loss of 10% due to the modulation and demodulation that modems must

perform
with a dial up connection.)

"C4" would be where I plug in the KB size such as "482" and it gives me a
estimated download time of 1:27 (mm:ss). The cell that returns this is
formatted as time.

Now, I'm trying to write a VB.NET (ASP) function that calculates this for

me
when the record is automatically inserted in the table. The field that

holds
this "EDT" is simply a text field and I've alway manually calculated this
with the Excel file and typed it in.
I've tried the Function below but not having a lot of luck. Not getting
errors...just no conversion seems to work. If I KEEP the
ToString("hh:mm:ss:), I literally get "hh:mm:ss: inserted into the

database.
If I remove it and simply Return dblEDT, I get " 0.000128183026004728"
for

a
file size of 482KB.

Does any of this make sense? Any sugguestions?


Function CalculateDownloadTime(intFileSize As Integer) As String

' Estimate is calculated on a modem dial up connection of 50Kbs and

transfer
loss
' of 10% due to the modulation and demodulation that modems must perform
with
' a dial up connection.

Dim dblEDT As Double

dblEDT = (((intFileSize)/50000)/84600)*1.1

Return dblEDT.ToString("hh:mm:ss")

End Function


Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: KathyB | last post by:
Hi, not too swift with anything other than simple SQL statements, so I'm looking for some help. Using SQL Server 2000 with this stored proc: (@varCust varchar(50)) AS SET NOCOUNT ON
6
by: Able | last post by:
Dear friends I need to format seconds as hh:mm:ss. I see a lot of coding transforming seconds to hh:mm:ss. Somebody know a short way? Regards Able
2
by: Robert Brown | last post by:
Hi all. I have written a program that transfers data via FTP. I can calculate the rough amount of time left. I get a value such as 70.83 seconds left for instance. What I want to do is to...
4
by: Rich | last post by:
Now.ToShortTimeString returns 9:13 PM. I would like to get this in miliatry time with seconds included 21:13:45 (or something like that - just military time with seconds). How can this be...
1
by: Jason Chan | last post by:
DateTime mydate = new DateTime(2006,1,1,0,0,0); string testStr = mydate.ToString("hh:mm:ss"); //return 12:00:00 mydate = new DateTime(2006,1,1,1,0,0) testStr = mydate.ToString("hh:mm:ss");...
5
by: kpp9c | last post by:
Hi, I was looking at python & datetime and hoping that it would already have a method/func to translate time formats. I need to translate seconds to hh:mm:ss.ms and vice versa and would like...
1
by: Vishal Bhargava | last post by:
Is there an inbuilt library in Python which you can use to convert time in seconds to hh:mm:ss format? Thanks, Vishal
1
by: unknown66 | last post by:
hello, I have a time value in unix time that I would like to convert into a time format of hh:mm:ss:ms. For example, I have this number, 1172234138451, that I would like to be in the hh:mm:ss:ms...
1
seshu
by: seshu | last post by:
Hi every body to morning my cousine has show his application and also his live db in that to sav the length of all the voice files he has saved in time format ie he took the datatype of time now i...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.