How to find the datatype of a particular variable...

Dear pals,

I am developing an win32 console application, I need to find the data type
of particular variable dynamically.  Is it possible?
Say for eg,
declaring 'a' as integer, how can I find the data type of variable 'a'
dynamically.

Awaiting for your ideas.

note: please ignore this, if it is not a relevant group.

@Shahul.



0
shahul (6)
3/15/2006 7:40:18 AM
vc.mfc 33608 articles. 0 followers. Follow

3 Replies
461 Views

Similar Articles

[PageSpeed] 15

I'm trying to imagine why your would need this. It sounds like this will be 
hard coded so you'll know. If you need something higher-level to do this, I 
would probably create a class that is similar to a variant in that it could 
store any type of data and include a member variable that contained a value 
that indicated the current type.

Alternatively, you could try something like this:

#define TYPEINT 1
#define TYPECHAR 2
#define TYPEFLOAT 3

int GetType(int i)
{
   return TYPEINT;
}

int GetType(char c)
{
   return TYPECHAR;
}

int GetType(float f)
{
   return TYPEFLOAT;
}

// Etc.

main()
{
    int i, j;

    j = GetType(i);
}

-- 
Jonathan Wood
SoftCircuits
http://www.softcircuits.com
Available for consulting: http://www.softcircuits.com/jwood/resume.htm

"shahul" <shahul@chellasoft.com> wrote in message 
news:uxyv0OASGHA.5808@TK2MSFTNGP12.phx.gbl...
> Dear pals,
>
> I am developing an win32 console application, I need to find the data type
> of particular variable dynamically.  Is it possible?
> Say for eg,
> declaring 'a' as integer, how can I find the data type of variable 'a'
> dynamically.
>
> Awaiting for your ideas.
>
> note: please ignore this, if it is not a relevant group.
>
> @Shahul.
>
>
> 


0
jwood (1292)
3/15/2006 8:50:39 AM
Hi,

Your method will do but only for the cases you care for. For every new type 
you will need to define a separate method...

The correct way is to use RTTI which is supported by the language.
Particularly, there is 'typeid' operator (or some people say function) which 
may be used like so:

if ("CMyClass" == typeid(pObject).name())
{
// pObject is of the type CMyClass

}


-- 
======
Arman


"Jonathan Wood" wrote:

> I'm trying to imagine why your would need this. It sounds like this will be 
> hard coded so you'll know. If you need something higher-level to do this, I 
> would probably create a class that is similar to a variant in that it could 
> store any type of data and include a member variable that contained a value 
> that indicated the current type.
> 
> Alternatively, you could try something like this:
> 
> #define TYPEINT 1
> #define TYPECHAR 2
> #define TYPEFLOAT 3
> 
> int GetType(int i)
> {
>    return TYPEINT;
> }
> 
> int GetType(char c)
> {
>    return TYPECHAR;
> }
> 
> int GetType(float f)
> {
>    return TYPEFLOAT;
> }
> 
> // Etc.
> 
> main()
> {
>     int i, j;
> 
>     j = GetType(i);
> }
> 
> -- 
> Jonathan Wood
> SoftCircuits
> http://www.softcircuits.com
> Available for consulting: http://www.softcircuits.com/jwood/resume.htm
> 
> "shahul" <shahul@chellasoft.com> wrote in message 
> news:uxyv0OASGHA.5808@TK2MSFTNGP12.phx.gbl...
> > Dear pals,
> >
> > I am developing an win32 console application, I need to find the data type
> > of particular variable dynamically.  Is it possible?
> > Say for eg,
> > declaring 'a' as integer, how can I find the data type of variable 'a'
> > dynamically.
> >
> > Awaiting for your ideas.
> >
> > note: please ignore this, if it is not a relevant group.
> >
> > @Shahul.
> >
> >
> > 
> 
> 
> 
0
armancho_x1 (249)
3/15/2006 11:55:27 AM
On Wed, 15 Mar 2006 13:10:18 +0530, shahul wrote:

 
> note: please ignore this, if it is not a relevant group.

Crossposting to many groups is not an acceptable way to use newsgroups.
You are wasting people's time by posting in groups which are not relevant
to your question.

For example, your post has absolutely nothing to do with DirectX.

Please take the time to find one appropriate newsgroup by looking at other
posts in that group and post there.

A useful tool for doing this the search capability on
http://groups.google.com.

Otherwise, you will become a pariah.

See:

http://tmhare.mvps.org/help.htm#mp

Thank you.

