Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Why CLng required in this line??


Reply
 
Thread Tools Display Modes
  #1  
Old 12-05-2003, 11:50 AM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,665
Default 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.
Reply With Quote
  #2  
Old 12-05-2003, 12:05 PM
rufen101's Avatar
rufen101 rufen101 is offline
Contributor
 
Join Date: Nov 2002
Location: Montréal, Québec, Canada
Posts: 575
Default

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
Reply With Quote
  #3  
Old 12-05-2003, 12:09 PM
OnErr0r's Avatar
OnErr0r OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,686
Default

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.
Reply With Quote
  #4  
Old 12-05-2003, 12:54 PM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,665
Default

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
Reply With Quote
  #5  
Old 12-05-2003, 01:01 PM
Iceplug's Avatar
Iceplug Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
Default

Have you tried
OP(i) = CInt(XX(i))?
Does that make things work or not?
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #6  
Old 12-05-2003, 01:25 PM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,665
Default

Program will crash with that line.

(That's what's confusing me!)
Reply With Quote
  #7  
Old 12-05-2003, 01:26 PM
OnErr0r's Avatar
OnErr0r OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,686
Default

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.
Reply With Quote
  #8  
Old 12-05-2003, 06:39 PM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,665
Default

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.
Reply With Quote
  #9  
Old 12-05-2003, 06:55 PM
VBJoe's Avatar
VBJoe VBJoe is offline
Village VB Idiot

* Expert *
 
Join Date: Jan 2003
Location: Idaho
Posts: 1,850
Default

Why does your application only run as an executable? Methinks you have bigger problems than a buggy CAST operation.
Reply With Quote
  #10  
Old 12-05-2003, 07:25 PM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,665
Default

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.
Reply With Quote
  #11  
Old 12-06-2003, 10:34 PM
mms mms is offline
Ultimate Contributor
 
Join Date: Jul 2002
Location: Hamilton, Ontario
Posts: 1,665
Default

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.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Drawing inclined squares XVB Interface and Graphics 7 11-14-2003 03:46 AM
Line Numbers in Word and VBA Ditchdoc Word, PowerPoint, Outlook, and Other Office Products 4 10-12-2003 11:05 PM
Drawing joined parallel line segments bart111 Game Programming 0 03-15-2003 06:32 PM
Transfer private controls to another project.. Help! Jazler General 8 07-01-2002 09:59 AM
How to goto end of the line or record line snownieve General 3 03-28-2001 01:14 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->