Solved

Invalid Use of New Keyword

Posted on 1998-06-05
15
285 Views
Last Modified: 2010-05-03
I have a Visual Basic 5.0 Group with several projects in it.  Some ActiveX controls and 1 ActiveX Server.  Everything was working fine with no problems.  Then I decided to do a Build Project Group command.  This worked fine until it got to the main EXE program and gave me the error message or Invalid Use of New Keyword on the following line:
Private House as new PropertyObject

Now this line has worked fine before when I just ran the program in VB.  Now after I did the Make Project Group Command and it rebuilt the PropertyObject Class I can not even run the program in VB5.0 anymore.

Anyone please help I have no clue as to the cause of this problem or how to go about fixing it, but this is holding me back from continueing.
0
Comment
Question by:clsmaster
  • 9
  • 6
15 Comments
 
LVL 4

Expert Comment

by:zsi
Comment Utility
Check to make sure that the object containing PropertyObject has a valid reference, one that is up to date.  It is looking through the list of valid object references and not finding PropertyObject.

Also, as a safeguard, make sure that you are running SP3.

zsi
0
 

Author Comment

by:clsmaster
Comment Utility
There is a reference to PropertyObject and I'm running SP3
0
 

Author Comment

by:clsmaster
Comment Utility
Here is the odd thing about that though.  If I retype that line Properties appears on the list after the new keyword.  And House is used throughout the project.
If I go into references I can uncheck the PropertyObject reference without any problems (it does not say object is use)
If I then go back into the code and try to retype the line Properties does not appear in the list.  Why doesn't it say that the PropertyObject Reference is in use????
0
 
LVL 4

Expert Comment

by:zsi
Comment Utility
You only get that message if the reference is to an OCX control that is being used on a form.  The system does not verify the use of an object in code when you remove a reference.

This is a very desirable feature.  When you recompile a DLL or EXE that is being referenced, you have to de-reference it, close the references dialog box, and then re-reference the object.  If the system would not allow you to de-reference an object that was referred to in code, you would have to comment out all of the code, refresh the reference, and then uncomment the code again.  That would be a nightmare.

Try this: instead of using early binding (Dim x as New r.o), try using late binding (dim x as object.  Set x = CreateObject("r.o") ) and see if that allows you to get around the problem.

If it does, then you know that you were trying to refer to an invalid object.

Also, just to make sure that everything was registered correctly, you should unregister your project's DLL/EXEs and re-register them.  

Lastly, once this is all resolved, you should look in the manual for information on binary compatibility.  This will help to alleviate problems in the future.

zsi
0
 

Author Comment

by:clsmaster
Comment Utility
How do I go about deregister my controls and DLLs
0
 
LVL 4

Expert Comment

by:zsi
Comment Utility
For the dll, use RegSvr32 with the /u parameter.

Just make sure that you do not unregister any system dlls - only the ones that you have created with your project.
0
 

Author Comment

by:clsmaster
Comment Utility
Doing late binding works.
I then went into VB References and the PropertyObject Reference.
I then ran regsvr32 /u on the DLL
I then ran regsrv32 on the DLL (to register it)
I then switched back to VB and reselect the PropertyObject Ref.
I then tried to run the program, but still got the error with the new keyword.


How do I fix this???? I really don't want to have to do late binding because it makes it a lot easier to program with early bind statement completion and all.

PLEASE HELP
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 4

Expert Comment

by:zsi
Comment Utility
Are you sure that the file that you are unregistering and re-registering is the same one that you are using in your app?  Search through your computer and make sure that you do not have duplicate versions of the dll.  If you do, make it so that you are only using the one that your are registering.  

0
 

Author Comment

by:clsmaster
Comment Utility
Yeah I did A find and no other matches came up, also in the reference dialog box the path is the same.  This time after I did /u I did make PropertyObject.dll instead of doing regsrv32 again.

Here's an odd thing if I make a new EXE and go into the references box the name of the same DLL is not the same as in the program.  In the new EXE I only have the EXE not the DLL.  Also it works perfectly fine here.
0
 

Author Comment

by:clsmaster
Comment Utility
If I add the project to the new EXE then the name changes back to what it is in the real program, but everything still works fine.
0
 

Author Comment

by:clsmaster
Comment Utility
I found a way to fix it.  In the new EXE I just Add all the projects and forms from the original and now it works.
0
 
LVL 4

Expert Comment

by:zsi
Comment Utility
So is this resolved? :)
0
 

Author Comment

by:clsmaster
Comment Utility
If you don't know the answer of what, so that if and when I run into a similar problem I'll know the anwser.
Also either way fell free to submit something as an answer, so I can give you the points, you've been a big help either way.
0
 
LVL 4

Accepted Solution

by:
zsi earned 90 total points
Comment Utility
If I can find a more difinitive answer, I will post it here.  It is definetly a registration problem, however.

I have experienced this problem before, I am sure it will come back to me.

zsi
0
 

Author Comment

by:clsmaster
Comment Utility
Thanks Please do post it if you can figure out what has happened here.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now