Cannot convert Group Description to String Variable - vbscript

I have the following code:
Set objHoldGroup = GetObject("LDAP://" & objGroup)
strGroupDesc = (objHoldGroup.Description)
WScript.Echo(strGroupDesc)
The variable strGroupDesc returns nothing when echoed. I can output the description directly but I need it for further processing. Thoughts?

Explanation: Apparently your script sets Option Explicit (good), which you didn't tell us about (bad). This option makes defining variables before you can use them mandatory (good). Normally that would raise an "undefined variable" error, though. Since that doesn't seem to happen with your code, you seem to also have an On Error Resume Next somewhere in your code (very bad), which, again, you chose to keep quiet about (bad).
Next time please don't omit parts of your code that are vital for troubleshooting the problem. And don't use On Error Resume Next.

Issue found: I forgot to Dim strGroupDesc.

Related

VBScript Nothing returns garbage

We have to use VBScript as an embedded script engine in our Hospital Information System.
When we use nothing to set the value of a control (textbox/checkbox/...) it worked always fine. Since somepoint it sets now the textbox to "?>".
item("TEXTBOX").value = nothing ' Leads to -> "?>"
It is not completly clear what causes this, maybe a windows update is responsible, every rollup ~ since KB3212646 Win7 2017-01 seems to cause this error.
My Question is now, has someone else also seem this error, so that it is clear that MS causes this error or is our HIS publisher responsible for not handling nothing correct.
I know setting a textbox to Nothing is not best practice instead "" should be better, but since the item object could be more the just a textbox e.g. a combobox/checkbox this seems, from an objectoriented perpsective, better. Or am I completly wrong?
Following #Ansgar comment, you should apparently change everywhere you have = nothing to = "" in your example
item("TEXTBOX").value = ""
Beware to keep the nothing if you have the Set keyword in left
Set some_object = Nothing

VBScript newbie, GetObject 424 Object Required when connecting to application

I am trying to connect to an open application and send command to one of it's DLL functions. Here is the code- the error happens on the the GetObject. What am I doing wrong?
Dim oOL
Dim lcCmd
lcCmd = "'QQWOMOD.TWOAuto', '100',False"
MsgBox lcCmd
On Error Resume Next
'The Next stmt is commented out, but gives the same error as the one that follows it
'Set oOL = GetObject("C:\Program Files (x86)\Component Control\Quantum Control\Quantum.exe", "Quantum.SysMod")
Set oOL = GetObject("Quantum.SysMod")
If oOL is Nothing Then
MsgBox "1- " + Err.Description
MsgBox "1- " + Err.number
End If
MsgBox ("2")
oOL.InspectWO(lcCmd)
MsgBox("3")
A suggestion: comment this line and run the program again.
On Error Resume Next
This line is not allowing you to understand the error because the program will go ahead even though the error is raised.
Welcome to Stack Overflow. I'm still amazed by the number of people who start programming using ancient VBScript, but let's see this through. :)
The first thing you need to do is avoid using On Error Resume Next wherever possible, since this will mask the true cause of your errors. The error you report, Object Required is because oOL has not been set at all due to an error with the line above. If I take your example and allow errors, we'll see that it's complaining about a syntax error stemming from the call to GetObject. I believe you meant to use CreateObject?
Assuming that's the case, you'll have to run it again and see if it works. If not, and you get an error like "ActiveX component can't create object" it means you don't have the necessary DLL installed for Quantum SysMod. You should look at the software's documentation to see about registering it. You can also reference the regsvr32 page.
Again, if you have any other development tools available to you that can load the required component such as, C# or even VB.Net, then you should really try using those instead. VBScript is a terrible language.

VBScript returns an error of "Name redefined"

I have an alert box, and if I'm currently on the test Database, I want the alert box to have different text when compared to live database.
So I declared a variable called isTestDb and set it to True, but I keep getting this annoying error:
Microsoft VBScript compilation error '800a0411'
Name redefined
myfiles/conn_open.asp, line 12
Dim isTestDb
----^
Here is my simple code which sits inside an include at a much higher level than where I'm doing my conditional check, I'm assuming that isn't a problem.
Dim isTestDb
isTestDb = True
-- Much Later in another file somehwere
If isTestDb Then
Response.Write("<h1>It is set to True</h1>")
Response.End
Else
Response.Write("<h1>It is set to False</h1>")
Response.End
End If
I have checked all my working directory and I'm certain that variable is not set somewhere else by the same name, I even tried different names for the variable and got the exact same error.
In my case this was due to the fact that I had referenced the same file twice in my .asp file using:
<!--#include file="myFile.asp">
And the referenced file had the declaration in it hence the second declaration conflicted with the first
This is happenning because the variable, isTestDb has already been defined in another page.
I have no idea why, but when I removed the Dim isTestDb line, it all works as expected now!! :/
it can also be because you are including file you already including in other include file.
For example:
File a.asp is including x.asp.
And in your main file you including both:
<!--#include file="a.asp">
<!--#include file="x.asp">

