VB6 Invalid Use of New Keyword
Question
Why do I get the error Invalid use of New keyword
when I write:
Dim obj As New ChilkatGlobal
Answer
In Visual Basic 6.0, there are two ways to use external components like ChilkatGlobal
— but you must choose only one:
Option 1: Create the object in code using New
- Example:
Dim obj As New ChilkatGlobal
- Go to Project → References...
- Check the box for
Chilkat ActiveX
or similar
Option 2: Use the component visually (drag onto the form)
- Do not use
New
in code - Instead, go to Project → Components...
- Then drag the component from the toolbox onto the form
Important Rule
Do not do both. If you both add a reference and drag the component onto the form, VB6 gets confused and you'll get errors like Invalid use of New keyword.
Best Practice for Chilkat Components
When using Chilkat in your application, you should always use the first approach:
✅ Add a Reference via Project → References...
❌ Do not drag-and-drop the component onto the form.
This ensures that you can create and manage Chilkat objects correctly using New
in code, and avoid runtime errors.