Page 2 of 3 <123>
Topic Options
#132369 - 2005-01-14 11:01 PM Re: Lexer for KiX
Les Offline
KiX Master
*****

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

Les, my dr. evil avatar is far from my actual appearance...



LOL... Mine doesn't do me justice either.

Anyway, I commend you on your bravery in taking on such a monumental task.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#132370 - 2005-01-14 11:19 PM Re: Lexer for KiX
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
lol!

Well, the actual convertor will most likely be a long work in progress. Currently it does a lot of the typical stuff like comments, variables, End If, etc. that make up the bulk of the tedious. I'm focused on getting something useful out vbs by emulating kix with those libraries.
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#132371 - 2005-01-14 11:37 PM Re: Lexer for KiX
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
Hey Jim, thought I would pass this along to you (as well as a few asprin ) :

Microsoft has a daily article on "Howto" in VBS, called Hey, Scripting Guy! and the archives may help you in your quest.

As a side note, a few weeks back, we were discussing how complicated just mapping a drive was in VBS compared to KIX, and I made an attempt to convert their code into a function. It's untested, but may get you going if you haven't done that conversion yet.

Good Luck!

Top
#132372 - 2005-01-14 11:58 PM Re: Lexer for KiX
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
Alpo, I try to keep up with the boards and did spot this article and I did incorporate it into the library already! Thanks for saving me time!

Quote:

Microsoft has a daily article on "Howto" in VBS, called Hey, Scripting Guy! and the archives may help you in your quest.



I'm also all over this. I sent this message to them on Thursday. Note you'll recognize a converted CError() udf.
Quote:

I'm probably not alone here by saying VBScript's error handling has me frustrated. Particularly, COM errors that vbscript doesn't seem to be able to interpret.

For instance, if I run this code snippet:

On Error Resume Next
Set objGroup = GetObject("WinNT://"& strComputer &"/"& strLocalDestinationGroup)
objGroup.Add "WinNT://"& strUserToAdd
wscript.echo err.number
wscript.echo err.description

and it fails because the user I'm trying to add already belongs to the target group, the err returned is:
-2147023518
and the descriiption is empty. Therein lies the problem.

HOWEVER, if I remove the On Error Resume Next, the compiler quits execution on the .Add method and correctly resolves the error to:

User is already a member of the target group.

So I'm using this function to convert the error to hex and back again into a standard System Error Code.

Function CError(lErr)
If lErr<0 Then lErr=HexToDec(Right(Hex(lErr),4)) End If
Err.Number = lErr
End function

Function HexToDec(strHex)
dim lngResult
dim intIndex
dim strDigit
dim intDigit
dim intValue

lngResult = 0
for intIndex = len(strHex) to 1 step -1
strDigit = mid(strHex, intIndex, 1)
intDigit = instr("0123456789ABCDEF", ucase(strDigit))-1
if intDigit >= 0 then
intValue = intDigit * (16 ^ (len(strHex)-intIndex))
lngResult = lngResult + intValue
else
lngResult = 0
intIndex = 0 ' stop the loop
end if
next

HexToDec = lngResult
End Function

Now, CError will properly convert -2147023518 to decimal 1378 which we can verify on this table: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/system_error_codes__1300-1699_.asp

The problem is this. If I try to err.raise= 1378, VBScript is clueless. Setting err.number = 1378 does help either.

How can I get VBScript to recognize and resolve these standard error codes to the proper description?

Any other error handling methodologies would be great help as well.



_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#132373 - 2005-01-19 04:29 AM Re: Lexer for KiX
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
Hey Jim... I worked over the Cerror function... tell me what you think.

Code:
  

on error resume next
strComputer="computer"
strLocalDestinationGroup="Administrators"
strUsertoAdd="Administrator"

Set objGroup = GetObject("WinNT://"& strComputer &"/"& strLocalDestinationGroup)
objGroup.Add "WinNT://"& strUserToAdd
cerror(err.number)
wscript.echo err.number
wscript.echo err.description

Function CError(lErr)
dim cerr,ws,temp,cerrorfile,ret,fs,file,output
If lErr<0 Then
cErr=HexToDec(Right(Hex(lErr),4))
Set ws=Wscript.createobject("Wscript.Shell")
temp=ws.expandenvironmentStrings("%temp%")
cerrorfile=temp & "\cerror.txt"
ret=ws.run ("%comspec% /c net helpmsg " & cerr & " >" & CerrorFile,0,"True")
set fs=wscript.createobject("Scripting.FilesystemObject")
Set File=fs.OpenTextFile(cerrorfile,1)
file.skipline
output=file.readline
file.close
err.raise cerr,,output
End If
End function

