Page 1 of 1 1
Topic Options
#135824 - 2005-03-16 10:14 PM Integer not Output problem with Array???
rscript99 Offline
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
#135825 - 2005-03-16 10:33 PM Re: Integer not Output problem with Array???
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
What are you saying, that it needs to be a string?
In that case, try:
$Ext=""+$phones[$counter,0]
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#135826 - 2005-03-16 10:48 PM Re: Integer not Output problem with Array???
rscript99 Offline
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
#135827 - 2005-03-17 12:10 AM Re: Integer not Output problem with Array???
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Well... now I am even more confused.

Check the VarTypeName($ext) and if it is integer and you want it to be a string, cast it as per my example. You should not put vars in quotes like you do. Also, @CRLF is easier than CHR().
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#135828 - 2005-03-17 09:40 PM Re: Integer not Output problem with Array???
rscript99 Offline
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
#135829 - 2005-03-17 09:49 PM Re: Integer not Output problem with Array???
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
You assume wrong. I mean as in the line:
WriteLine(1,"telephoneNumber: $ext"+ Chr(13) + Chr(10))

Should be:
WriteLine(1,"telephoneNumber: " + $ext + @CRLF)


Edited by Les (2005-03-17 11:41 PM)
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#135830 - 2005-03-17 10:55 PM Re: Integer not Output problem with Array???
rscript99 Offline
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
#135831 - 2005-03-17 11:02 PM Re: Integer not Output problem with Array???
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Quote:

I guess it is because you can't have different data types in an array



You guess wrong! It is still an integer in the array. It's just that it gets cast as a string later.

{sigh}
I don't know how to get through to you. Your problem is that you were trying to embed an integer inside a string. When you concatenate as per my example, KiX will cast it as a string. I thought the numerous examples would have mad that clear.

BTW, vars in strings are evil, and the sooner you break yourself of the habit, the better.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#135832 - 2005-03-17 11:09 PM Re: Integer not Output problem with Array???
Les Offline
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 Offline
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
#135834 - 2005-03-17 11:44 PM Re: Integer not Output problem with Array???
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
You're welcome.

My attitude and I are inseparable... sorry.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.067 seconds in which 0.032 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org