Page 1 of 1 1
Topic Options
#156797 - 2006-02-07 04:12 PM VBS "MID" equivalent
DrShark Offline
Fresh Scripter

Registered: 2005-07-13
Posts: 33
All,

can someone give a hint and tell me the best KIX equivalent for the VBScript "MID"!?

Best Regards

Top
#156798 - 2006-02-07 04:38 PM Re: VBS "MID" equivalent
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
SubStr(), also Left() and Right().
Top
#156799 - 2006-02-07 04:39 PM Re: VBS "MID" equivalent
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
Substr() function maybe?
Top
#156800 - 2006-02-07 05:00 PM Re: VBS "MID" equivalent
DrShark Offline
Fresh Scripter

Registered: 2005-07-13
Posts: 33
Then someone may help me with this function - I translated it to KIX but it raises an error and does not give back the desired value.

Code:

$strTest="LDAP://CN=DrShark,OU=1,OU=2,OU=3,OU=Test,DC=test,DC=dom"
$TestOU = getFirstOU($strTest)
MessageBox($TestOU,"")

Function getFirstOU($LDAP)

If instr(UCase($LDAP),"OU=")>0
$strStringAnfang=instr(UCase($LDAP),"OU=")+3
Else
$strStringAnfang=instr(UCase($LDAP),"DC=")+3
EndIf

$strStringEnde=instr(UCase($LDAP),",")
$strStringLength=($strStringEnde-$strStringAnfang)

$temp=Substr($LDAP,$strStringAnfang,$strStringLength)

getFirstOU=$temp

EndFunction


Top
#156801 - 2006-02-07 05:09 PM Re: VBS "MID" equivalent
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
$strStringEnde=instr(UCase($LDAP),",")

does not do what you want.
at least I believe so.
would guess you are after something like:
Code:

$strTest="LDAP://CN=DrShark,OU=1,OU=2,OU=3,OU=Test,DC=test,DC=dom"
$TestOU = getFirstOU($strTest)
MessageBox($TestOU,"")

Function getFirstOU($LDAP)

If instr(UCase($LDAP),"OU=")>0
$LDAP = substr($LDAP, instr(UCase($LDAP),"OU=")+3)
Else
$LDAP = substr($LDAP, instr(UCase($LDAP),"DC=")+3)
EndIf
getFirstOU= substr($LDAP,1, instr(ucase($LDAP),",") - 1)
EndFunction

_________________________
!

download KiXnet

Top
#156802 - 2006-02-07 05:20 PM Re: VBS "MID" equivalent
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Golfed:
Break ON
$DN="LDAP://CN=DrShark,OU=1,OU=2,OU=3,OU=Test,DC=test,DC=dom"
$ = Split(Split(Split($DN,'cn=')[1],',dc=')[0],',ou=')[1]
$ ?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#156803 - 2006-02-07 05:26 PM Re: VBS "MID" equivalent
DrShark Offline
Fresh Scripter

Registered: 2005-07-13
Posts: 33
I am after the coplete string so after calling the function it should be someting like this: "OU=1,OU=2,OU=3,OU=Test,DC=test,DC=dom".

But when using your suggestion it says: Missing "(" in line 12...

Top
#156804 - 2006-02-07 06:15 PM Re: VBS "MID" equivalent
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
so, if you are after the whole string, what you try to accomplish with:
$strStringEnde=instr(UCase($LDAP),",")

???
_________________________
!

download KiXnet

Top
#156805 - 2006-02-07 06:38 PM Re: VBS "MID" equivalent
DrShark Offline
Fresh Scripter

Registered: 2005-07-13
Posts: 33
Quote:

so, if you are after the whole string, what you try to accomplish with:
$strStringEnde=instr(UCase($LDAP),",")





I just copy&pasted the code from some other vbs scripts where I need it and I am now trying to convert it to KiX.

If you see some improvements or code that is obsolet let me know. I only need this string mentioned above for further steps.

Top
#156806 - 2006-02-07 07:48 PM Re: VBS "MID" equivalent
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
OK, if you want the Right() of it...
(not golfed)
Break ON
$DN="LDAP://CN=DrShark,OU=1,OU=2,OU=3,OU=Test,DC=test,DC=dom"
$Len = Len($DN)
$Len ?
$InStr = InStr($DN,',ou=')
$InStr ?
$ = Right($DN,$Len-$InStr)
$ ?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#156807 - 2006-02-07 08:11 PM Re: VBS "MID" equivalent
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
but...
drshark...
why your udf is named "getFirstOU" if you want the whole string?

if you want the whole string single line of substr is enough.
_________________________
!

download KiXnet

Top
#156808 - 2006-02-07 10:33 PM Re: VBS "MID" equivalent
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
You mean better than this?
$DN="LDAP://CN=DrShark,OU=1,OU=2,OU=3,OU=Test,DC=test,DC=dom"
$ = Right($DN,Len($DN)-InStr($DN,',ou='))
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#156809 - 2006-02-08 12:10 AM Re: VBS "MID" equivalent
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
les, yes.
$DN="LDAP://CN=DrShark,OU=1,OU=2,OU=3,OU=Test,DC=test,DC=dom"
$ = substr($DN,1+InStr($DN,',ou='))
_________________________
!

download KiXnet

Top
#156810 - 2006-02-08 12:25 AM Re: VBS "MID" equivalent
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
and that's why I don't play golf
_________________________
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:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 641 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.065 seconds in which 0.024 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