Valhalla Legends Forums Archive | Visual Basic Programming | Whats wrong with this?

AuthorMessageTime
Gandalf
Private Function ReturnDHMS(iSec1 As Single) As String

Dim iMin As Single
Dim iHrs As Single
Dim iDay As Single
Dim iSec As Single

iSec = iSec1

iHrs = (iMin \ 60)
iMin = (iSec \ 60)
iSec = (iSec Mod 60)

If iHrs >= 24 Then
iDay = iHrs \ 24
iHrs = iHrs Mod 24
End If

ReturnDHMS = "Day:" & Str(iDay) & " Hrs:" & Str(iHrs) & " Min: " & Str(iMin) & " Sec: " & Str(iSec)

End Function
February 8, 2004, 5:02 AM
UserLoser.
Isn't necessarly bot related, and you posted this somewhere else
February 8, 2004, 5:04 AM
Gandalf
[quote author=UserLoser. link=board=17;threadid=5165;start=0#msg43062 date=1076216686]
Isn't necessarly bot related, and you posted this somewhere else
[/quote]
Well, im sure this can help some people doing some stuff related with bots and 2nd, if this isnt a Bot Related Topic why did u bother answering, if u going to answer u could help instead of telling people that they wrong. (When u get your own Forum Running i will do what u want me to do, but sorry this is not ur forum.)
February 8, 2004, 5:08 AM
Grok
[quote author=Gandalf link=board=17;threadid=5165;start=0#msg43061 date=1076216570]
Private Function ReturnDHMS(iSec1 As Single) As String

Dim iMin As Single
Dim iHrs As Single
Dim iDay As Single
Dim iSec As Single

iSec = iSec1

iHrs = (iMin \ 60)
iMin = (iSec \ 60)
iSec = (iSec Mod 60)

If iHrs >= 24 Then
iDay = iHrs \ 24
iHrs = iHrs Mod 24
End If

ReturnDHMS = "Day:" & Str(iDay) & " Hrs:" & Str(iHrs) & " Min: " & Str(iMin) & " Sec: " & Str(iSec)

End Function
[/quote]

Why are you using integer division with Single operands? Plus, what's your question? You didn't state a problem.

Nevermind, I see the problem. The value of iMin is still 0 when you're calculating iHrs. Those lines are upside down.

[code]
Private Function ReturnDHMS(iSec1 As Single) As String

Dim d As Long, h As Long, m As Long, s As Long

s = iSec1 Mod 60&
iSec1 = iSec1 - s
m = (iSec1 Mod 3600&) \ 60&
iSec1 = iSec1 - 60& * m
h = (iSec1 Mod 86400) \ 3600&
iSec1 = iSec1 - 3600& * h
d = iSec1 \ 86400

ReturnDHMS = "Days: " & Str(d) & " Hrs:" & Str(h) & " Min: " & Str(m) & " Sec: " & Str(s)

End Function
[/code]
February 8, 2004, 5:19 AM
iago
[quote author=Gandalf link=board=17;threadid=5165;start=0#msg43063 date=1076216899]
[quote author=UserLoser. link=board=17;threadid=5165;start=0#msg43062 date=1076216686]
Isn't necessarly bot related, and you posted this somewhere else
[/quote]
Well, im sure this can help some people doing some stuff related with bots and 2nd, if this isnt a Bot Related Topic why did u bother answering, if u going to answer u could help instead of telling people that they wrong. (When u get your own Forum Running i will do what u want me to do, but sorry this is not ur forum.)
[/quote]

you'll find you get more help if your polite. Although he doesn't run the forum, UserLoser is a fairly respected regular here and knows the ropes.
February 8, 2004, 5:50 AM
Myndfyr
Two suggestions.

First, this code was already in another topic. You only need to ask once; most of us who are here regularly read up on each topic when it's new -- at least glancing at it.

Second, when you post code, use the [ code ] and [ / code ] brackets to make it monotype and a different color:

[code]
Private Function ReturnDHMS(iSec1 As Single) As String

Dim d As Long, h As Long, m As Long, s As Long

s = iSec1 Mod 60&
iSec1 = iSec1 - s
m = (iSec1 Mod 3600&) \ 60&
iSec1 = iSec1 - 60& * m
h = (iSec1 Mod 86400) \ 3600&
iSec1 = iSec1 - 3600& * h
d = iSec1 \ 86400

ReturnDHMS = "Days: " & Str(d) & " Hrs:" & Str(h) & " Min: " & Str(m) & " Sec: " & Str(s)

End Function
[/code]
(Grok's correct code)

I believe these guidelines are in the forum rules, and it's more or less courteous and customary to post this way.

Anyway, if you want to continue to take advantage of the expertise and willingness to help here, I'd suggest you follow suit. As iago pointed out, people like UserLoser, who really know what they're doing, are much more apt to really help you out if you follow the guidelines set forth by the people who run the forums.

And - to complete UserLoser's suggestion - this would be a really great topic for the Visual Basic forum.

Cheers
February 8, 2004, 8:42 AM
Grok
This also works:

[code]
Private Function ReturnDHMS(iSec1 As Single) As String

Dim d As Long, h As Long, m As Long, s As Long

s = iSec1 Mod 60&
m = (iSec1 \ 60) Mod 60
h = (iSec1 \ 3600) Mod 24
d = iSec1 \ 86400

ReturnDHMS = "Days: " & Str(d) & " Hrs:" & Str(h) & " Min: " & Str(m) & " Sec: " & Str(s)

End Function
[/code]
February 8, 2004, 10:39 AM
Gandalf
Well, sorry, i wont post any not related post in this topic, and thnx for the code.
February 8, 2004, 2:55 PM

Search