Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function Return Value - BrowseForFolder
#1
Hi,
I am trying to have a certain action happen if the user chooses cancel instead of ok.

It says in the code below that it return 0 on cancel but I don't know how to receive that value

The suggested syntax doesn't seem to have any return value for OK or Cancel..only for s
Code:
Copy      Help
str s
if(BrowseForFolder(s "$windows$")) out s

I totally know this is very basic but can you explain to me the logic behind using the statement the way you have it above
Code:
Copy      Help
if(BrowseForFolder(s "$windows$")) out s
rather than just as
Code:
Copy      Help
BrowseForFolder(s "$windows$")

I have pasted the full function text below...

Thanks,
Stuart

Code:
Copy      Help
;/
function# str&s [$initdir] [flags] [$text] ;;flags: 1 include files, 2 include non-file objects (Control Panel, etc), 4 new style

;Displays "Browse For Folder" dialog and stores full path of selected folder into s.
;Returns 1 on OK, 0 on Cancel.


;flags may also include one or more of BIF_x flags (see function code), lshifted by 8 bits. For example, to browse for computer, use 2|(0x1000<<8). For more info, search for SHBrowseForFolder in the MSDN Library.

;EXAMPLE
;str s
;if(BrowseForFolder(s "$windows$")) out s



def BIF_RETURNONLYFSDIRS 0x0001
;def BIF_DONTGOBELOWDOMAIN 0x0002
;def BIF_STATUSTEXT 0x0004
;def BIF_RETURNFSANCESTORS 0x0008

def BIF_EDITBOX 0x0010
;def BIF_VALIDATE 0x0020
def BIF_NEWDIALOGSTYLE 0x0040
def BIF_USENEWUI (BIF_NEWDIALOGSTYLE | BIF_EDITBOX)
;def BIF_BROWSEINCLUDEURLS 0x0080
;def BIF_UAHINT 0x0100
;def BIF_NONEWFOLDERBUTTON 0x0200
;def BIF_NOTRANSLATETARGETS 0x0400
;def BIF_BROWSEFORCOMPUTER 0x1000
;def BIF_BROWSEFORPRINTER 0x2000

def BIF_BROWSEINCLUDEFILES 0x4000
;def BIF_SHAREABLE 0x8000

BROWSEINFO b
b.hwndOwner=win()
if(flags&1) b.ulFlags|BIF_BROWSEINCLUDEFILES
if(flags&2=0) b.ulFlags|BIF_RETURNONLYFSDIRS
if(flags&4) b.ulFlags|BIF_USENEWUI
b.ulFlags|flags>>8
b.lpszTitle=text
if(flags&4)
,STRINT p.i=flags; p.s.searchpath(initdir)
,b.lpfn=&BFF_Callback; b.lParam=&p
else if(len(initdir)) b.pidlRoot=PidlFromStr(initdir)

ITEMIDLIST* pidl=SHBrowseForFolder(&b)

if(pidl) PidlToStr(pidl &s flags&2=0); CoTaskMemFree pidl; else s.all
if(b.pidlRoot) CoTaskMemFree b.pidlRoot
ret s.len
[/code]
#2
if(something)

is the same as

if(something not = 0)

In this case, the return value of the function is that "something".

----

Code:
Copy      Help
str s
if(BrowseForFolder(s "$windows$"))
,out "OK"
else
,out "Cancel"

;or
if(BrowseForFolder(s "$windows$")!=0)
,out "OK"
else
,out "Cancel"

;or
if(!BrowseForFolder(s "$windows$"))
,out "Cancel"
else
,out "OK"

;or
if(BrowseForFolder(s "$windows$")=0)
,out "Cancel"
else
,out "OK"

;or
int ok=BrowseForFolder(s "$windows$")!=0
if(ok)
,out "OK"
else
,out "Cancel"

;or
ok=BrowseForFolder(s "$windows$")!=0
if(ok!=0)
,out "OK"
else
,out "Cancel"

----

Small error in documentation. Must be " Returns a nonzero value on OK, 0 on Cancel."[/code]
#3
Thanks!!!!!


Forum Jump:


Users browsing this thread: 1 Guest(s)