Scope within controls

I'm creating a control panel to load data files and do not understand how the scope differs between built-in and user-defined functions. This is hard to describe but I'll do my best to be clear.

If the user presses button A ["Select file(s)"], the button action procedure calls Open and populates a Listbox with each of the file names returned. I don't have to reference S_fileName as an SVAR in this case. Everything works just fine.

If the user presses button B ["Search in directory..."], the action procedure launches another panel designed to search for files within directories, then calls PauseForUser to wait for the new panel to close. This new panel creates a global string S_fileName when it is closed, however, this global variable is not accessible to the original panel. Attempting to reference it as when using Open results in null string errors. Inserting an SVAR reference statement immediately after the PauseForUser statement results in a mismatched global variable reference type.

Does anyone understand why my references to S_fileName via button B do not work? And what should I change to get a proper reference?
OK, I found some answers in the Help files :)

DisplayHelpTopic "Accessing Variables Used by Igor Operations"

Igor Help wrote:

When you invoke them from a user-defined function, they create local variables.

So the S_fileName coming from Open isn't really a global variable. I'll need to find a different way to access the S_fileName produced from my file searching panel. Or change the variable name and go with the global route. I'll probably explore using pass-by-reference instead.
How about something like this ...

Function OpenPanelOne()

    string newfilename = ""

    NewPane/n=firstpanel/...
    ...
    if (V_flag)
       newfilename = OpenPanelTwo()
       if (strlen(newfilename)==0)
            return 0
       end
    end

    return 0

end

Function/S OpenPanelTwo()

   NewPanel/N=secondpanel/...
   ...
   Open/...

   PauseForUser
   ...

   KillWindow ...

   return S_filename

end


--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville