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

  • Thread starter Thread starter D. Shane Fowlkes
  • Start date Start date
D

D. Shane Fowlkes

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/downloads/selectedcat.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
 
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
 
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.
 
Back
Top