Page 1 of 1 1
Topic Options
#72714 - 2003-01-23 03:36 PM RE: fnRemapDrives()
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Jens said...
quote:
If there are multiple errors while running this UDF the returned error code will be incorrect as you are adding all error codes.

--------------------
Jens

This was the intended behavior. As the Do loop enumerates the persistent drive mappings and successfully changes all registry entries the final error code will be zero. If there is one (or more) errors writing to the registry (which is highly unlikely) the error code will be greater than 0 as stated in the documentation. A -1 error code indicates that no match was found.

[ 23. January 2003, 15:38: Message edited by: Chris S. ]

Top
#72715 - 2003-01-23 03:41 PM Re: RE: fnRemapDrives()
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
BTW, here is the link to fnRemapDrives()
Top
#72716 - 2003-01-23 03:47 PM Re: RE: fnRemapDrives()
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
However, my issue is that the stated error code will not relect the actual error(s) that occured.

[ 23. January 2003, 15:47: Message edited by: sealeopard ]
_________________________
There are two types of vessels, submarines and targets.

Top
#72717 - 2003-01-23 03:52 PM Re: RE: fnRemapDrives()
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Any error level other than 0 on WriteValue() indicates that the function failed.

What error level would you be looking for?

I'm open to suggestions. I know you are very knowledgeable in regards to best practices, so I'm receptive to your thoughts.

Top
#72718 - 2003-01-23 03:59 PM Re: RE: fnRemapDrives()
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
mmm...
think it's fine if it even returns error.
that is something many of the UDFs don't do.

and it's just a fragment of the UDFs that return proper/correct errors...

it could exit on the first error too, but what if that is the only error...
_________________________
!

download KiXnet

Top
#72719 - 2003-01-23 04:00 PM Re: RE: fnRemapDrives()
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
I'd rather do an
code:
$rc=WRITEVALUE(...)
if @ERROR
$err=@ERROR
endif

This way you will receive the correct error code for the last failed write. It does imply that previous write might have failed with the same error code. The advbantage is that e.g. an error code of 2 can be translated to the correct @SERROR message if you put an 'exit $err' at the end of your function.

I am modifying my UDfs to return proper errro codes by using the following syntax where applicable:
code:
function dummy($a)
;doding stuff
$dummy='return value'
exit @ERROR
endfunction

If possible I try to copy the KiXtart syntax by returning '0' for successful UDFs and the appropriate error code for failed UDFs. I can then evaluate @ERROR/@SERROR outside the UDF.
_________________________
There are two types of vessels, submarines and targets.

Top
#72720 - 2003-01-23 04:07 PM Re: RE: fnRemapDrives()
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
My dilema with this UDF was that the user could have any number of mapped drives with the target server's name in it. If I only use the last error code, i.e.

code:
$rc=WRITEVALUE(...)
if @ERROR
$err=@ERROR
endif

...then a failed write error code could potentially be overwritten by a successful one. The only option would be to exit the UDF on any WriteValue() error.

Top
#72721 - 2003-01-23 04:10 PM Re: RE: fnRemapDrives()
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
with that syntax actually there is no way of overwriting failure with success as that if takes care of it [Wink]
_________________________
!

download KiXnet

Top
#72722 - 2003-01-23 04:10 PM Re: RE: fnRemapDrives()
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
That's why I put the IF clause into it. An error code will only be set if the WRITEVALUE fails, a successful write will not change the last error code.
_________________________
There are two types of vessels, submarines and targets.

Top
#72723 - 2003-01-23 04:12 PM Re: RE: fnRemapDrives()
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Gotcha.

Is the -1 ok to indicate that no action was taken?

Top
#72724 - 2003-01-23 04:16 PM Re: RE: fnRemapDrives()
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Personally, I'd go for '0' if it was sccessful, independend of whether the drives were remapped or not. However, if you need to know whether there was a remap at all, then yes, '-1' would work.
_________________________
There are two types of vessels, submarines and targets.

Top
#72725 - 2003-01-23 04:44 PM Re: RE: fnRemapDrives()
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
but then you are not able to do:
if fnremapdrives()
"error occured"
endif

as "-1" will be catched as true too...
_________________________
!

download KiXnet

Top
#72726 - 2003-01-23 05:17 PM Re: RE: fnRemapDrives()
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
In that case you will have to differentiate more anyway, e.g.
code:
$rc=fnremapdrives()
select
case @ERROR
case $rc=0
case $rc=-1
case 1
endselect
;or (assuming that @ERROR=0 even if $rc=-1)
if @ERROR
else
endif

[/code]
_________________________
There are two types of vessels, submarines and targets.

Top
#72727 - 2003-01-23 05:19 PM Re: RE: fnRemapDrives()
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
actually there was no return code...

as it sets error but does not seem to return anything...
_________________________
!

download KiXnet

Top
#72728 - 2003-01-23 05:33 PM Re: RE: fnRemapDrives()
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
 -
Top
#72729 - 2003-01-23 06:22 PM Re: RE: fnRemapDrives()
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
LOL!
_________________________
!

download KiXnet

Top
#72730 - 2003-01-23 06:23 PM Re: RE: fnRemapDrives()
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Can I be the one with the whip? [Big Grin]
_________________________
There are two types of vessels, submarines and targets.

Top
#72731 - 2003-01-23 06:24 PM Re: RE: fnRemapDrives()
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
biting the ass?
_________________________
!

download KiXnet

Top
#72732 - 2003-01-23 06:27 PM Re: RE: fnRemapDrives()
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Sadistic, hippophilic necrophile

or, in plain English...

beating a dead horse. [Wink] [Big Grin]

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.08 seconds in which 0.033 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