This vbs code show error when I click to execute it
Set objIP = CreateObject( "SScripting.IPNetwork" )
strIP = objIP.DNSLookup( "www.google.com" )
WScript.Echo "IP address of www.google.com: " & strIP
Set objIP = Nothing
The error is here in this is pic.
It seems to me that activeX components are often poorly documented and if you can't get stuff working, you need a method that bypasses the documentation and goes directly to what you've actually got available on you machine.
I had documentation that said something like:
Set library = CreateObject("somethinglibLib.SomethingLibrary.2")
would work, it didn't... where now?
I found that the "somethinglibLib.SomethingLibrary.2" should exist in the registry in a ProgID key, if it doesn't your CreateObject won't work.
I won't cover the cases where you haven't registered the activeX component as that is covered elsewhere.
But if you search the registry for part of the object name you are looking for, you may find as I did a ProgId containing
"somethinglib.SomethingSite.1"
knowing this I found
Set library = CreateObject("somethinglib.SomethingSite.1")
worked
Now my example is due partly to the version I had installed not matching the documentation, but hopefully this technique may help others.
In order to make your code working, you need to make sure you have System Scripting Runtime installed on your machine.
Here is very good reference for that.
Related
I have an VB6 application.
When trying to Start it prompts an error ActiveX component can't create object
The program is failed in below line
Set GCIWCon = CreateObject("Dbsecurity.database")
I have checked that DAO3.6 library is existed and below line can be executed
CreateObject ("Excel.Sheet")
Thus, I assumed that DAO3.6 is working properly, but the object "Dbsecurity.database" is not found.
I do have a rough idea about the DAO library but I have no idea what is missing in order to make the issued line work.
Can anyone suggest what the object "Dbsecurity.database" can be and how to include it in the VBA?
Thanks
I found ImageMagick online and am trying to add it to one of my legacy VB6 projects to convert some .jpgs --> PDFs.
I installed and registered the dll:
ImageMagick-7.0.7-29-Q16-x64-dll.exe
I added the reference in my projects without any issues:
ImageMagicObject 1.0 Type Library
The problem now comes when I try to create an object of ImageMagickObject.MagickImage.1 like so:
'Dim your object as a simple Object
Dim imgMkObj As Object
'Set your object
Set imgMkObj = CreateObject("ImageMagickObject.MagickImage.1")
'Convert your image
MsgBox imgMkObj.Convert("C:\source.jpg", "-resize=800x600", "C:\destination.pdf")
When it gets to the SET part, it gives me an error
Run Time error 429
ActiveX component can't create object
And I really have no idea how to proceed from here. Is there a ImageObject component that I need to have added in my app (OCX) to make this work. I'm trying to programmatically (not command line) to change the formats of some documents.
Can anyone shed some light on this?
Thanks.
It looks like you've installed the 64 bit version of the DLL.
If they offer a 32 bit install that might solve your problem?
VB6 is a 32 bit application
I am having to make an old VB6 application run on Windows 10. The issue was that the reference to DomDocument40 is not part of Windows 10 (or 7 i believe) and instead uses DomDocument60 (part of the msxml6.dll).
The line was:
Dim oXMLDom1 As New DOMDocument40
To ensure backward compatibility i believe it is better to use DomDocument which will automatically use the appropriate version on the system. Is this correct?
So my line is now:
Dim oXMLDom1 As New DOMDocument
However, now when I try to run the application i get the compiler error 'Method or data member not found.' This relates to the following line (which I now see setProperty is not supported in msxml6):
oXMLDom1.setProperty "SelectionLanguage", "XPath"
Can anyone tell me firstly if using DomDocument instead of DomDocument40 is the recommended solution. And if so what I should do about setProperty no longer being available?
I know the best solution is to write this in almost any other language ;) but that's not an option.
This is probably not an answer, but you should be able to safely comment out that line as XPath is the default value from MSXML 4.0 onwards. If the application is to run on Win10, XPath should be the default.
EDIT
After some testing, I think all you need to do is change this:
Dim oXMLDom1 As New DOMDocument
To this:
Dim oXMLDom1 As New MSXML2.DOMDocument
The only way I got the SetProperty method to fail like that was explicitly adding a reference to Microsoft XML, version 2.0 and declaring the object without MSXML2 (that also fails, as the class name is MSXML for that version). I tested this adding references from Microsoft XML, v2.6 to Microsoft XML, v6.0 and it works without problems for all of them. Please notice that I did all this testing on an XP machine, as I have no way to test it on a Win10 PC right now, but it should work fine.
I am getting the following type mismatch error on the following
IF obj.propery THEN
...
END IF
the code I am using is on visual source safe and when other developers run the same project the code runs with no error. The property is actually a string which is where the problem could be. When I debug and test the property i.e.
?obj.propery = True
no errors are thrown which is a bit strange. If I place the cursor over the property it says "True". I have done a bit of searching on the matter and have found that this may have something to do with OPTION STRICT, however I have the same version of the code as the other developers and OPTION STRICT is not OFF, it hasn't been altered in the code at all. Are there any other settings that could affect this execution of code at run time?
It strikes me that there could be an entirely different reason for your Type Mismatch error, especially as you are accessing an object property. I've experienced this error when I have, for some reason, been pointing at a different DLL to that registered. You will find with VB that it registers a DLL "on the fly" when you build it, so you may end up accessing the code somewhere that you did not expect. This may not be the problem in your case, but it is worth exploring.
This was nothing to do with VB6, it was to do with XP Mode and using my user account from another domain as opposed to XPMUser. When I use XPMUser the application runs this is very odd and I am not sure why this is. If anyone has the reason I would love to hear.
So you are sure this is not the case of a boolean being Vrai?
I'd be inclined to be more explicit in your IF condition
IF isempty(obj.property) = false AND isnull(obj.property) = false
BUT
it would be prudent to check that obj isn't null first, before you start accessing its properties....
I'm using VB 6.0 and it gives me:
Compile Error:
Can't Find Project or Library
in this sub:
Private Sub MDITimer_Timer()
Dim textStr As String
textStr = Format(Now, "dd-mm-yyyy hh:mm:ss")
StatusBar.Panels(1).Text = textStr
End Sub
I made it like this and the error still was in the Format function (so it is not a StatusBar problem).
Can you tell me what is the Reference that we have to add to use the Format function? Or if a Reference is not needed, what do we have to do to make this work?
Problem's more likely to be the StatusBar (In the Microsoft Windows Common Controls, MSCOMCTL.ocx). Format is built into the VB6 language, you shouldn't need any reference at all.
EDIT Format is in VBA.Strings. I think this is in the "Visual Basic for Applications" reference, MSVBVM60.dll. I thought the VB6 IDE prevented you from unticking the reference.
You probably overloaded Format() with a declaration of the same name. Have you tried calling VBA.Format() instead?
You should also use Format$() to avoid the unnecessary overhead of working with the Variant result Format() returns.
I know this is old but in case someone else comes down this road...
When I had this issue found the real problem was nothing to do with MSVBVM60.dll which as said cannot be disabled as a reference.
What the error is complaining about is that a reference defined in the project is not resolved. It is not saying that the missing reference necessarily has anything to do with the function it is highlighting. What I assume the compiler is doing is sequentially searching the defined references to find the function. During that search it finds one of the references is not resolved (ie the dll or whatever is missing). This causes it to stop the search and give the error.
Reason using VBA.Format helps is that it tells the compiler where to search avoiding the need to scan through all the references.
Solution: check references defined in the project (Project => References) and make sure they are all resolved.
Usually an unresolved reference will have the word 'MISSING:' in front of it. The path shown for the reference is where the project thinks it should be, it does not mean it is there.