Page 1 of 1 1
Topic Options
#148521 - 2005-09-27 05:24 AM Hiding Return Values
Skorpion Offline
Fresh Scripter

Registered: 2005-09-27
Posts: 11
Hey all,

I've got a logon script and in there I've got a UDF to map drives.
The only problem is that with the Use command it returns 1's everytime it maps a drive...

This is the statement:
Code:
Use $Drive "\\" + $Server + "\" + $Share



I've also tried adding a $ = in front of the statement but I then get an "Error in expression".

Has anyone got any ideas how I would get around this? I can post the UDF if required.

Top
#148522 - 2005-09-27 05:39 AM Re: Hiding Return Values
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4459
Loc: USA
the use command doesn't return a 1 or 0...I'd bet its the UDF doing it... put your $= in front of the UDF.
Top
#148523 - 2005-09-27 05:43 AM Re: Hiding Return Values
Skorpion Offline
Fresh Scripter

Registered: 2005-09-27
Posts: 11
Seems like a good point but when I tried it I still get a whole lot of 1's in the output...
Top
#148524 - 2005-09-27 05:46 AM Re: Hiding Return Values
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4459
Loc: USA
Functions (and most UDFs) return error codes... so in order to silence them you will need to send that output to a variable... Check out the FAQ Section... there is a whole topic dedicated to the subject.
Top
#148525 - 2005-09-27 06:09 AM Re: Hiding Return Values
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4459
Loc: USA
Is the UDF one from this forum or from somewhere else? You can post it if you like...

and just for any clarification...

$=functionname($var) or $nul=functionname($var)
will supress the output (the 0s or 1s) and put the output into a variable called $ or $nul... or for that matter whatever you want to call it.

The reason you get an error when you put $= in front of the use is because use is a command, not a function. If you checkout the manual, you will see that the commands, and functions are separated into different sections.


Edited by Allen (2005-09-27 06:11 AM)

Top
#148526 - 2005-09-27 06:10 AM Re: Hiding Return Values
Skorpion Offline
Fresh Scripter

Registered: 2005-09-27
Posts: 11
Tried that but nothing - So now I've got $RV = MapDrive() but I still get 1's...

I've tried it in debug mode and it definately appears to be when using the "Use" command that it's outputting the 1's if that helps

Top
#148527 - 2005-09-27 06:20 AM Re: Hiding Return Values
Skorpion Offline
Fresh Scripter

Registered: 2005-09-27
Posts: 11
Here's the UDF - I created it today (I know, not the tidiest - still got to clean it up a bit)

Code:
Function MapDrive($Drive, $Share, Optional $Server)
If $Drive NOT "" AND $Share NOT ""
Use $Drive /DELETE
If $Server NOT ""
Use $Drive "\\" + $Server + "\" + $Share
Else
; Used for \\server\share (i.e. the users home folder from AD)
Use $Drive $Share
EndIf

If @ERROR = 0 OR @ERROR = 1202
Color w/n
? $Drive + " drive - " + $Share + " on " + $FileServer + " - Attached"
Else
Color r+/n
? "Cannot connect to " + $Drive + "!! " + @SERROR
EndIf
EndIf

Color w/n
EndFunction


Top
#148528 - 2005-09-27 06:48 AM Re: Hiding Return Values
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4459
Loc: USA
I would like to first suggest that there are at least 2 different Mapdrive UDFs in the UDF Forum... you might check those out, as there is no real need to reinvent the wheel.

But the problems and the 1's you are seeing are actually in your if statements:

Replace this:
Code:
 If $Drive NOT "" AND $Share NOT ""


with this:
Code:
if $drive and $share 



But if you really want to use the "Not"s, try this...

Code:
If not $Drive="" AND not $Share=""




As a side note, I had to laugh... I wonder if you come from a batch coding background... I was accused of liking "Not" when I first start posting here, and it was because all I had ever used was bat files.


Edited by Allen (2005-09-27 06:56 AM)

Top
#148529 - 2005-09-27 06:57 AM Re: Hiding Return Values
Skorpion Offline
Fresh Scripter

Registered: 2005-09-27
Posts: 11
No I'm actually a PHP Developer :-)

I prefer NOT to <> as it's clearer for non-programmers (or non-scripters) to understand what it's doing...

You're a legend :-) Worked perfectly... love KiX but don't like it's conditional statements, like if() {} ! etc syntax (but then again I would, programmed in PHP, Java and C)

Top
#148530 - 2005-09-27 06:58 AM Re: Hiding Return Values
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4459
Loc: USA
Actually, $drive and $share are both required parameters of your udf... so really the first "if" is redundant... because kixtart will error out if you do not supply the proper parameters...
Top
#148531 - 2005-09-27 11:24 AM Re: Hiding Return Values
Skorpion Offline
Fresh Scripter

Registered: 2005-09-27
Posts: 11
But what if you supply an argument that exists but has no value? then the "if" statement is not redundant... but I may be wrong, i'm not 100% up to how KiX would handle this situation.
Top
#148532 - 2005-09-27 02:31 PM Re: Hiding Return Values
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4945
Loc: Leatherhead, Surrey, UK
Quote:

I prefer NOT to <> as it's clearer for non-programmers (or non-scripters) to understand what it's doing...




Careful, "NOT" and "<>" do completely different things. Don't fall into the trap of thinking that they are interchangeable. You can often use them to get the same result, much as you can use a hammer to drive a screw.

Be very careful when using things like NOT, also when using the item value for boolean truths. All variables in KiXtart are variants, and KiXtart will convert between sub-types silently when it has to.

This can mean that your numeric values can be easily cast to string variants. This catches people out because a string with a value of "0" is actually TRUE, whereas a number with a value of 0 is FALSE. However a zero length string is FALSE.

The most common example of confusion is when reading registry values, which are always returned as strings regardless of registry type.

For example:
Code:
"0 is " IIf(0,"TRUE","FALSE") ?
"1 is " IIf(1,"TRUE","FALSE") ?
"'0' is " IIf('0',"TRUE","FALSE") ?
"'1' is " IIf('1',"TRUE","FALSE") ?
"'' is " IIf('',"TRUE","FALSE") ?



Gives:
Quote:

0 is FALSE
1 is TRUE
'0' is TRUE
'1' is TRUE
'' is FALSE



Top
#148533 - 2005-10-01 04:14 PM Re: Hiding Return Values
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11162
Loc: Boston, MA, USA
And read the FAQ Forum with regards to suppressing 0 and 1 outputs.
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


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

Who's Online
0 registered and 59 anonymous users online.
Newest Members
diefnet, Arogya, gkustra, emnipetro, Hirze
17644 Registered Users

Generated in 0.035 seconds in which 0.01 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