PC Review


Reply
Thread Tools Rate Thread

change variable type

 
 
spencer.sadkin@gmail.com
Guest
Posts: n/a
 
      24th Dec 2008
what is the vba function that is like the vb Ctype?


i have a bunch of checkboxes that get created programatically with
names based on an array. i need to test these values so i have a
variabled dimmed as checkbox and i need to set this based on the names
in the array.

thanks
 
Reply With Quote
 
 
 
 
Chip Pearson
Guest
Posts: n/a
 
      24th Dec 2008
There isn't a generic CType function. Most primitive data types have
functions to convert a value to that type. E.g.,

Dim L As Long
Dim J as integer
J=1234
L=CLng(J)

The most common is the CStr function to convert a numeric primitive to
a string:

Dim S As String
Dim L As Long
L = 123
S = CStr(L)

You can't convert arbitrarily from one type to another. You code roll
your own, but that would be a lot of work that may or may not really
be necessary.

If your checkbox objects were created from the Controls command bar,
you can use something like

Dim OleObj As OLEObject
For Each OleObj In Worksheets(1).OLEObjects
If TypeOf OleObj.Object Is MSForms.CheckBox Then
Debug.Print OleObj.Object.Caption
End If
Next OleObj

The TypeOf/Is construct can be used with any object. E.g.,

Dim C1 As Object
Set C1 = New Class1
If TypeOf C1 Is Class1 Then
' C1 is type Class1
Else
' C1 is not type Class1
End if


Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Wed, 24 Dec 2008 07:13:20 -0800 (PST), (E-Mail Removed)
wrote:

>what is the vba function that is like the vb Ctype?
>
>
>i have a bunch of checkboxes that get created programatically with
>names based on an array. i need to test these values so i have a
>variabled dimmed as checkbox and i need to set this based on the names
>in the array.
>
>thanks

 
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
Re: Type change in a declared Variable? NickHK Microsoft Excel Programming 1 14th Dec 2006 02:01 AM
RE: Type change in a declared Variable? =?Utf-8?B?TWFydGluIEZpc2hsb2Nr?= Microsoft Excel Programming 0 13th Dec 2006 01:30 AM
RE: Type change in a declared Variable? =?Utf-8?B?R2FyeScncyBTdHVkZW50?= Microsoft Excel Programming 0 13th Dec 2006 01:23 AM
RE: Type change in a declared Variable? =?Utf-8?B?QWxvaw==?= Microsoft Excel Programming 0 13th Dec 2006 01:20 AM
how to cast an object to the type stored in a System.Type variable? Fred Zolar Microsoft C# .NET 2 18th Jun 2004 08:44 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:15 AM.