what are the codes returned for FIleDiaglog

wheretheidivides

Active Member
Licensed User
Longtime User
I was wondering what the list of codes returned for FileDialog. Can't seem to find them anywhere. Also, what line of code do you use to apply that info? thanks.
 
Last edited:

MLDev

Active Member
Licensed User
Longtime User
If the positive button is clicked it returns -1, Negative returns -2, and Cancel returns -3. This will open the file if the Open button is clicked.

B4X:
ret = fd.Show("Please Select File", "Open", "Cancel", "", Null)
   
If ret = -1 Then
   myFile = File.ReadString(fd.FilePath, fd.ChosenName)
End If
 
Upvote 0

wheretheidivides

Active Member
Licensed User
Longtime User

===========================
thanks, but -1 and -2 differ how?
-1 open clicked
-2 open not clicked??????
-3 clicked cancel

if you click cancel then you wouldn't have clicked -2, right? and if someone types in wrong filename, how would you know
 
Upvote 0

derez

Expert
Licensed User
Longtime User
The -1 refers to the first "..." , the -2 refers to the third and the -3 refers to the middle, whatever the string inside is.
 
Upvote 0

wheretheidivides

Active Member
Licensed User
Longtime User
OK, I see. it's -1, -3 and then -2. It's out of order.

Now 1 more question. I got the following code below to work now. However, using the filedialog, if the user types in the wrong filename in the text box, it gives an error occurred error. If the user then presses no, the program ends. Obviously this is not what I want,

1)How do I check to see if the input into the text box on the filedialog is a valid file?
2) is there a way just to get rid of that box to input text on the filedialog? I don't see a need for it. I'd rather have someone click on a file that is there.


B4X:
Sub Button5098_Click
'------------------------------------------------
'cant use filedailog directly so must dim fd and use fd
   Dim fd As FileDialog 
   ExpPicFilename = "..."
 
'---------------------------------------------------
'set file dialog input
    fd.FastScroll = True
    fd.FilePath = File.Combine(File.DirRootExternal, "/Saved/PDTK/Pics/")
    fd.FileFilter = ".jpg"
 
 '------------------------------------------
 'bring up file dialog
    Dim ret As Int
   
   ret = fd.Show("Select picture to associate to.", "Associate", "Cancel", "", Null) 
   ExpPicFilename = fd.ChosenName  'will return the file name you select

'-----------------------------------------------------------
'do something after user selects on file dialog menu
   Select ret
      Case -1
         If ExpPicFilename = "" Then
            'Associate selected and no file name
            ToastMessageShow("Nothing Selected.","")
         Else
            'Associate selected with no file name
            ToastMessageShow("New picture associated.","")
            ImageView5099.Bitmap = LoadBitmap(File.DirRootExternal, "/Saved/PDTK/Pics/" & ExpPicFilename)
            Label5070a.Text = File.Combine(File.DirRootExternal, "/Saved/PDTK/Pics/")
            Label5070b.Text = ExpPicFilename
         End If
         
      Case -3
         ToastMessageShow("Cancel.  Nothing Selected.","")
         
      Case Else
         ToastMessageShow("Nothing Selected.","")
         
   End Select

'----------------------------------------
End Sub
 
Upvote 0

wheretheidivides

Active Member
Licensed User
Longtime User
Here's my solution and it seems to work. Thanks everyone for your responses to my messages. 2 months ago I barely got by, but now I'm feeling 100 times better. I even managed to databases with margets DB and am just amazed at what I have learned (although I am having pointer issues).

thanks.

B4X:
Sub Button5098_Click
'------------------------------------------------
'cant use filedailog directly so must dim fd and use fd
   Dim fd As FileDialog 
   ExpPicFilename = "..."
 
'---------------------------------------------------
'set file dialog input
    fd.FastScroll = True
    fd.FilePath = File.Combine(File.DirRootExternal, "/Saved/PDTK/Pics/")
    fd.FileFilter = ".jpg"
 
 '------------------------------------------
 'bring up file dialog
    Dim ret As Int
   
   ret = fd.Show("Select picture to associate to.", "Associate", "Cancel", "", Null) 
   ExpPicFilename = fd.ChosenName  'will return the file name you select

'-----------------------------------------------------------
'do something after user selects on file dialog menu
   If ret = -1 Then
      If File.Exists(File.DirRootExternal, "/Saved/PDTK/Pics/" & ExpPicFilename) = False OR fd.ChosenName = "" Then Then
         Msgbox("File does not exist.","")
      Else
         'Associate selected with no file name
         Msgbox("New picture associated.","")
         ImageView5099.Bitmap = LoadBitmap(File.DirRootExternal, "/Saved/PDTK/Pics/" & ExpPicFilename)
         Label5070a.Text = File.Combine(File.DirRootExternal, "/Saved/PDTK/Pics/")
         Label5070b.Text = ExpPicFilename
      End If
   End If
'-------------------------------------------------
   If ret = -3 Then
      Msgbox("Nothing Selected.","")   
   End If

'----------------------------------------
End Sub
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…