PC Review


Reply
Thread Tools Rate Thread

CObj() Function -- What's the point?

 
 
Raterus
Guest
Posts: n/a
 
      25th Feb 2004
I'm trying to figure out what exactly the CObj() function does. I'm not
using it for any reason, but on a review of all those casting functions like
cstr, cbool, cdate, I saw it, but couldn't for the life of me figure out the
point of such a function, or how I would ever need to use it. It takes in
an object as a parameter, and returns an object.

Here's what the MSDN documentation has to say about it:

CObj Example

This example uses the CObj function to convert a numeric value to Object.
The Object variable itself contains only a four-byte pointer, which points
to the Double value assigned to it.

Dim MyDouble As Double
Dim MyObject As Object
MyDouble = 2.7182818284
MyObject = CObj(MyDouble) ' Double value is pointed to by MyObject.

Just wondering...
--Michael


 
Reply With Quote
 
 
 
 
CJ Taylor
Guest
Posts: n/a
 
      25th Feb 2004
Well... we don't really use CObj anymore... more of a VB6 thing than
anything.

Second of all, it is good practice for explicit type casting, which if you
had Option Strict On you would get errors if you didn't use CObj in this
case.

or the more preferred VB.NET Style

CType(myDoubleVariable, System.Object)

or

DirectCast(myDoubleVar, System.Object)


"Raterus" <raterus@localhost> wrote in message
news:u4nCaA%23%(E-Mail Removed)...
> I'm trying to figure out what exactly the CObj() function does. I'm not
> using it for any reason, but on a review of all those casting functions

like
> cstr, cbool, cdate, I saw it, but couldn't for the life of me figure out

the
> point of such a function, or how I would ever need to use it. It takes in
> an object as a parameter, and returns an object.
>
> Here's what the MSDN documentation has to say about it:
>
> CObj Example
>
> This example uses the CObj function to convert a numeric value to Object.
> The Object variable itself contains only a four-byte pointer, which points
> to the Double value assigned to it.
>
> Dim MyDouble As Double
> Dim MyObject As Object
> MyDouble = 2.7182818284
> MyObject = CObj(MyDouble) ' Double value is pointed to by MyObject.
>
> Just wondering...
> --Michael
>
>



 
Reply With Quote
Reply

Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C# COM entry point function =?Utf-8?B?R2Vvcmdl?= Microsoft C# .NET 4 17th Jul 2007 04:16 AM
add point doesn't seem to function in powerpoint =?Utf-8?B?bmV3?= Microsoft Powerpoint 1 19th Jun 2006 09:40 PM
What can cause update function to point to website? =?Utf-8?B?TGVvbmFyZA==?= Microsoft Excel Misc 0 21st Sep 2005 07:08 PM
Break-even point function? =?Utf-8?B?V2Fsa2Vy?= Microsoft Excel Worksheet Functions 4 2nd Nov 2004 06:51 AM
How to Create a Function Point for a class member function. Microsoft Microsoft VC .NET 2 13th Aug 2004 09:00 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:52 PM.