Function HexToDec(strHex)
dim lngResult
dim intIndex
dim strDigit
dim intDigit
dim intValue

lngResult = 0
for intIndex = len(strHex) to 1 step -1
strDigit = mid(strHex, intIndex, 1)
intDigit = instr("0123456789ABCDEF", ucase(strDigit))-1
if intDigit >= 0 then
intValue = intDigit * (16 ^ (len(strHex)-intIndex))
lngResult = lngResult + intValue
else
lngResult = 0
intIndex = 0 ' stop the loop
end if
next

HexToDec = lngResult
End Function




Top
#132374 - 2005-01-20 06:42 PM Re: Lexer for KiX
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
Hey, that's a pretty decent solution! Rather than write to a file, we could 'wshpipe' and parse. I'm thinking that a 'complete' error handling function is in order for vbscript. I'll tack this on the list.

GREAT WORK!
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#132375 - 2005-01-20 10:30 PM Re: Lexer for KiX
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
Great. While I was writing this, I was thinking, "It sure would be nice to have Pipe Function here."

Anyway, I am mildly interested in your project. Even though this is VBScript (blasphemy in these parts), please keep the board informed and maybe share some of your code.

Top
#132376 - 2005-01-20 11:30 PM Re: Lexer for KiX
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
I hope the project actually makes others (perhaps everyone in the world who uses vbscript) aware of the simplicity of Kix.

The code is available in the CVS from the project page. I commit at least twice per day. HOWEVER, webcvs seems to update only once every 24 (or so) hours. Best bet is to get yourself Tortoise CVS and set it up. For the naysayers, I'm behind a firewall and proxy and managed to get it working, but this is much more simple without the extra hurdles. When I get a complete set of code, I'll make it availalbe on the download page. (No sense in writing code that works right the first time, right?) =)

If anyone does a checkout, there's project file for PSPad called "VBScript Code Catalog.ppr".

I'll keep the board up to date best I can.

Oh, and if anyone's bored, I've been avoiding rewriting DelTree()...
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#132377 - 2005-01-21 05:11 AM Re: Lexer for KiX
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
I have no idea what you are talking about.

I'm not familiar CVS... care to elaborate?

Top
#132378 - 2005-01-21 06:13 AM Re: Lexer for KiX
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
Ahh... Concurrent Versions System . Here's more than you want to know about CVS at sourceforge. On the short, it enables several users to write code on their local systems simultaneously and maintains every version of every file ever checked in. For instance, both of us check out a bunch of the same files, update them and create new ones. When we've made significant progress or were done working for the time being, we check in our files. If the other developers have already checked in, a diff program will display the differences and allow us to overwrite, merge, discard, etc.. You may have heard of Merant's PVCS or Microsoft's Visual Source Safe. Both commercial products provide similar features. CVS is opensource and generally included with every version of Unix or Linux that I can think of.

Sourceforge offers CVS services for its hosted projects. Both developers and non-developers can get all of the source code for every project available on sourceforge through CVS. Developers compile or in my case collect all of their source into a binary distributable (zip,tar,exe) and then make that available for download which is known as a release. Don't let me dumb it down though. Volumes have been written and published on it.

Sourceforge allows anyone to view the cvs for each project through the web without installing a client. The problem here is that these pages are not dynamic and seem to be updated on and inconsistent basis. Additionally, the client allows you to download the whole ball of wax whereas the web is one at a time.


Edited by jtokach (2005-01-21 06:20 AM)
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#132379 - 2005-01-21 06:36 AM Re: Lexer for KiX
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
Thanks for the explaination... I've heard of Source Safe, but not CVS. Anyway the web link you provided gave me enough to nose around. Looks like you've done quite a bit, but have a good ways to go.
Top
#132380 - 2005-01-21 06:42 AM Re: Lexer for KiX
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
About 20 functions, 3 commands and all macros less 3 to go. The .xls two levels up from the root tracks my progress.
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#132381 - 2005-01-21 07:48 AM Re: Lexer for KiX
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
Okay... I'm trying to pull myself away from this... hopefully this will be the last...

I hacked on Chris's WSHPipe and it functions pretty close to his original. You may have to revist exit codes in it, but for now, it works.

Code:
 

on error resume next

strComputer="computer"
strLocalDestinationGroup="Administrators"
strUsertoAdd="Administrator"

Set objGroup = GetObject("WinNT://"& strComputer &"/"& strLocalDestinationGroup)
objGroup.Add "WinNT://"& strUserToAdd
cerror(err.number)
wscript.echo err.number
wscript.echo err.description

function display
Msgbox Err.number & ":" & Err.Description
Err.clear
end function

Function CError(lErr)
dim cerr,output,line,errdesc
If lErr<0 Then
cErr=HexToDec(Right(Hex(lErr),4))
output=wshpipe("net helpmsg " & cerr)
for each line in output
if line<>"" then
errdesc=errdesc & " " & line
end if
next
errdesc=ltrim(errdesc)
Err.raise cerr,,errdesc
End If
End function

Function WshPipe(ShellCMD)
Dim oExec, Output, ExitCode
Set oExec = CreateObject("WScript.Shell").Exec(ShellCMD)
If Not VarType(oExec)=9 then
WshPipe="WScript.Shell Exec Unsupported"
Err.Raise 10
Exit Function
End If
Output = oExec.StdOut.ReadAll & oExec.StdErr.ReadAll
WshPipe=Split(Join(Split(Output,CHR(13)),""),CHR(10))
End Function

Function HexToDec(strHex)
dim lngResult
dim intIndex
dim strDigit
dim intDigit
dim intValue

lngResult = 0
for intIndex = len(strHex) to 1 step -1
strDigit = mid(strHex, intIndex, 1)
intDigit = instr("0123456789ABCDEF", ucase(strDigit))-1
if intDigit >= 0 then
intValue = intDigit * (16 ^ (len(strHex)-intIndex))
lngResult = lngResult + intValue
else
lngResult = 0
intIndex = 0 ' stop the loop
end if
next

HexToDec = lngResult
End Function





Top
#132382 - 2005-01-21 09:35 AM Re: Lexer for KiX
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hmm...
http://vbscript.sourceforge.net/

project activity: 0%
number of CVS submissions: 0

when you gonna insert something there?
_________________________
!

download KiXnet

Top
#132383 - 2005-01-21 02:27 PM Re: Lexer for KiX
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
I guess Jim will have to tell you why nothing is on the project home page, but he does have files here:
http://cvs.sourceforge.net/viewcvs.py/vbscript/#dirlist

Top
#132384 - 2005-01-21 03:14 PM Re: Lexer for KiX
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
alrighty!
didn't find my way there.
_________________________
!

download KiXnet

Top
#132385 - 2005-01-22 02:34 AM Re: Lexer for KiX
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
Yeah, this is a known bug with SF. Click the little bug icon next to numbers for a description. They are no longer updating these numbers until it's resolved.
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#132386 - 2005-01-22 02:37 AM Re: Lexer for KiX
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
Quote:

I guess Jim will have to tell you why nothing is on the project home page, but he does have files here:
http://cvs.sourceforge.net/viewcvs.py/vbscript/#dirlist




Yeah, I don't time for a real home page. It points to the project page and forums for now.

In CVS, you'll find the VBS code under V1\Library\Vbscript\KIX422

Also, the zero commits and adds isn't working either.
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
#132387 - 2005-01-22 03:08 AM Re: Lexer for KiX
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
While messing with these VBScripts and modifying functions, I was unable to find a method for an optional argument in the function, like we do in kix... function($x, optional $y).

Does anyone know if this is even possible in VBS?


Edited by Al_Po (2005-01-22 05:06 AM)

Top
#132388 - 2005-01-22 04:13 AM Re: Lexer for KiX
jtokach Offline
Seasoned Scripter
*****

Registered: 2001-11-15
Posts: 513
Loc: PA, USA
Nope. There are a few workarounds. I've chosen this method in my conversions:

Code:
ret = myfunction(string1, null, string2)
function myfunction(arg1,optarg1,optarg2)
If IsNull(optarg1) Then
'do nothing with it
Else
'do something with it
End If

If IsNull(optarg2) Then
'do nothing with it
Else
'do something with it
End If
End function



You'll also want to review the Include2() function as vbs has no method to import externals like kix's call. I think it's in v1\library\vbscript\general
_________________________
-Jim

...the sort of general malaise that only the genius possess and the insane lament.

Top
Page 2 of 3 <123>


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

Who's Online
1 registered (Allen) and 1198 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.039 seconds in which 0.014 seconds were spent on a total of 13 queries. Zlib compression enabled.

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