Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default change variable type

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default change variable type

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),
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Type change in a declared Variable? NickHK Excel Programming 1 December 14th 06 02:01 AM
Type change in a declared Variable? Martin Fishlock Excel Programming 0 December 13th 06 01:30 AM
Type change in a declared Variable? Gary''s Student Excel Programming 0 December 13th 06 01:23 AM
Type change in a declared Variable? Alok Excel Programming 0 December 13th 06 01:20 AM
how to change all the words of one type(Gunsuh type)to another metumevlut Excel Discussion (Misc queries) 2 November 11th 05 03:29 PM


All times are GMT +1. The time now is 10:14 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"