• Welcome to Valhalla Legends Archive.
 

Whats wrong with this?

Started by Gandalf, February 07, 2004, 11:02 PM

Previous topic - Next topic

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

UserLoser.

Isn't necessarly bot related, and you posted this somewhere else

Gandalf

#2
Quote from: UserLoser. on February 07, 2004, 11:04 PM
Isn't necessarly bot related, and you posted this somewhere else
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.)

Grok

#3
Quote from: Gandalf on February 07, 2004, 11:02 PM
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

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.


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

iago

Quote from: Gandalf on February 07, 2004, 11:08 PM
Quote from: UserLoser. on February 07, 2004, 11:04 PM
Isn't necessarly bot related, and you posted this somewhere else
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.)

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.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


MyndFyre

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:


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

(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
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Grok

This also works:


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

Gandalf

Well,  sorry, i wont post any not related post in this topic, and thnx for the code.