Fugazi
(Starting to like KiXtart)
2004-12-13 11:19 PM
Problem Emunerating directory

I am trying to do a simple enum of a directory and I am only returning a "." as the results. Can someone see what I am doing wrong.
Code:
  $username=Dir  ($nodepath)

While $username <> "" AND @ERROR = 0
?$username
If NOT InStr ($username,".")
decrypt()
Select
Case $cboUserSort.Text = "Name"
$fullname=ReadProfileString ($nodepath+$username,"Primary","Fullname")
If InStr($fullname,$txtFind.text)
$item=$listUsers.items.add
$Item.SubItems(0).Text = ($transuserid)
$Item.SubItems(1).Text = ($fullname)
Case $cboUserSort.Text = "User ID#"
If InStr($transuserid,$txtFind.text)
?"Find User ID ="$Find
$item=$listUsers.items.add
$Item.SubItems(0).Text = ($transuserid)
$Item.SubItems(1).Text = ReadProfileString ($nodepath+$username,"Primary","Fullname")
EndSelect
EndIf
$username = Dir("")
Loop




The Decrypt () function will translate a numeric file name to a valid Network ID ($transuserid).


LonkeroAdministrator
(KiX Master Guru)
2004-12-13 11:59 PM
Re: Problem Emunerating directory

I would try changing:
$username = Dir("")

to:
$username = Dir()


Fugazi
(Starting to like KiXtart)
2004-12-14 03:29 PM
Re: Problem Emunerating directory

Found the problem out forgot the endif for the instr statements.

Les
(KiX Master)
2004-12-14 03:49 PM
Re: Problem Emunerating directory

Be careful when looping on not @error as it can sneak up on you.
Code:
$var = 0
While $var < 10 and not @Error
'var = '+ $var ?
$var = $var + 1
If $var = 5
$rc=MessageBox("snookered","Test")
EndIf
Loop



You may start out OK but then later embelish the code somewhere inside the loop that could throw @Error. BTDTGTTS


Sealeopard
(KiX Master)
2004-12-15 05:09 AM
Re: Problem Emunerating directory

Why reinvent the wheel if there are already a couple of DIR...() UDFs posted in the UDF Forum?

MCA
(KiX Supporter)
2004-12-15 01:06 PM
Re: Problem Emunerating directory

Dear,

We run our program kixstrip which you can find on our site and
which shows indeed you are missing two ENDIF statements:
The result of our call: kistrip input.kix output.kix /block_check /show_errors
shows
Code:

$username=Dir ($nodepath)
WHILE $username <> "" AND @error = 0
?$username
IF NOT InStr ($username,".")
decrypt()
SELECT
CASE
$cbousersort.text = "Name"
$fullname=ReadProfileString ($nodepath+$username,"Primary","Fullname")
IF InStr($fullname,$txtfind.text)
$item=$listusers.items.add
$item.subitems(0).text = ($transuserid)
$item.subitems(1).text = ($fullname)
CASE
$cbousersort.text = "User ID#"
IF InStr($transuserid,$txtfind.text)
?"Find User ID ="$Find
$item=$listusers.items.add
$item.subitems(0).text = ($transuserid)
$item.subitems(1).text = ReadProfileString ($nodepath+$username,"Primary","Fullname")
ENDSELECT
ENDIF
$username = Dir("")
LOOP


;($begin)
;
; kixstrip 4.03e - kixtart 4.22
;
; wed 15-dec-2004 12:58:15
;
;Informative KIXSTRIP: input=23 output=23 skip=0
;
;Warning KIXSTRIP: 2 errors in block structure(s). missing statement(s).
; - do:until [0:0]
; - for|each:in|to:step|next [0|0:0|0:0|0]
; - function:endfunction [0:0]
; -ERROR- - if:else:endif [3:0:1]
; - select:case:endselect [1:2:1]
; - while:loop [1:1]
;Warning KIXSTRIP: some lines contains errors or possible errors.
;Informative KIXSTRIP: 5 block_structures found.
;Informative KIXSTRIP: no UDF's found.
;Informative KIXSTRIP: no labels found.
;Summary KIXSTRIP: BREAK CALL DEBUG DISPLAY ENDFUNCTION EXECUTE EXIT FUNCTION GET GETS GOSUB GOTO OLExxx PLAY QUIT RETURN RUN SHELL SLEEP THEN USE
;
;($end)
;($begin)
;
;
;($end)


greetings.



Kdyer
(KiX Supporter)
2004-12-15 02:46 PM
Re: Problem Emunerating directory

MCA is correct to a point..

You are missing more than just a couple of ENDIFs

You can clean up your code to be -
Code:

WHILE $username <> "" AND @error = 0
?$username
IF NOT InStr ($username,".")
decrypt()
;SELECT ;<< IS THIS NEEDED?
;CASE ;<< IS THIS NEEDED?
$cbousersort.text = "Name"
$fullname=ReadProfileString ($nodepath+$username,"Primary","Fullname")
IF InStr($fullname,$txtfind.text)
$item=$listusers.items.add
$item.subitems(0).text = ($transuserid)
$item.subitems(1).text = ($fullname)
ELSE ;<< MISSING ELSE?
$cbousersort.text = "User ID#"
IF InStr($transuserid,$txtfind.text)
?"Find User ID ="$Find
$item=$listusers.items.add
$item.subitems(0).text = ($transuserid)
$item.subitems(1).text = ReadProfileString ($nodepath+$username,"Primary","Fullname")
ENDSELECT
ENDIF
$username = Dir("")
;ENDSELECT ;<< IS THIS NEEDED?
ENDIF ; MISSING ENDIF
LOOP



Thanks,

Kent


Les
(KiX Master)
2004-12-15 03:02 PM
Re: Problem Emunerating directory

You are still looping on not @error. I would go with a more modularized method rather than in-line. Read in the works into an array with a UDF first and then iterate through the array.

maciep
(Korg Regular)
2004-12-15 03:39 PM
Re: Problem Emunerating directory

Kent, it looks like you have an ENDSELECT where you'd want an ENDIF. And i think you should also move that username=Dir() down a level, because it'll just keep looping if username = '.'

Les, what's the problem with looping on @error if the last statement, the Dir() assignment, sets @error? I've never had a problem with it in that situation.


Les
(KiX Master)
2004-12-15 04:07 PM
Re: Problem Emunerating directory

Guess maybe you didn't read my post and run my example.
http://www.kixtart.org/ubbthreads/showthreaded.php?Cat=&Number=130405&page=&view=&sb=5&o=&vc=1

If after you read it and analyze it, you still have questions, post back.


maciep
(Korg Regular)
2004-12-15 04:15 PM
Re: Problem Emunerating directory

I did read it and i did test it. But still it has nothing to do with the Dir() function and its ability to set @error

Code:

$var = 0
$username = dir("c:\*.*")
While $var < 10 and not @Error
'var = '+ $var ?
$var = $var + 1
If $var = 5
MessageBox("snookered","Test")
EndIf
$userName = dir()
Loop
? @error



Fugazi
(Starting to like KiXtart)
2004-12-16 07:08 PM
Re: Problem Emunerating directory

The reason I left this as a Select Case is that I originally had the sort including location and computer name. The powers that be at that time did not see a use for it and I removed it. I did change it to an IF statement then reconsidered because I can almost gaurentee that they will have me put it back at the next meeting for this application (which is why I forgot to include the EndIf's).