Georges_K
(Getting the hang of it)
2006-08-16 11:19 PM
Error in Expression... need an extra set of eyes...

Hi guys,
Sorry if this question sounds pretty simple (which it usually ends up being so). Please keep in mind, that I'm a novice scripter.

I'm having this problem with an array that I'm trying to create, and I am always getting an "Error in Expression" error when I get to that line. I read the book, and looked up scripts, and I can't seem to figure out what I'm doing wrong. I know the exact line in my script where it's failing...

here's the script:

Code:
Break ON
$ = SetOption("NoVarsInStrings",On)
$ = SetOption("Explicit",On)
Call ("C:\Scripts\kix\CVUSD\udf.kix")
Global $un,$ou,$handle,$LINE,$LineCount
Dim $a, $answer
? "User? "
Gets $un

? "OU? "
Gets $ou

EnumerateUsers($un,$ou)

Function EnumerateUsers(Optional $un, Optional $ou)
Shell '%COMSPEC% /C dsquery user -limit 0 -name *' + $un + '* -o dn > pathCheck_dn.dat'

Dim $user,$users, $slashed, $last, $first, $myOU, $element, $i, $ouStore, $ouCount
Dim $handle $handle=FreeFileHandle()
$ = Open($handle,"pathCheck_dn.dat",2)
$LINE=ReadLine($handle)
Do
; Let's create the Array out of the string in the file, comma delimited
$users=Split($LINE,",")

; Scanning for the existence of the ou
$element=0
$ouCount=0
For $element=0 to UBound($users)
$myOU = AScan($users,$ou,$element,,1);
? "$$myOU: " + $myOU ? "$$ou: " + $ou ? "$$element: " + $element ? "$$users[$element]: " +$users[$element] ?
If ($myOU = $element) And InStr($users[$element],"OU") And InStr($users[$element],$ou)
? $users[$element]
$ouStore[$ouCount] = $users[$element]
$ouCount=$ouCount + 1
EndIf
Next

; Getting the LAST NAME, removing the description of the field i.e CN= , and the baskslash to escape the comma
$slashed = Right($users[0],Len($users[0]) - Len(Left($users[0],4)))
$last = Left($slashed,Len($slashed) - Len(Left($slashed,1)))

; This is the First Name
$first = $users[1]
; Print it out
;? $LINE
? $first + " " + $last ?
? "$$ouStore Limit:" UBound($ouStore)
For $i = 0 to UBound($ouStore)
If $ouStore <> ''
"OUs Found: " $ouStore[$i] + Chr(9)
EndIf
Next


; Read the Next Line
$LINE=ReadLine($handle)

; Clean Up
Until @ERROR = -1
Close($handle)
If Exist("@SCRIPTDIR\pathCheck_dn.dat")
Del ("@SCRIPTDIR\pathCheck_dn.dat")
EndIf
EndFunction



The exact error I'm getting is this:
ERROR : error in expression!
Script: C:\scripts\kix\CVUSD\Utils\Search.kix
Line : 111


I have tried defining the size of the array ($ouStore[500]) just for the heck of it, but that didn't work either.

Any ideas?

p.s: I am aware that are some unhandled situation in this script, I am not nearly done with it yet ... I'm just eager to figure out this array issue first..
Thank you in advance.


Mart
(KiX Supporter)
2006-08-16 11:29 PM
Re: Error in Expression... need an extra set of eyes...

Error on line 111 Your script only has 64 lines so is this the entire script? Guess not or there is some kind of typo.

Georges_K
(Getting the hang of it)
2006-08-16 11:36 PM
Re: Error in Expression... need an extra set of eyes...

Haa ... you know I didn't think about that, I actually took out a bunch of Commented out DEBUG lines, and I'm also using the ASE editor, so it adds some 32 lines of Scripts settings on top which I ommited as well.. so the line number is correct in my editor... but for the record, line 111 does correspond with the, now, red line in the code. (sorry about the confusion)

NTDOCAdministrator
(KiX Master)
2006-08-16 11:59 PM
Re: Error in Expression... need an extra set of eyes...

Well not even really reviewing your code I get this back from SANITY.UDF

Code:
Warning: Global variable declared as Local.
Variable Name: $un
In function: EnumerateUsers
Referenced on line: 15
Global declared on line: 5

Warning: Global variable declared as Local.
Variable Name: $ou
In function: EnumerateUsers
Referenced on line: 15
Global declared on line: 5

Warning: Global variable declared as Local.
Variable Name: $handle
In function: EnumerateUsers
Referenced on line: 19
Global declared on line: 5

Warning: Undeclared variable.
Variable Name: $
In function: Main
Referenced on line: 2

Warning: Undeclared variable.
Variable Name: $
In function: EnumerateUsers
Referenced on line: 20

Warning: Undeclared variable.
Variable Name: $myOU:
In function: EnumerateUsers
Referenced on line: 31

Warning: Variable referenced inside string.
Variable Name: $myOU:
In function: EnumerateUsers
Referenced on line: 31

Warning: Undeclared variable.
Variable Name: $ou:
In function: EnumerateUsers
Referenced on line: 31

Warning: Variable referenced inside string.
Variable Name: $ou:
In function: EnumerateUsers
Referenced on line: 31

Warning: Undeclared variable.
Variable Name: $element:
In function: EnumerateUsers
Referenced on line: 31

Warning: Variable referenced inside string.
Variable Name: $element:
In function: EnumerateUsers
Referenced on line: 31

Warning: Variable referenced inside string.
Variable Name: $users
In function: EnumerateUsers
Referenced on line: 31

Warning: Variable referenced inside string.
Variable Name: $element
In function: EnumerateUsers
Referenced on line: 31

Warning: Variable referenced inside string.
Variable Name: $ouStore
In function: EnumerateUsers
Referenced on line: 48

14 warnings encountered in 65 lines.



Georges_K
(Getting the hang of it)
2006-08-17 12:06 AM
Re: Error in Expression... need an extra set of eyes...

Hm.. that's a cool UDF, i didn't know about it... let me look into that...
Thanks Doc,
I'll post again if after fixing those, I still have problems with this array.


LonkeroAdministrator
(KiX Master Guru)
2006-08-17 12:07 AM
Re: Error in Expression... need an extra set of eyes...

the issue is, you dim $ouStore as normal variable and then try to access it as if it was a array.

Georges_K
(Getting the hang of it)
2006-08-17 12:12 AM
Re: Error in Expression... need an extra set of eyes...

Would Dim-ing it as $ouStore[] declare it as an array? that didn't seem to work either, even when I declared it as $ouStore[10] ...

LonkeroAdministrator
(KiX Master Guru)
2006-08-17 12:23 AM
Re: Error in Expression... need an extra set of eyes...

well, it does work to some point.
but ofcourse, you can't access out side of it's bounds.
nor use array inside strings. obviously.


Georges_K
(Getting the hang of it)
2006-08-17 12:30 AM
Re: Error in Expression... need an extra set of eyes...

so, what would be the correct way to assign an array element to another array ....

I guess I'm just not quite clear about that.
As I mentioned before, I am newbie, so I'm trying to learn the ropes here. I do appreciate your patience!


LonkeroAdministrator
(KiX Master Guru)
2006-08-17 12:35 AM
Re: Error in Expression... need an extra set of eyes...

well, to get you started, that 500 element dim sounds fitting.

but...
If $ouStore <> ''

you can't test against the whole array.
the element yes.


btw, doc, just realised that sanity checker is buggy.


Georges_K
(Getting the hang of it)
2006-08-17 12:44 AM
Re: Error in Expression... need an extra set of eyes...

Thanks.
though I looked more into the "variables in string" that you guys (or rather the sanity script). and it's actually incorrect. the "var in strings" that it's finding are ones that I really did put as "$$variable name" to print out the variable name (as a label) for debugging purposes. Thus the line that looks like this:
? "$$myOU: " + $myOU (Sanity is catching "$$myOU" as a var in string, which is incorrect I think)

I know that I still have some issues with some var declarations. (still have some confusion regarding the scope of variables)


NTDOCAdministrator
(KiX Master)
2006-08-17 01:37 AM
Re: Error in Expression... need an extra set of eyes...

Quote:

btw, doc, just realised that sanity checker is buggy




Well it's not my code. It's Glenn's code, but in discussion about it, he did say that it's not perfect. It's designed to assist you in discovering potential issues in your code.

If you know what you've written is correct then just ignore the output. It's a warning, not a directive.


Georges_K
(Getting the hang of it)
2006-08-17 01:40 AM
Re: Error in Expression... need an extra set of eyes...

That's cool, thanks guys. I figured out my problem, and the Sanity checker actually did help with it.

Thanks for your assistance.