467,075 Members | 1,007 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,075 developers. It's quick & easy.

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
  • viewed: 2080
Share:
2 Replies
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Able | last post: by
2 posts views Thread by Robert Brown | last post: by
5 posts views Thread by kpp9c | last post: by
1 post views Thread by Vishal Bhargava | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.