#135824 - 2005-03-16 10:14 PM
Integer not Output problem with Array???
|
rscript99
Fresh Scripter
Registered: 2005-03-14
Posts: 6
|
I wrote a script that takes an Excel spreadsheet and outputs it to an.ldf which I will import later to populate the telephoneNumber field in AD. Everything works properly except the $ext variable does not output any data. It appears that the problem is because the $ext field is an integer, since I can add text to the field in Excel and it starts working.
I am posting the code minus the ReadExcel2 UDF. Any help with this problem would be appreciated.
Code:
Break ON $phones = ReadExcel2('c:\phone list.xls',,-1,5) For $counter=1 to ubound($phones,1) $Ext=$phones[$counter,0] $givenName=$phones[$counter,2] $extra=$phones[$counter,4] $sn=$phones[$counter,3] $sn=$phones[$counter,3]
IF $extra="" $sn=$phones[$counter,3] Else $sn=Left($phones[$counter,3],1)+$extra ENDIF $cn=Left($givenName,1)+$sn $cn8=Left($givenName,1)+Left($sn,7) $DN="CN=$cn,OU=mycity,DC=mydomain,DC=com" $DN2="CN=$cn8,OU=mycity,DC=mydomain,DC=com"
Open(1,"c:\extensionsrb.ldf",5) WriteLine(1,"DN: $DN"+ Chr(13) + Chr(10)) WriteLine(1,"changetype: modify"+ Chr(13) + Chr(10))
WriteLine(1,"replace: telephoneNumber"+ Chr(13) + Chr(10)) WriteLine(1,"telephoneNumber: $ext"+ Chr(13) + Chr(10)) WriteLine(1,"-"+ Chr(13) + Chr(10)) WriteLine(1,Chr(13) + Chr(10))
IF $DN<>$DN2 WriteLine(1,"DN: $DN2"+ Chr(13) + Chr(10)) WriteLine(1,"changetype: modify"+ Chr(13) + Chr(10))
WriteLine(1,"replace: telephoneNumber"+ Chr(13) + Chr(10)) WriteLine(1,"telephoneNumber: $ext"+ Chr(13) + Chr(10)) WriteLine(1,"-"+ Chr(13) + Chr(10)) WriteLine(1,Chr(13) + Chr(10)) ENDIF
Next
|
|
Top
|
|
|
|
#135826 - 2005-03-16 10:48 PM
Re: Integer not Output problem with Array???
|
rscript99
Fresh Scripter
Registered: 2005-03-14
Posts: 6
|
Sorry if I am not saying it right. To be more specific, all of the elements in the array are text (First Name or Last Name) except $Ext which is a 4 digit extension (i.e. 1234). All of the other elements are output to the .ldf file with no problems, but for some reason the $ext variable is not output or is output with no value.
The only difference I see is that the extension is a number and not text.
Not sure if this is what you understood from my orginal post but I will try it.
|
|
Top
|
|
|
|
#135828 - 2005-03-17 09:40 PM
Re: Integer not Output problem with Array???
|
rscript99
Fresh Scripter
Registered: 2005-03-14
Posts: 6
|
I guess what I am saying is that I really don't care if it is an integer or a string as long as it passes the data to the output file. What I am wondering is, whether there is a rule or something that does not allow a mixture of string values and integer values to exist in the same array. I appreciate the code you gave me and I am getting ready to try it, but I am just wondering why the script did not work without this extra code.
Also, I don't always put quotes around my variables, not sure why I did here. I will take them off and see what happens. - I'm assuming you are talking about when I declare them.
|
|
Top
|
|
|
|
#135830 - 2005-03-17 10:55 PM
Re: Integer not Output problem with Array???
|
rscript99
Fresh Scripter
Registered: 2005-03-14
Posts: 6
|
OK, I got you, I guess I do that because so far it works for me. I would rather keep the lines as literal as possible without piecing them together with a bunch of "+" symbols. Maybe it's wrong, but as long as it works I probably will still do it.
I tried the code you gave me and that did the trick. Thank you! I still don't know why it wouldn't work without that code, but I guess it is because you can't have different data types in an array.
I tried removing the quotes from these lines: Code:
$DN="CN=$cn,OU=MyCity,DC=MyDomain,DC=com" $DN2="CN=$cn8,OU=MyCity,DC=MyDomain,DC=com" But it caused the script to fail. Thanks again for all of your help.
|
|
Top
|
|
|
|
#135832 - 2005-03-17 11:09 PM
Re: Integer not Output problem with Array???
|
Les
KiX Master
   
Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
|
Oh, and the NoVarsInStrings way to do these is: $DN="CN="+$cn+",OU=MyCity,DC=MyDomain,DC=com" $DN2="CN="+$cn8+",OU=MyCity,DC=MyDomain,DC=com"
It is not a matter of clarity, it is simply laziness. In your version of the above example, it is not clear that on the second line, the varname is $cn8 and not $cn.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.
|
|
Top
|
|
|
|
#135833 - 2005-03-17 11:29 PM
Re: Integer not Output problem with Array???
|
rscript99
Fresh Scripter
Registered: 2005-03-14
Posts: 6
|
Quote:
Quote:
You assume wrong.
Quote:
You guess wrong!
Quote:
{sigh}I don't know how to get through to you.
Quote:
I thought the numerous examples would have mad that clear.
Man, I don't know how to take you, on one hand you seem like you want to help, but then you complain while you're doing it.
I want to thank you again for your help, but IMHO you could afford to lose the attitude. Not everyone is an expert, in fact this is the first script I've written using arrays.
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 2220 anonymous users online.
|
|
|