Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 31st, 2003, 08:17 AM
John42 John42 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: -
Posts: 23 John42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to John42 Send a message via Yahoo to John42
Angry Bug in Vb6

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.

Reply With Quote
  #2  
Old December 31st, 2003, 10:19 AM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,178 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 56 m 45 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
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

Reply With Quote
  #3  
Old December 31st, 2003, 11:56 PM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
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..

Reply With Quote
  #4  
Old January 1st, 2004, 05:57 AM
John42 John42 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: -
Posts: 23 John42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to John42 Send a message via Yahoo to John42
Quote:
Originally posted by cleverpig
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..


Ok, i´m not sure i follow . So do i need to change the type of variable i´m using or get more memory?

Reply With Quote
  #5  
Old January 1st, 2004, 06:27 PM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,178 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 56 m 45 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
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?

Reply With Quote
  #6  
Old January 1st, 2004, 08:47 PM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
Yes,As Fisherman said..It's my meaning..

Reply With Quote
  #7  
Old January 2nd, 2004, 05:31 AM
John42 John42 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: -
Posts: 23 John42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to John42 Send a message via Yahoo to John42
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

Reply With Quote
  #8  
Old January 3rd, 2004, 08:14 PM
robbage robbage is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Perth, Western Australia
Posts: 30 robbage User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via ICQ to robbage
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 !]

Reply With Quote
  #9  
Old January 3rd, 2004, 08:44 PM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,178 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 56 m 45 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
that's true. Forgot about that one - however the problem is more in variable assignment than in rounding

Reply With Quote
  #10  
Old January 4th, 2004, 08:43 AM
John42 John42 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: -
Posts: 23 John42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to John42 Send a message via Yahoo to John42
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.

Reply With Quote
  #11  
Old January 6th, 2004, 03:12 AM
robbage robbage is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Perth, Western Australia
Posts: 30 robbage User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via ICQ to robbage
Quote:
Originally posted by John42
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...


Thats right, but it has nothing to do with the Int() function. Totaltime Mod 60 returns 32 anyway
__________________
System:
  • Cool motherboard
  • Some hard drive or other
  • Some other stuff that costs a lot
  • Target brand mousepad
  • Blue power light!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Bug in Vb6


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |