Page 1 of 2 12>
Topic Options
#120851 - 2004-06-08 07:04 PM VBSCRIPT converted to KIXTART (Set Statement)
ktodi Offline
Getting the hang of it

Registered: 2002-03-29
Posts: 60
The script posted below was a working vbscript that I am attempting to now run from kixtart. I am getting an error on first SET statement then the script quits. What change should I make to get it to work?

$w2kwxp = @PRODUCTTYPE = "Windows 2000 Professional" OR @PRODUCTTYPE = "Windows XP Professional"

If $w2kwxp
Dim $WSHNetwork, $fso
Set $WSHNetwork = CreateObject("WScript.Network")
Set $fso = CreateObject("Scripting.FileSystemObject")

Dim $LogEntry
$UName = @USERID
$DName = @LDOMAIN
$CName = @WKSTA

Dim $Status
$Status = "NotLogged"
If $fso.FileExists("\\nserv\wkslogs$\" & $CName & ".txt") Then
Dim $SearchString
$SearchString = ($DName & "\" & $UName)
Dim $ParseFile, $TextStream, $TextLine
Set $ParseFile = $fso.GetFile("\\nserv\wkslogs$\" & $CName & ".txt")
Set $TextStream = $ParseFile.OpenAsTextStream
Do While Not $TextStream.AtEndOfStream
$TextLine = $TextStream.ReadLine
If InStr(1,$TextLine,$SearchString,1) <> 0 Then
Status = "AlreadyLogged"
End If
Loop
$TextStream.Close
End If



If $Status = "NotLogged" Then
Dim $Logfile
$Logfile = ("\\nserv\wkslogs$\" & $CName & ".txt")
Dim ologfile
Set $ologfile = fso.OpenTextFile($Logfile, 8, True)
$ologfile.writeline ($DName & "\" & $UName)
$ologfile.close
End If
End If

Sleep 7

Exit

Top
#120852 - 2004-06-08 07:19 PM Re: VBSCRIPT converted to KIXTART (Set Statement)
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Just lose the SET. There is no SET command in KiX.

You also need to change the ampersand (&) to plus (+) and you should avoid vars in strings cuz they are evil.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#120853 - 2004-06-08 07:27 PM Re: VBSCRIPT converted to KIXTART (Set Statement)
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
You should also change your "Do While Not ..." to "While Not ..."

In other words, just remove the "Do".
_________________________
Eric

Top
#120854 - 2004-06-08 07:28 PM Re: VBSCRIPT converted to KIXTART (Set Statement)
ktodi Offline
Getting the hang of it

Registered: 2002-03-29
Posts: 60
Thanks for the advice and help. How would you poputale the string then without using variables? Would you create arrays?
Top
#120855 - 2004-06-08 07:35 PM Re: VBSCRIPT converted to KIXTART (Set Statement)
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I am talking about embedding vars inside strings. It is fine to build a var by concatenating strings and vars.

'this is a $var in a string' ;EVIL
$var2 = 'this is a ' + $var + ' concatenated' ;GOOD

use NoVarsInStrings to rid yourself of the evil ways.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#120856 - 2004-06-08 07:39 PM Re: VBSCRIPT converted to KIXTART (Set Statement)
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
where exactly do you see the vars in strings?
_________________________
Eric

Top
#120857 - 2004-06-08 07:43 PM Re: VBSCRIPT converted to KIXTART (Set Statement)
ktodi Offline
Getting the hang of it

Registered: 2002-03-29
Posts: 60
Her is the script with the "Do" and "set" commands removed and the "&" replaced with +. The script does not work and I get no errors, any advice?

$w2kwxp = @PRODUCTTYPE = "Windows 2000 Professional" OR @PRODUCTTYPE = "Windows XP Professional"

If $w2kwxp
Dim $WSHNetwork, $fso
$WSHNetwork = CreateObject("WScript.Network")
$fso = CreateObject("Scripting.FileSystemObject")

Dim $LogEntry
$UName = @USERID
$DName = @LDOMAIN
$CName = @WKSTA

Dim $Status
$Status = "NotLogged"
If $fso.FileExists("\\nserv\wkslogs$\" + $CName + ".txt") Then
Dim $SearchString
$SearchString = ($DName + "\" + $UName)
Dim $ParseFile, $TextStream, $TextLine
$ParseFile = $fso.GetFile("\\nserv\wkslogs$\" + $CName + ".txt")
$TextStream = $ParseFile.OpenAsTextStream
While Not $TextStream.AtEndOfStream
$TextLine = $TextStream.ReadLine
If InStr(1,$TextLine,$SearchString,1) <> 0 Then
Status = "AlreadyLogged"
End If
Loop
$TextStream.Close
End If



If $Status = "NotLogged" Then
Dim $Logfile
$Logfile = ("\\nserv\wkslogs$\" + $CName + ".txt")
Dim ologfile
$ologfile = fso.OpenTextFile($Logfile, 8, True)
$ologfile.writeline ($DName + "\" + $UName)
$ologfile.close
End If
End If

Sleep 7

Exit

Top
#120858 - 2004-06-08 07:44 PM Re: VBSCRIPT converted to KIXTART (Set Statement)
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
DOH!
Never mind... my blind... no vars in strings.


Edited by Les (2004-06-08 07:46 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
#120859 - 2004-06-08 07:45 PM Re: VBSCRIPT converted to KIXTART (Set Statement)
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
There is no THEN in KiX either... lose it.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#120860 - 2004-06-08 07:54 PM Re: VBSCRIPT converted to KIXTART (Set Statement)
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
And Instr() only takes 2 parameters,

InStr($TextLine,$SearchString)
_________________________
Eric

Top
#120861 - 2004-06-08 08:09 PM Re: VBSCRIPT converted to KIXTART (Set Statement)
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
And you're missing a '$' on

Code:
 Status = "AlreadyLogged" 



And in Kix, it's "EndIf" not "End If"
_________________________
Eric

Top
#120862 - 2004-06-08 08:15 PM Re: VBSCRIPT converted to KIXTART (Set Statement)
ktodi Offline
Getting the hang of it

Registered: 2002-03-29
Posts: 60
Still no go. I receive no errors and the script does not pause for 7 seconds so I know it is not completeing. I have fixed the "instr" command and taken the "Then" statements out. Any other ideas?

$w2kwxp = @PRODUCTTYPE = "Windows 2000 Professional" OR @PRODUCTTYPE = "Windows XP Professional"

If $w2kwxp
Dim $WSHNetwork, $fso
$WSHNetwork = CreateObject("WScript.Network")
$fso = CreateObject("Scripting.FileSystemObject")

Dim $LogEntry
$UName = @USERID
$DName = @LDOMAIN
$CName = @WKSTA

Dim $Status
$Status = "NotLogged"
If $fso.FileExists("\\nserv\wkslogs$\" + $CName + ".txt")
Dim $SearchString
$SearchString = ($DName + "\" + $UName)
Dim $ParseFile, $TextStream, $TextLine
$ParseFile = $fso.GetFile("\\nserv\wkslogs$\" + $CName + ".txt")
$TextStream = $ParseFile.OpenAsTextStream
While Not $TextStream.AtEndOfStream
$TextLine = $TextStream.ReadLine
If InStr($TextLine,$SearchString) <> 0
Status = "AlreadyLogged"
End If
Loop
$TextStream.Close
End If



If $Status = "NotLogged"
Dim $Logfile
$Logfile = ("\\nserv\wkslogs$\" + $CName + ".txt")
Dim ologfile
$ologfile = fso.OpenTextFile($Logfile, 8, True)
$ologfile.writeline ($DName + "\" + $UName)
$ologfile.close
End If
End If

Sleep 7

Exit

Top
#120863 - 2004-06-08 08:44 PM Re: VBSCRIPT converted to KIXTART (Set Statement)
ktodi Offline
Getting the hang of it

Registered: 2002-03-29
Posts: 60
Thanks you guys once again made my life easy, everything works now below is the working script.

$w2kwxp = @PRODUCTTYPE = "Windows 2000 Professional" OR @PRODUCTTYPE = "Windows XP Professional"

If $w2kwxp
Dim $WSHNetwork, $fso
$WSHNetwork = CreateObject("WScript.Network")
$fso = CreateObject("Scripting.FileSystemObject")

Dim $LogEntry
$UName = @USERID
$DName = @LDOMAIN
$CName = @WKSTA

Dim $Status
$Status = "NotLogged"
If $fso.FileExists("\\nserv\wkslogs$\" + $CName + ".txt")
Dim $SearchString
$SearchString = ($DName + "\" + $UName)
Dim $ParseFile, $TextStream, $TextLine
$ParseFile = $fso.GetFile("\\nserv\wkslogs$\" + $CName + ".txt")
$TextStream = $ParseFile.OpenAsTextStream
While Not $TextStream.AtEndOfStream
$TextLine = $TextStream.ReadLine
If InStr($TextLine,$SearchString) <> 0
$Status = "AlreadyLogged"
EndIf
Loop
$TextStream.Close
EndIf



If $Status = "NotLogged"
Dim $Logfile
$Logfile = ("\\nserv\wkslogs$\" + $CName + ".txt")
Dim $ologfile
$ologfile = $fso.OpenTextFile($Logfile, 8, True)
$ologfile.writeline ($DName + "\" + $UName)
$ologfile.close
EndIf
EndIf

Sleep 7

Exit

Top
#120864 - 2004-06-08 10:56 PM Re: VBSCRIPT converted to KIXTART (Set Statement)
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4572
Loc: USA
Quote:


$w2kwxp = @PRODUCTTYPE = "Windows 2000 Professional" OR @PRODUCTTYPE = "Windows XP Professional"






I'm confused with this line of code. When I tested it, it returns 1, but for the life of me I have no idea why? Someone please tell me this is not acceptable syntax because otherwise I have no idea what I'm doing.

Shouldn't KiXtart give an error on this?
_________________________
(... better days ahead)

Top
#120865 - 2004-06-09 12:04 AM Re: VBSCRIPT converted to KIXTART (Set Statement)
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
lets parse it.

Code:

$w2kwxp = @PRODUCTTYPE = "Windows 2000 Professional" OR @PRODUCTTYPE = "Windows XP Professional"


comes to:
Code:

$w2kwxp = (@PRODUCTTYPE = "Windows 2000 Professional") OR (@PRODUCTTYPE = "Windows XP Professional")



and becomes any of these:
Code:

$w2kwxp = (1 OR 0)
$w2kwxp = (0 OR 1)
$w2kwxp = (0 OR 0)



so, afaik, it's "correct" syntax
_________________________
!

download KiXnet

Top
#120866 - 2004-06-09 03:52 AM Re: VBSCRIPT converted to KIXTART (Set Statement)
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4572
Loc: USA
ANDing and ORing... has never been my strong suit. When I first saw that line, with multiple equals and no IFs, it just seemed like it had to be wrong. Until now, I can't think of any example that I've seen on this board that follows that syntax. Now that you've broke it down it make more sense. Thanks.
_________________________
(... better days ahead)

Top
#120867 - 2004-06-09 03:56 AM Re: VBSCRIPT converted to KIXTART (Set Statement)
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
It works, I think, because KiXtart is very forgiving. I don't think you'll see it in anyone's "best practice" book anytime soon.
Top
#120868 - 2004-06-09 08:30 AM Re: VBSCRIPT converted to KIXTART (Set Statement)
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
it might work (speak not break the script) but It's quite pointless as it results in any case true ...

try to run this on a 9x/NT box
_________________________



Top
#120869 - 2004-06-09 10:15 AM Re: VBSCRIPT converted to KIXTART (Set Statement)
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
It works because it is perfectly correct syntax. There is nothing wrong with it at all.

You will see this syntax used frequently, and it is actually good programming style.

Quote:

but It's quite pointless as it results in any case true



No, for a Win9x or NT box the expression will of course evaluate to "0", which is what it required.

As a personal preference I'd use parentheses to highlight the sub-expressions and ensure correct parsing. I might also use the bitwise "|" but in fact the logical "OR" is more correct in this case:
Code:
$w2kwxp = (@PRODUCTTYPE = "Windows 2000 Professional") | (@PRODUCTTYPE = "Windows XP Professional")



Other languages like 'C' have seperate assignment ('x=0') and equivalent ('if(x==0)') operators because it is not always possible to determine from context whether the expression is assignment or syntax.

This is a good example of how it can be ambiguous, but fortunately the KiXtart parser makes the right choice.

Top
#120870 - 2004-06-09 10:24 AM Re: VBSCRIPT converted to KIXTART (Set Statement)
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
I stand corrected
_________________________



Top
Page 1 of 2 12>


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.081 seconds in which 0.034 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