 |

12-05-2003, 11:50 AM
|
|
Ultimate Contributor
|
|
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,665
|
|
Why CLng required in this line??
|
Given that OP() is dimmed an Integer and XX() a Double
I can't understand why the CLng function is required in this line of code:
OP(i) = CInt(CLng(XX(i)))
You would think the one CInt would suffice.
|
|

12-05-2003, 12:05 PM
|
 |
Contributor
|
|
Join Date: Nov 2002
Location: Montréal, Québec, Canada
Posts: 575
|
|
|
The only reason I see why Clng would be required, is if XX(i) is greater than 32,767 which is the maximum value for an Integer. The maximum value for a Long variable is 2,147,483,647.
|
__________________
Rufen
|

12-05-2003, 12:09 PM
|
 |
Obsessive OPtimizer
Administrator * Guru *
|
|
Join Date: Jun 2002
Location: Debug Window
Posts: 13,686
|
|
|
It shouldn't be. Btw, I'm sure you know.. but a double can easily exceed the maximum of an integer. CLng and CInt also round up over .5. Int or Fix might be better alternatives, if you need to truncate decimals.
|
|

12-05-2003, 12:54 PM
|
|
Ultimate Contributor
|
|
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,665
|
|
|
do you mean:
OP(i) = Int((XX(i))) and/or OP(i) = Fix((XX(i))) ??
I tried both of these, and both fail.
Only
OP(i) = CInt(CLng(XX(i)))
works...
but I don't understand why!
XX(i) should not contain values outside -32768 and + 32767,
but because of rounding there may be values like 32767.000005 etc
|
|

12-05-2003, 01:01 PM
|
 |
MetaCenturion
Retired Moderator * Guru *
|
|
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
|
|
Have you tried
OP(i) = CInt(XX(i))?
Does that make things work or not? 
|
|

12-05-2003, 01:25 PM
|
|
Ultimate Contributor
|
|
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,665
|
|
Program will crash with that line.
(That's what's confusing me!)
|
|

12-05-2003, 01:26 PM
|
 |
Obsessive OPtimizer
Administrator * Guru *
|
|
Join Date: Jun 2002
Location: Debug Window
Posts: 13,686
|
|
I'd like to see some sample code/data.
Edit: btw, when you say int and fix "fail", can you be specific as to how they fail. Error number and description would be helpful.
|
Last edited by OnErr0r; 12-05-2003 at 02:11 PM.
|

12-05-2003, 06:39 PM
|
|
Ultimate Contributor
|
|
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,665
|
|
|
I will see if I can pull out the relevant code and some sample data
to emulate this.
I don't know the error number, and am not even sure if program
crashes on that line because the program will only run as an exe
and I don't know how to debug properly (I am searching net to see
if I can add error handling routine to write to log file).
What I am sure of, is that the program runs without problems using
OP(i) = CInt(CLng(XX(i)))
and crashes as soon as I change that line to
OP(i) = Int((XX(i)))
or any variant thereof.
I have a few other bugs in the program (they do not crash program
or anything) and I am wondering if this might be the root of that
problem. Since I don't understand what's exactly happening with
the data in that line of code, I can't be sure.
|
|

12-05-2003, 06:55 PM
|
 |
Village VB Idiot
* Expert *
|
|
Join Date: Jan 2003
Location: Idaho
Posts: 1,850
|
|
|
Why does your application only run as an executable? Methinks you have bigger problems than a buggy CAST operation.
|
|

12-05-2003, 07:25 PM
|
|
Ultimate Contributor
|
|
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,665
|
|
|
The program reads a CD-audio signal (so as to alter the signal) and
the IDE does not process the information fast enough.
The exe just barely does this processing quickly enough, but it
does manage.
|
|

12-06-2003, 10:34 PM
|
|
Ultimate Contributor
|
|
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,665
|
|
|
I found out why this works as it does.
To make the program run fast enough to do what it has to do,
I disabled all the error checking when compiling to exe.
Remove Integer Overflow Checks causes this behaviour,
VB must force the overflow value to an integer value with the
CInt(CLng(X)) combination.
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|