|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I think i have found a bug in vb6.
when i call this procedure in a loop over and over again somethings goes wrong... Totaltime increases with 0.2 after every loop, having a startvalue of 29,9 and a endvalue of 35,1. When Totaltime is 31.5, Seconds should be 32, BUT Seconds becomes 31. If you run this code only once Seconds becomes 32 (which it should be) What could be wrong?? Public Totaltime As Double Public Minutes As Double Public Seconds As Double Public hundredth As Long '---------------------------- Do Until Totaltime=35.1 RaknaVarvtid Totaltime=Totaltime+0.2 Loop '------------------------------- Public Sub RaknaVarvtid() Minutes = Int(Totaltid / 60) Minutes = Minutesr Mod 60 Seconds = Int(Totaltime Mod 60) Seconds should become 32 here hundredth = Totaltime * 100 hundredth = Hundreds Mod 100 End Sub I think it´s the Mod or Int() function that is the problem. I´ve tried the Round() function to...: Seconds=Round(Totaltime) ...and in that case the same thing happens, Seconds become 31 instead of 32. Use this code in a Vb-project and see for yourself. Last edited by John42 : December 31st, 2003 at 11:29 AM. |
|
#2
|
||||
|
||||
|
I don't know that this would be a bug, but more in the way that VB handles the int() function. However, I'm not clear on the code that you posted. Can you include a more complete listing?
__________________
Fisherman "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - A.Einstein |
|
#3
|
|||
|
|||
|
it will be cause by some type transfer!Because the integer variable is stored in 16 bit space in x86 platform,but a single variable or double variable is stored in 2-4 times as the integer variable..When u run "/" operation,u will get a bigger space as a single or double variable.When u run int function,u will transfer the bigger space to be stored in a smaller space in the memory!Some decimal fraction information will be lost in this transfr period..
|
|
#4
|
|||
|
|||
|
Quote:
Ok, i´m not sure i follow . So do i need to change the type of variable i´m using or get more memory? |
|
#5
|
||||
|
||||
|
a question = your variable named Seconds... why do you have it declared as "Double"? If you're using the int() function to find the value of Seconds, then wouldn't dimming the variable as Integer be appropriate?
|
|
#6
|
|||
|
|||
|
Yes,As Fisherman said..It's my meaning..
|
|
#7
|
|||
|
|||
|
I´v declared Seconds and all the other variables, exept Totaltime wich is declared as Single, as integers, but the problem is not yet fixed
![]() |
|
#8
|
|||
|
|||
|
Int() rounds down always. Int(x.y) always returns x. What dou want to happen? If you want it to round UP then use CInt() CInt(2.7)=3
The problem then is that the part after the decimal has to be greater than .5 before it will round up eg CInt(2.5) = 2 , but CInt(2.51) = 3 Try this line: Seconds = CInt((Totaltime Mod 60) + 0.01) [Assuming I've understood your problem correctly !] |
|
#9
|
||||
|
||||
|
that's true. Forgot about that one - however the problem is more in variable assignment than in rounding
|
|
#10
|
|||
|
|||
|
robbage: what happens if you run this code?
Public Seconds as Integer Public Totaltime as Single Totaltime=31.5 Seconds= Int(Totaltime Mod 60) If i run this code Seconds=32... BUT if you read my first message you will see that Seconds=31 after running the exaxt same code! Fisherman and cleverpig: Thanks for all the help so far If the problem is as cleverpig says, then the only solution must be to put in some more memory in the computer, right?(Please tell me i´m wrong ) Because right now i´m using the Single-variable, wich is the variable that needs the least space, and the problem is still there. |
|
#11
|
|||
|
|||
|
Quote:
Thats right, but it has nothing to do with the Int() function. Totaltime Mod 60 returns 32 anyway ![]()
__________________
System:
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Bug in Vb6 |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|