Follow up set to: microsoft.public.access,microsoft.public.vc.ide_general
which probably isn't the best group for this post but the best among the
ones you chose.

-- 
Please read this before replying:
1. Dshow & posting help:  http://tmhare.mvps.org/help.htm
2. Trim & respond inline (please don't top post or snip everything)
3. Benefit others:  follow up if you are helped or you found a solution
0
phil3996 (17)
3/15/2006 1:55:47 PM
Reply:

Similar Artilces:

How do I configure Exchange 5.5 to use a particular NIC card to transport mail?
First some info on my network. Recently our ISP changed its pricing so we could no longer afford to have a block of 32 static assigned IP's. As a result we now have 2 static IP addresses. One is being used by the PDC/Web/Exchange server, the other has been assigned to our Symantec Firewall appliance allowing us to move all of our workstations behind the firewall and allowing us to use the firewall appliance DHCP server to supply enough internal IP's so we could maintain access for all the workstations. I also added a second NIC card to the Server and connected it to the firewall as wel...

Reference Variable in multiple Subs
Reference Variable in multiple Subs Hello, I=92m trying to accomplish the following: Sub WriteQuery() Dim strSQL as String strSQL =3D _ =93Select * from myTable=94 End Sub Sub RunQuery() Docmd.RunSQL(strSQL) =91won=92t run because variable not defined in immediate sub End Sub It=92s a simplified example, but I=92m trying to reference a variable (that=92s set in one sub) in another sub=85can I do this in some manner? Thanks, alex Try declaring strSQL at the very top of the module as Public or Private variable. Option Compare Database Option Explicit Dim strSQ...

Inserting arrays as variables
How can I insert an array or range of variables (e.g. .042 to .168) into a formula? Alternatively, can I define variables (e.g. x, y) without having to use Visual Basic? I'm trying to create a chart which outputs values based on constants and a function involving the range of variables. Thanks for your help! {0.042,0.07,0.1,0.11,0.123,0.13,0.168} as an example -- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "anthonyd" <anthonyd@discussions.microsoft.com> wrote in message news:404CE381-5890-458B-9A43-6EA3CB894591@micros...

How To Find A Macro -- Word 2007
Our company has several hundred controlled forms that are saved as protected templates on a server. Recently, we've had many cases of people trying to open these templates and getting error messages about macros (Do you want to enable?) even though there shouldn't be any macros in the forms that are giving the errors. I know very little (read "less than nothing") about macros. How do you find and disable an unwanted macro in a document? Where do they hide? I don't know if it matters, but all of the forms that give these errors have been recently revised...

Find Last instance of carriage return In a Memo Field
Hi, I have a form where the user usually pastes a glob of text into it a memo field called "Comment". After he pastes the text, the cursor is obviously at the end of the text. I would like the user to be able to click a button and for the comment to be highlighted from the very end of the text to the first instance of a carriage return going backwards. In other words, I want to automatically select the very last line of the comment. I was thinking that I could use seldown, but I would need to first find the Last instance of Chr$(13). Or, can the instr function can be ...

where can I find an excel file I "saved as" in OLKE9?
I saved over an EXCELL file that someone sent to me in OUTLOOK, after adding hours of data. Unfortunately I clicked "save as" but did not change the directory. It has saved my EXCEL FILE in a folder called OLKE9. I have searchjed the path, but cant fnd the file (I am displaying hidden files). Please help, I need this file in only 8 hours time or my life will be a misery. Easy way: Open ANY file (EXCEPT THAT ONE!!) through Outlook, and hit File-->Save as. That'll take you to the OLK folder. If you don't see it, likely, it's gone. Never, ever open files attached ...

tool to find GDI resource leak
Hallo, i search a tool or DLL or source to find GDI resource leaks. I've Boundschecker, but it don't find GDI resource leaks. Jimmy > i search a tool or DLL or source to find GDI resource leaks. > I've Boundschecker, but it don't find GDI resource leaks. Hmm, as far as I can remember BC did find GDI leaks without problems several years ago, when I was using it. You may also check this: http://msdn.microsoft.com/msdnmag/issues/03/01/GDILeaks/default.aspx -- Igor Green, Grig Software. www.grigsoft.com Compare It! + Synchronize It! : files and folders comparison neve...

Able to find text properties?
Is there a function in excel to test the text properties of a cell. ie. if it's bold or red color text? thanks naveed010@hotmail.com G0 to the Help files, and lookup Cell worksheet function That will give you a list of the types of formats that can be returned. Mostly date, time and currency formats. The only color return would be the "negative red" in currency. What you're looking for needs code. -- HTH, RD ============================================== Please keep all correspondence within the Group, so all may benefit! ========================================...

How to find the datatype of a particular variable...
Dear pals, I am developing an win32 console application, I need to find the data type of particular variable dynamically. Is it possible? Say for eg, declaring 'a' as integer, how can I find the data type of variable 'a' dynamically. Awaiting for your ideas. note: please ignore this, if it is not a relevant group. @Shahul. I'm trying to imagine why your would need this. It sounds like this will be hard coded so you'll know. If you need something higher-level to do this, I would probably create a class that is similar to a variant in that it could store any t...

Find 3rd Record
Hi there, I need to find the third record in a query. This is my basic select query: SELECT tblGuests.GID, tblGuests.Date FROM tblGuests ORDER BY tblGuests.GID, tblGuests.Date; There are several thousand records in tblGuests, some Guests (GID) have just one record, others have 20 or more. I've thought of DateDiff function but that doesn't seem to work. I have also thought that I need to find only records where there are more than 2 records for a certain GID so I can filter out the Guests who have only visited 1 or 2 times using the count function but have no idea how to do t...

Variable in Subtotal
Dear all, I'm trying to put a subtotal in my list, but in some cases I have three columns to sum (4,5,6); some case I have more or less columns to sum; it's variable. How can change this code to obtain it? Range(Cells(7, 1), Cells(65536, 256)).Subtotal GroupBy:=3D1, Function:=3DxlSum, TotalList:=3DArray(4, 5, 6), _ Replace:=3DTrue, PageBreaks:=3DFalse, SummaryBelowData:=3DTrue Thanks a lot!!! Andr=E9. ...

where can i find a list of excell formula's? #2
I'm learning to use excel more and more and i would like to know how to create a formula that subtracts one cell from another. Is there a list of formula's for excel? Look in HELP contents for function index -- Don Guillett SalesAid Software donaldb@281.com "Art" <Art@discussions.microsoft.com> wrote in message news:DFF58A3A-86CE-415C-A471-0F995F95C108@microsoft.com... > I'm learning to use excel more and more and i would like to know how to > create a formula that subtracts one cell from another. Is there a list of > formula's for excel? Art, y...

find location max value in column
I need to find the cell location of the max value in a column. If paste the following [from =(cell onwards] into a cell I get the righ result. Having a hgard time getting the right VBA code to make thi work in an unattended macro. Probably some bonehead mistake on my part but I cannot find it. Suggestions? GOAL is to make this formula work. Range("z2").Formula "=(CELL(e1,OFFSET(e1,MATCH(MAX(e1:e100),e1:100,0)-1,0)))" TIA, Ro -- rroac ----------------------------------------------------------------------- rroach's Profile: http://www.excelforum.com/member.php?act...

Finding last occurence of Interior.ColorIndex 36
I have been searching for a formula to help me find the last time (most recent) color 36 appears in a column of colored cells. Most of the time there is no typed information and when there is, it is not the same for every color 36 cell. The cells are not conditionally formatted. C. Pearson's site is great, but I can't find what I need. I don't want to change color, I don't want to know how many times it shows up, I just want to find the last time it is in the column. I could count down to find it, but there are over 15,000 columns spread over several worksheet...

upgrade to 2007 can't find exsiting website
I just upgrade from microsoft office 2003 to 2007 office enterprise, my operating system is visita. I'm trying to get my website from 2003, it comes in but none of my pictures,background,pages. doesn't show. I've uninstall the software and installe it again, hopeing this would fix the problem. I'm at a lost here. someone please help. I think Microsoft should let office 2003 run with visita, instead running out to buy some software that suppose to be compatiable. this is a waste of money. Office 2003 SP2 & SP3 will run on Vista. -- ~~~~~~~~~~~~~~~~~~ Rob Giorda...

Can we bind a control to the static member variable ?
Hi, I was wondering, can we bind a control ? e.g. Can an edit box be bound with a static variable of type CEdit ?? I have tried but giving error.. ===== Regards, Jigar Mehta Jigar Mehta wrote: > Hi, > > I was wondering, can we bind a control ? > > e.g. Can an edit box be bound with a static variable of type CEdit ?? > > I have tried but giving error.. > ===== > Regards, > Jigar Mehta > > That is a very unusual thing to want to do. I don't know if it works because I've never needed such a thing. Can you tell us about the error you get,...

Combo box to find records
Hi, need help with what I am sure is a simple problem. I have a form and wish to find records using a combo box. Which I know how to do. The problem is it takes me to "one" record. I would like to select, for example, employee name: John Smith and it return all records for John Smith while filtering out all other records. I would be thankful for any help. Thanks, Michael On Wed, 30 Jan 2008 20:24:04 -0800, Michaelchessking <Michaelchessking@discussions.microsoft.com> wrote: >Hi, need help with what I am sure is a simple problem. > >I have a form and wis...

edit variable length items in "Access" database tables
In my database table I am holding a variable length item in a database record; the item may be from two to six alphabetic characters long. Trailiing spaces pad the item where required. To print out the item in a report, the item itself is sandwiched between two fixed-length items separated by an oblique stroke, (forward slash): - ***/variable length/***. How can I suppress the trailing spaces in my variable length item when printing results ? Yours Sincerely, CHARLES WALKER Take a look at the RTrim function or even the Trim function. RTrim(SomeField) will trim trailing spaces off a...

Still can not find an option
Excel 2007 ... trying to find the option to email a single sheet from a workbook but not having any success.. have gone to the options > customize and looked in ALL available but do not see one for send this worksheet by email... only selection is send workbook.... is it named diferently in this version or can someone direct me where to go exactly within the customize menu.... thanks On Jan 26, 12:57=A0pm, TechnoGram <mumz...@hotmail.com> wrote: > Excel 2007 =A0... =A0trying to find the option to email a single sheet > from a workbook but not having any success.. have gone...

Standard toolbar "Find" is strange
When I use the standard toolbar find button (the one that says "type a contact to find" it ALWAYS returns "OUTLOOK COULD NOT FIND THE REQUESTED CONTACT" If I use the advanced find this works well, any ideas? ...

Find records that meet this criteria
Hello, I need to create a query that will search about 10 individual date fields to see if any of the dates are: greater than 30 days prior to, or 1 day after the <pdate>. The data is laid out like this: person dt 1 dt2 dt3 dt4 dt5 dt6 pdate rec1 7/6/09 5/6/09 4/12/09 5/5/09 9/12/09 5/15/08 6/6/09 Thank you, Maybe you can add another column and use a couple of =countif()'s. =countif(b2:g2,">="&h2-30) + countif(b2:g2,">"&h2+1) I'm not sure about what happens ...

global variable #2
hi this is a simple question (i'm new in vc++). i create a vc++ project with mfc, i need define a FILE* pt as global variable, visible from all my class and function (different files). Where have i to write the global variable definition??? carlo Carlo wrote: > i create a vc++ project with > mfc, i need define a FILE* pt as global variable, visible from all my > class and function (different files). Where have i to write the global > variable definition??? Exactly once, typically in one of the .cpp files. // declaration (typically in a header) extern FILE* pt; // defin...

Advanced Find for the case subject's parent-child level
Hi all, I'm trying to filter\run report cases according to subject hierarchy. In the "advanced find" all I can choose is the specific subject regardless his parent. The same behavior occur when I export the whole cases table to excel as a pivot table. Any suggestion would be of assistance. Tnx N. ------=_NextPart_0001_B2E9FE9B Content-Type: text/plain Content-Transfer-Encoding: 7bit "Niel100" <niryon5@hotmail.com> wrote: > I'm trying to filter\run report cases according to subject hierarchy. > In the "advanced find" all I can choose is ...

cannot find reverse hostname.
i am gettin the following error. Your message did not reach some or all of the intended recipients. Subject: FW: ER Sent: 10/5/2006 7:22 AM The following recipient(s) could not be reached: email address on 10/5/2006 7:23 AM You do not have permission to send to this recipient. For assistance, contact your system administrator. <omaspam1.vertrue.com #5.7.1 smtp;554 5.7.1 Client host rejected: cannot find your reverse hostname, [IP Adress} Does this have to do with Sender ID? this has to do with your ISP ...

updates
I have successfully updated Office 2004 through 10.9.1, but when I try to go any further I get a message - "installer cannot find the correct software . . . ." How did you update? Update 10.1.9 is for Office v.X only; the latest update for Office 2004 is 11.3.4. If you are using Office 2004, simply run Microsoft AutoUpdate (which can be found in your Applications folder) and let it perform all the updates for you. On 12/3/07 20:04, in article 1173726294.060440.242930@n33g2000cwc.googlegroups.com, "skrouse@verizon.net" <skrouse@verizon.net> wrote: > I have succ...