Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
When MUST a variable be an Integer?
#1
So I literally have over 7000 lines of code and just recently changed the value of a variable from a whole number to a decimal value. I'm now getting some strange results but can't seem to find which routine is causing the problem. 

Before entering a Sort routine I had a variable QS, which could carry a value between 1 and 4 depending on which of 4 arrays I  was directing to the QuickSort. I found that the array which was identified at #2, needed to be broken down to two different sorts so rather than redo all the QS numbers for the 4 arrays I simply changed #2 to 2.1 and 2.2. The code run sorts all the time and keeps track of how many sorts are being performed (mostly to see how I can improve things)

When I ran the code everything worked fine , QS = 2.1 and QS = 2.2 were sorting ok until sort # 42. From sort # 42 and onwards, QS would not recognize the decimal values but somehow QS = 2 returned. It appears as if the 2.1 and 2.2 values of QS dropped off and QS from sort #42 an onwards became = to 2

I'm having trouble finding where this change in value occurred. It's not showing up in a simple search where I may have inadvertently use 2 rather than 2.1 or 2.2 so it must be in something like a Select Case where the Cases will not recognize anything other than the whole number, or maybe an IF statement or a Loop statement or some kind of an Assignment statement which only deals with integers. I do have multiple nested IF's and Loops.

I realize the simple solution is to go back, do not change #2 to 2.1 and 2.2 but just create a 5th and I will do this but if I can figure out why, after 42 sorts the decimal value is dropped then either I won't do that again or I can get the program back on track with a simple change of something at sort #42.

You guys have any thoughts on what command/function/routine that will only recognize a variable as an integer?
Reply
#2
decimal numbers do not work well for index to array but using default single works as long as you don't do any decimal, same goes for all routines that expect integers. sometimes qb64 rounds things or drops decimal and works, sometimes not.

hard to tell much without seeing where and how QS is being used
b = b + ...
Reply
#3
You must be right b ... something has to be rounding the index but only when I have it printed to the screen. After running my routines again (despite my screen showing QS = 2) I have discovered that after 42 sorts is not the same value of QS actually being used in the program run. The program run results are coming up as accurate for QS = 2.1 and QS = 2.2 no matter what the sort count is. So happy my resulting values are accurate. I guess, to display the correct QS value on the screen I perhaps should convert it display the string value of QS rather than the numeric value.

These things can drive you to drink. I appreciate the help ++
Reply
#4
(04-27-2024, 03:39 PM)Dimster Wrote: You must be right b ... something has to be rounding the index but only when I have it printed to the screen. After running my routines again (despite my screen showing QS = 2) I have discovered that after 42 sorts is not the same value of QS actually being used in the program run. The program run results are coming up as accurate for QS = 2.1 and QS = 2.2 no matter what the sort count is. So happy my resulting values are accurate. I guess, to display the correct QS value on the screen I perhaps should convert it display the string value of QS rather than the numeric value.

These things can drive you to drink. I appreciate the help ++

Somewhere in your code you are assigning your SINGLE variable to an INTEGER variable. When this is done anything after the decimal point is dropped.

Look around your code and see if this may be happening.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply




Users browsing this thread: 1 Guest(s)