Page 1 of 1 1
Topic Options
#113474 - 2004-02-06 11:21 AM Help..strange character t the end of value?
Grutte Pier Offline
Getting the hang of it

Registered: 2001-10-06
Posts: 52
Loc: Leeuwarden, The Netherlands
Hello,

I've make this script using two functions (udfSqueeze and WshPipe) and all goes just fine but when I write the value to the reg the value shows at right place but at the end a strange character that looks like a Pipe ("|") is added to the value.
The value sould be:
\\servername\NSSVOL1\USERS\ICT\BILLG
but it shows:
\\servername\NSSVOL1\USERS\ICT\BILLG|

this is my code:
Code:

; -----------------------------------------------------------------------
; Doc_path.kix
; -----------------------------------------------------------------------
; The script changes the destination of the default document location of
; the applications:
; MS Excel
; MS Word
; MS Powerpoint
; -----------------------------------------------------------------------
; Samengesteld door Frans Erich
; -----------------------------------------------------------------------
; Updated by
;
; -----------------------------------------------------------------------
; Dependencies
; - Kixtart version 4.1 or later
; - Function udfSqueeze
; - Function WshPipe
; - Windows Script Host
; -----------------------------------------------------------------------
; Credits to
; The builetin board communities of www.kixtart.org and www.kixscripts.com
; Special thanks to builetin board modorators:
; - Richard H.
; - sealeopard
; - Chris S.
; - NTDOC
; -----------------------------------------------------------------------
; Variables
$search=" H:"
$word_key="HKEY_CURRENT_USER\Software\Microsoft\Office\8.0\Word\Options"
; -----------------------------------------------------------------------

Function udfSqueeze($sSource,Optional $sDelimiters, Optional $bTrim)
Dim $iSourceLength $iSourceLength=0
Dim $iIndex $iIndex=0
Dim $iLastGood $iLastGood=0
Dim $bFound $bFound=0

$udfSqueeze=""

; --------------------------
; Defaults and sanity checks
; --------------------------
If $sDelimiters="" $sDelimiters=" " EndIf
If $bTrim $bTrim=1 Else $bTrim=0 EndIf

; ----------------------------------------
; High speed squeeze for single characters
; ----------------------------------------
If Len($sDelimiters)=1
$sDelimiters=""+$sDelimiters+$sDelimiters
$iIndex=InStr($sSource,$sDelimiters)
While $iIndex
$sSource=""+SubStr($sSource,1,$iIndex)+SubStr($sSource,$iIndex+2,Len($sSource))
$iIndex=InStr($sSource,$sDelimiters)
Loop
If $bTrim
$sDelimiters=SubStr($sDelimiters,1,1)
; -------------
; Trim leading.
; -------------
While SubStr($sSource,1,1)=$sDelimiters
$sSource=SubStr($sSource,2,Len($sSource))
Loop
; --------------
; Trim Trailing.
; --------------
$iIndex=Len($sSource)
While SubStr($sSource,$iIndex,1)=$sDelimiters
$sSource=SubStr($sSource,1,$iIndex-1)
$iIndex=Len($sSource)
Loop
EndIf
$udfSqueeze=$sSource
Else
; --------------------------------------
; Slower squeeze for multiple characters
; --------------------------------------
$iSourceLength=Len($sSource)
For $iIndex = 1 To $iSourceLength
$cChar=SubStr($sSource,$iIndex,1)
If InStr($sDelimiters,$cChar)
If $bFound=0 AND ( $iLastGood OR $bTrim=0 )
$udfSqueeze=""+$udfSqueeze+SubStr($sDelimiters,1,1)
EndIf
$bFound=1
Else
$bFound=0
$udfSqueeze=""+$udfSqueeze+$cChar
If $bTrim $iLastGood=Len($udfSqueeze) EndIf
EndIf
Next
If $iLastGood $udfSqueeze=SubStr($udfSqueeze,1,$iLastGood) EndIf
EndIf

EndFunction
Function WshPipe($ShellCMD, OPTIONAL $NoEcho)
Dim $oExec, $Output
$oExec = CreateObject("WScript.Shell").Exec($ShellCMD)
If NOT VarType($oExec)=9 $WshPipe="WScript.Shell Exec Unsupported" Exit 10 EndIf
While NOT $oExec.Status Loop
$Output = $oExec.StdOut.ReadAll + $oExec.StdErr.ReadAll
If NOT $NoEcho $Output EndIf
$WshPipe=Split($Output,Chr(10))
Exit($oExec.ExitCode)
EndFunction

