Jump to content

CreateObject statement using variable instead of string literal


John Browne
 Share

Recommended Posts

  • Mobilize.Net Staff

Visual Basic supports a way to call external classes with the CreateObject() function. The function takes a class name as a parameter. Here's an example:

Dim ExcelSheet As Object
Set ExcelSheet = CreateObject("Excel.Sheet")

In this case, the parameter for the function is a string literal ("Excel.Sheet") and the VBUC will migrate the VB6 code correctly. 

However...

Suppose you have this VB6 code:


Const XL = "Excel.Sheet"
[some code]
CreateObject(XL)

In this case the VBUC will display the error "CreateObjects statements using a variable instead of a literal string" in the output code. This is because the value of the variable "foo" can change over time. In this case, it's advisable to replace the variable in the CreateObject syntax with the actual name of the object class being called:

CreateObject(Excel.Sheet)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Terms of Use