VB6 "Invalid use of property" error where the code seems fine

I am having a very strange problem. First, the code.
Private Function ProcessRecord(ByVal rsDocs As ADODB.Recordset) As Variant
Dim rsTemp As ADODB.Recordset
rsTemp = rsDocs
rsDocs = RemoveDuplicateDocs(rsTemp)
Exit Function
The error is occurring on the second line of the function, where rsTemp is set equal to rsDocs. It's saying: "Compile error: Invalid use of property". I've looked for information on this error elsewhere, and all the reports are cases where people either forgot an equal sign, or incorrectly added the "Set" command to the beginning of the line of code. This error makes no sense to me, because it was compiling fine before, and the changes I've made to this project are not even in the class that throwing the error. The code here is identical to the way it was before. Has anyone ever seen an error like this pop up for what seems to be no good reason? Thanks!
You need to use
set rsTemp = rsDocs
since rsTemp is an object.

Is it possible to retrieve the call stack programmatically in VB6?

When an error occurs in a function, I'd like to know the sequence of events that lead up to it, especially when that function is called from a dozen different places. Is there any way to retrieve the call stack in VB6, or do I have to do it the hard way (e.g., log entries in every function and error handler, etc.)?
You do have to do it the hard way, but it's not really all that hard... Seriously, once you've written the template once, it's a quick copy/paste/modify to match the function name in the Err.Raise statement to the actual function name.
Private Function DoSomething(ByVal Arg as String)
On Error GoTo Handler
Dim ThisVar as String
Dim ThatVar as Long
' Code here to implement DoSomething...
Exit Function
Handler:
Err.Raise Err.Number, , "MiscFunctions.DoSomething: " & Err.Description
End Function
When you have nested calls, this unwinds as each routine hits its Handler and adds its name to the error description. At the top level function, you get a "call stack" showing the list of routines that were called, and the error number and description of the error that actually occurred. It's not perfect, in that you don't get line numbers, but I've found that you don't usually need them to find your way to the problem. (And if you really want line numbers, you can put them in the function and reference them in the Err.Raise statement using the Erl variable. Without line numbers, that just returns 0.)
Also, note that within the function itself, you can raise your own errors with the values of interesting variables in the message like so:
Err.Raise PCLOADLETTER_ERRNUM, , "PC Load Letter error on Printer """ & PrinterName & """"
(The syntax highlighting looks wonky in the preview... I wonder how will it look when posted?)
I'm pretty sure you have to do it the hard way. At a previous job of mine, we had a very elegant error handling process for VB6 with DCOM components. However, it was a lot redundant code that had to be added to every method, so much that we had home-grown tools to insert it all for you.
I can't provide too much insight on its implementation (both because I've forgotten most of it and there's a chance they may consider it a trade secret). One thing that does stand out was that the method name couldn't be derived at run-time so it was added as a string variable (some developers would copy-paste instead of using the tool and it would lead to error stacks that lied...).
HTH
The hard, manual way is pretty much the only way. If you check out this question, someone suggested a tool called MZTools that will do much of the grunt work for you.
As other people said (years ago, I see... but there's so many people still using VB6! :) ), I think it's not possible to programmatically retrieve the Call Stack, unless you use some 3rd-party tool.
But if you need to do that for debugging purposes, you can consider of adding to the called routine an Optional input string variable, were you'll put the caller's name.
Sub MyRoutine
(...) ' Your code here
call DoSomething (Var1, Var2, Var3, "MyRoutine")
' ^
' Present routine's name -----------+
(...) ' Your code here
End Sub
Public DoSomething (DoVar1, DoVar2, DoVar3, Optional Caller as string = "[unknown]")
Debug.Print " DoSomething Routine Called. Caller = " & Caller
... ' (your code here)
End Sub
Not so elegant, maybe, but it worked for me.
Regards,
Max - Italy
Compuware (or was it Numega at the time) DevStudio for Visual Basic 6 used to do this. The way was by adding adding instrumenation to every call that called a very small snippet that added to the code stack. On any error it dumped out that callstack, and then did things like mail or post to a webserver all the debuging information. Adding and removing the instrumentation was a potentially lethal operation (especially back then, when we were using VSS as our source control), but if it worked, it work well.
As Darrel pointed out, you could add something very simlar by using MZTools and setting up a template. It's a lot of working, and is probably more effeort than the reward would be but if you have very difficult to track down bugs, it might help).

Resources