Save file dialog

Post

Posted
Rating:
#1 (In Topic #1352)
Regular
theyikes is in the usergroup ‘Regular’
Hello again! i have a quick question about showing a save file dialog box. Is it difficult?
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Administrator
gbWilly is in the usergroup ‘unknown’
Here is some example code, I added the project source

Code (gambas)

  1. Public Sub Form_Open()
  2.  
  3.   Application.MainWindow = Me
  4.   Me.Center
  5.   Me.Caption = "How to save some text using a Dialog.SaveFile"
  6.  
  7.  
  8. Public Sub Button1_Click()
  9.  
  10.   If Dialog.SaveFile() Then
  11.     'Cancel was clicked
  12.   Else
  13.     'Save the file using returned Dialog.Path
  14.     File.Save(Dialog.Path, TextArea1.Text)
  15.  
  16.  
  17. Public Sub TextArea1_Change()
  18.  
  19.   Button1.Enabled = True
  20.  

Attachment

Enjoy…

gbWilly
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories


… there is always a Catch if things go wrong!
Online now: No Back to the top

Post

Posted
Rating:
#3
Guru
BruceSteers is in the usergroup ‘Guru’
It's easy , you just have to wrap your head around the fact the return value is an error value and does not mean success.

So If Dialog.SaveFile() = True there was an error (cancel was clicked)

It seems kinda counter intuitive but there it is, many other gambas methods work that way too.

You can set Dialog.Path (plus other Dialog properties) before you call it then the dialog opens at that path.  then you read Dialog.Path after to get the chosen path.

Have a read of the wiki to learn about Dialog.Title, Dialog.Filter/Dialog.FilterIndex, etc
/comp/gb.qt4/dialog - Gambas Documentation

And if you add the component gb.form.dialog you will get more advanced dialogs with more options…
/comp/gb.form.dialog/dialog - Gambas Documentation
Online now: No Back to the top
1 guest and 0 members have just viewed this.