Break on
$rc=WshPipe("%comspec% /c net use",1)
For Each $line In $rc
If InStr($line,$search)
$linepart=Split(udfSqueeze($line," ","true"))
$ = WriteValue ($word_key,"DOC-PATH",$linepart[2],"reg_sz")
? $linepart[2]
EndIf
Next
:END




Thanks,

GP


Top
#113475 - 2004-02-06 12:01 PM Re: Help..strange character t the end of value?
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Odd. I've just tried it and it works fine (Kix 4.22, WinXP)
Top
#113476 - 2004-02-06 12:04 PM Re: Help..strange character t the end of value?
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
View the value as binary and check the ASCII value - my guess is that it is a carriage return 0x0d
Top
#113477 - 2004-02-06 01:25 PM Re: Help..strange character t the end of value?
Grutte Pier Offline
Getting the hang of it

Registered: 2001-10-06
Posts: 52
Loc: Leeuwarden, The Netherlands
Hello Richard,

How should I do this? And if it is a carriage return how can I prevent it from showing?

Thanks,

GP

Top
#113478 - 2004-02-06 02:59 PM Re: Help..strange character t the end of value?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hmm...
use reg-edit and check the type of the value.
is it really string or multi-string?
_________________________
!

download KiXnet

Top
#113479 - 2004-02-06 03:14 PM Re: Help..strange character t the end of value?
Grutte Pier Offline
Getting the hang of it

Registered: 2001-10-06
Posts: 52
Loc: Leeuwarden, The Netherlands
Hello Lonkero,

I've been there and the type is string.
Can't I trim of the character with some command?
I've tried Ltrim

Thanks,

GP

Top
#113480 - 2004-02-06 04:00 PM Re: Help..strange character t the end of value?
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
As specified in the KiXtart Manual, LTRIM only removes leading spaces. See for example LEFT or RIGHT.
_________________________
There are two types of vessels, submarines and targets.

Top
#113481 - 2004-02-06 04:33 PM Re: Help..strange character t the end of value?
Grutte Pier Offline
Getting the hang of it

Registered: 2001-10-06
Posts: 52
Loc: Leeuwarden, The Netherlands
OK
So I have to count the characters and then with left strip all characters but one and make that the new value.

But how do I count characters?

Thanks,

GP

Top
#113482 - 2004-02-06 04:44 PM Re: Help..strange character t the end of value?
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
in a string ?

len() will do that
_________________________



Top
#113483 - 2004-02-06 04:44 PM Re: Help..strange character t the end of value?
Grutte Pier Offline
Getting the hang of it

Registered: 2001-10-06
Posts: 52
Loc: Leeuwarden, The Netherlands
I've got it.

Code:


; -----------------------------------------------------------------------
; Doc_path.kix
; -----------------------------------------------------------------------
; The script changes the destination of the default document location of
; the applications:
; MS Excel
; MS Word
; MS Powerpoint
; -----------------------------------------------------------------------
; Samengesteld door Frans Erich
; f.j.erich@ict.azg.nl
; f.erich@chello.nl
; -----------------------------------------------------------------------
; Updated by
;
; -----------------------------------------------------------------------
; Dependencies
; - Kixtart version 4.1 or later
; - Function udfSqueeze
; - Function WshPipe
; - Windows Script Host
; -----------------------------------------------------------------------
; Credits to
; The builetin board communities of www.kixtart.org and www.kixscripts.com
; Special thanks to builetin board modorators:
; - Richard H.
; - sealeopard
; - Chris S.
; - NTDOC
; -----------------------------------------------------------------------
; Variables
$search = " H:"
$word_key = "HKEY_CURRENT_USER\Software\Microsoft\Office\8.0\Word\Options"
$excel_key = "HKEY_CURRENT_USER\Software\Microsoft\Office\8.0\Excel\Microsoft Excel"
$powerpoint_key = "HKEY_CURRENT_USER\Software\Microsoft\Office\8.0\PowerPoint\Recent Folder List\Default"
; -----------------------------------------------------------------------

Function udfSqueeze($sSource,Optional $sDelimiters, Optional $bTrim)
Dim $iSourceLength $iSourceLength=0
Dim $iIndex $iIndex=0
Dim $iLastGood $iLastGood=0
Dim $bFound $bFound=0

$udfSqueeze=""

; --------------------------
; Defaults and sanity checks
; --------------------------
If $sDelimiters="" $sDelimiters=" " EndIf
If $bTrim $bTrim=1 Else $bTrim=0 EndIf

; ----------------------------------------
; High speed squeeze for single characters
; ----------------------------------------
If Len($sDelimiters)=1
$sDelimiters=""+$sDelimiters+$sDelimiters
$iIndex=InStr($sSource,$sDelimiters)
While $iIndex
$sSource=""+SubStr($sSource,1,$iIndex)+SubStr($sSource,$iIndex+2,Len($sSource))
$iIndex=InStr($sSource,$sDelimiters)
Loop
If $bTrim
$sDelimiters=SubStr($sDelimiters,1,1)
; -------------
; Trim leading.
; -------------
While SubStr($sSource,1,1)=$sDelimiters
$sSource=SubStr($sSource,2,Len($sSource))
Loop
; --------------
; Trim Trailing.
; --------------
$iIndex=Len($sSource)
While SubStr($sSource,$iIndex,1)=$sDelimiters
$sSource=SubStr($sSource,1,$iIndex-1)
$iIndex=Len($sSource)
Loop
EndIf
$udfSqueeze=$sSource
Else
; --------------------------------------
; Slower squeeze for multiple characters
; --------------------------------------
$iSourceLength=Len($sSource)
For $iIndex = 1 To $iSourceLength
$cChar=SubStr($sSource,$iIndex,1)
If InStr($sDelimiters,$cChar)
If $bFound=0 AND ( $iLastGood OR $bTrim=0 )
$udfSqueeze=""+$udfSqueeze+SubStr($sDelimiters,1,1)
EndIf
$bFound=1
Else
$bFound=0
$udfSqueeze=""+$udfSqueeze+$cChar
If $bTrim $iLastGood=Len($udfSqueeze) EndIf
EndIf
Next
If $iLastGood $udfSqueeze=SubStr($udfSqueeze,1,$iLastGood) EndIf
EndIf

EndFunction
Function WshPipe($ShellCMD, OPTIONAL $NoEcho)
Dim $oExec, $Output
$oExec = CreateObject("WScript.Shell").Exec($ShellCMD)
If NOT VarType($oExec)=9 $WshPipe="WScript.Shell Exec Unsupported" Exit 10 EndIf
While NOT $oExec.Status Loop
$Output = $oExec.StdOut.ReadAll + $oExec.StdErr.ReadAll
If NOT $NoEcho $Output EndIf
$WshPipe=Split($Output,Chr(10))
Exit($oExec.ExitCode)
EndFunction

Break on
$CharNr = ""
$rc=WshPipe("%comspec% /c net use",1)
For Each $line In $rc
If InStr($line,$search)
$linepart=Split(udfSqueeze($line," ","true"))
; The next 3 lines strip a cha
$CharNr = Len ($linepart[2])
$CharNr = $CharNr - 1
$pad = Left ($linepart[2],$CharNr)
$ = WriteValue ($word_key,"DOC-PATH",$pad,"reg_sz")
$ = WriteValue ($excel_key,"DefaultPath",$pad,"reg_sz")
$ = WriteValue ($powerpoint_key,"",$pad,"reg_sz")
$linepart[2] ?

EndIf
Next
:END



Thanks a lot for the help you gave,

GP

Top
#113484 - 2004-02-06 05:35 PM Re: Help..strange character t the end of value?
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
You don't even need to count characters as the LEFT/RIGHT function accept negative numbers. This is all explained in the KiXtart Manual!
_________________________
There are two types of vessels, submarines and targets.

Top
#113485 - 2004-02-07 02:12 AM Re: Help..strange character t the end of value?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
my first shot is to do actually what was suggested (kinda) at the beginning.

do:

"last mark is:" right($my_bloody_string,1) ?
"in ascii that is:" asc(right($my_bloody_string,1))


this way you and us can benefit from your findings.


Edited by Lonkero (2004-02-11 02:27 PM)
_________________________
!

download KiXnet

Top
#113486 - 2004-02-11 01:39 PM Re: Help..strange character t the end of value?
Grutte Pier Offline
Getting the hang of it

Registered: 2001-10-06
Posts: 52
Loc: Leeuwarden, The Netherlands
That generates this error:

Invalid method/function call: missing ')'!

in line 120

And line 120 is:

the just added line
Code:

"in ascii that is:" Asc(rigth($linepart,1)) ?



thanks,

GP



Top
#113487 - 2004-02-11 02:28 PM Re: Help..strange character t the end of value?
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
ja, the right was wrongly written.
instead of RIGHT it was RIGTH.

talk about bad english.
_________________________
!

download KiXnet

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 756 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.075 seconds in which 0.051 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