Jump to content

Save File Dialog


Recommended Posts

Hello,

I'm trying to make a save file dialog that saves things. I've made a Space where users can type things and then push a save button and then the save dialog appears. I already figured that out, but how to let the program save the typed text.

For example what happens:

I type the text: "hello, how are you? I'm fine." and then push the save button, then the save file dialog appears. I type the filename select the right extension and then click save, but when I check if the file is really saved then it doesn't exist.

For example what I want the program to do:

I type the text: "hello, how are you? I'm fine." and then push the save button, then the save file dialog appears. I type the filename select the right extension and then click save. and when I check if the file is reallt saved it exists.

Kind Regards,

PcExpert

Link to comment
Share on other sites

  • Moderators

I am going to assume that you are talking about a .txt file. In that case you need to save the inputed text (GUICtrlRead($InputBox)) into a variable example: $InputRead = GUICtrlRead($InputBox) ....

Also, you know by now that you need to post your code for proper support. Could be that your FileSaveDialog() settings are incorrect.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Ok, here's the code:

#include <GUIConstants.au3>

#include <GUIConstants.au3>

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

$oRP = ObjCreate("RICHTEXT.RichtextCtrl.1")

GUICreate("Writer", 600, 600, -1, -1,BitOr($WS_OVERLAPPEDWINDOW,$WS_VISIBLE,$WS_CLIPSIBLINGS))

$TagsPageC = GuiCtrlCreateLabel('Visit Tags Page', 5, 180, 100, 15, $SS_CENTER)

GuiCtrlSetFont($TagsPageC,9,400,4)

GuiCtrlSetColor($TagsPageC,0x0000ff)

GuiCtrlSetCursor($TagsPageC,0)

$PrefsC = GUICtrlCreateButton('Font',175,575,70,20)

$StatC = GUICtrlCreateButton('Plain Style',245,575,70,20)

$openfile = GUICtrlCreateButton('Bestand openen',10,10,90,20)

$savefile = GUICtrlCreateButton('Bestand opslaan',120,10,90,20)

$GUIActiveX = GUICtrlCreateObj( $oRP, 10, 10 , 500 , 500 )

GUICtrlSetPos($GUIActiveX,10,70,580,500)

With $oRP; Object tag pool

.OLEDrag()

.Font = 'Arial'

;.FileName = @ScriptDir & '\RichText.rtf'

;.BackColor = 0xff00

EndWith

GUISetState ();Show GUI

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $TagsPageC

Run(@ComSpec & ' /c start http://www.myplugins.info/guids/typeinfo/t...#39;,'', @SW_HIDE)

Case $msg = $PrefsC

$oRP.SelFontSize = 12

Case $msg = $StatC

$oRP.SelBold = False

$oRP.SelItalic = False

$oRP.SelUnderline = False

$oRP.SelFontSize = 8

Case $msg = $Openfile

FileOpenDialog("Bestand Openen...", @MyDocumentsDir, "Documenten (*.rtf;*.pbw)", 1 + 4 )

Case $msg = $Savefile

FileSaveDialog( "Bestand Opslaan Als...", @MyDocumentsDir, "Documenten (*.rtf;*.pbw)", 2)

EndSelect

WEnd

Exit

Func MyErrFunc()

$HexNumber=hex($oMyError.number,8)

Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !" & @CRLF & @CRLF & _

"err.description is: " & @TAB & $oMyError.description & @CRLF & _

"err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _

"err.number is: " & @TAB & $HexNumber & @CRLF & _

"err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _

"err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _

"err.source is: " & @TAB & $oMyError.source & @CRLF & _

"err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _

"err.helpcontext is: " & @TAB & $oMyError.helpcontext _

,5)

SetError(1)

Endfunc

Link to comment
Share on other sites

#include <GUIConstants.au3>
#include "FileDialog.au3"

$Flags = BitOR($cdlOFNExplorer, $cdlOFNOverwritePrompt, $cdlOFNLongNames, $cdlOFNPathMustExist, $cdlOFNNoChangeDir)
$Dialog = 0

$oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

$oRP = ObjCreate("RICHTEXT.RichtextCtrl.1")

GUICreate("Writer", 600, 600, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_VISIBLE, $WS_CLIPSIBLINGS))
$TagsPageC = GUICtrlCreateLabel('Visit Tags Page', 5, 180, 100, 15, $SS_CENTER)
GUICtrlSetFont($TagsPageC, 9, 400, 4)
GUICtrlSetColor($TagsPageC, 0x0000ff)
GUICtrlSetCursor($TagsPageC, 0)
$PrefsC = GUICtrlCreateButton('Font', 175, 575, 70, 20)
$StatC = GUICtrlCreateButton('Plain Style', 245, 575, 70, 20)
$openfile = GUICtrlCreateButton('Bestand openen', 10, 10, 90, 20)
$savefile = GUICtrlCreateButton('Bestand opslaan', 120, 10, 90, 20)

$GUIActiveX = GUICtrlCreateObj($oRP, 10, 10, 500, 500)
GUICtrlSetPos($GUIActiveX, 10, 70, 580, 500)

With $oRP; Object tag pool
    .OLEDrag ()
    .Font = 'Arial'
;.FileName = @ScriptDir & '\RichText.rtf'
;.BackColor = 0xff00
EndWith

GUISetState();Show GUI

While 1
    $msg = GUIGetMsg()
    
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $TagsPageC
            Run(@ComSpec & ' /c start http://www.myplugins.info/guids/typeinfo/typeinfo.php?clsid={3B7C8860-D78F-101B-B9B5-04021C009402}', '', @SW_HIDE)
        Case $msg = $PrefsC
            $oRP.SelFontSize = 12
        Case $msg = $StatC
            $oRP.SelBold = False
            $oRP.SelItalic = False
            $oRP.SelUnderline = False
            $oRP.SelFontSize = 8
        Case $msg = $openfile
            FileOpenDialog("Bestand Openen...", @MyDocumentsDir, "Documenten (*.rtf;*.pbw)", 1 + 4)
        Case $msg = $savefile
            $oMyError = 0
            
            $Dialog = 1; show save
            $s_text = $oRP.text
            $file = _FileDialog ($s_text, "Bestand Opslaan Als...", @MyDocumentsDir, "", "Documenten (*.rtf;*.pbw)", 1, $Flags, $Dialog)
            $oMyError = $DialogError
            If @error Then
                MyErrFunc()
            EndIf
            $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
;~          FileSaveDialog( "Bestand Opslaan Als...", @MyDocumentsDir, "Documenten (*.rtf;*.pbw)", 2)
    EndSelect
WEnd

Exit

Func MyErrFunc()
    
    $HexNumber = Hex($oMyError.number, 8)
    
    MsgBox(0, "AutoItCOM Test", "We intercepted a COM Error !" & @CRLF & @CRLF & _
            "err.description is: " & @TAB & $oMyError.description & @CRLF & _
            "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
            "err.number is: " & @TAB & $HexNumber & @CRLF & _
            "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
            "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
            "err.source is: " & @TAB & $oMyError.source & @CRLF & _
            "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
            "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
            , 5)
    
    SetError(1)
EndFunc  ;==>MyErrFunc

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

If I use that code, i'll get the following errors:

C:\Documents and Settings\Administrator\Bureaublad\SCRIPT\products\PcBase Writer 1.au3(2,10) : ERROR: can't open include file "FileDialog.au3"

#include "FileDialog.au3"

~~~~~~~~~^

C:\Documents and Settings\Administrator\Bureaublad\SCRIPT\products\PcBase Writer 1.au3(4,31) : WARNING: $cdlOFNExplorer: possibly used before declaration.

$Flags = BitOR($cdlOFNExplorer,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\Administrator\Bureaublad\SCRIPT\products\PcBase Writer 1.au3(4,55) : WARNING: $cdlOFNOverwritePrompt: possibly used before declaration.

$Flags = BitOR($cdlOFNExplorer, $cdlOFNOverwritePrompt,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\Administrator\Bureaublad\SCRIPT\products\PcBase Writer 1.au3(4,73) : WARNING: $cdlOFNLongNames: possibly used before declaration.

$Flags = BitOR($cdlOFNExplorer, $cdlOFNOverwritePrompt, $cdlOFNLongNames,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\Administrator\Bureaublad\SCRIPT\products\PcBase Writer 1.au3(4,95) : WARNING: $cdlOFNPathMustExist: possibly used before declaration.

$Flags = BitOR($cdlOFNExplorer, $cdlOFNOverwritePrompt, $cdlOFNLongNames, $cdlOFNPathMustExist,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\Administrator\Bureaublad\SCRIPT\products\PcBase Writer 1.au3(4,115) : WARNING: $cdlOFNNoChangeDir: possibly used before declaration.

$Flags = BitOR($cdlOFNExplorer, $cdlOFNOverwritePrompt, $cdlOFNLongNames, $cdlOFNPathMustExist, $cdlOFNNoChangeDir)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~^

C:\Documents and Settings\Administrator\Bureaublad\SCRIPT\products\PcBase Writer 1.au3(56,37) : WARNING: $DialogError: possibly used before declaration.

$oMyError = $DialogError

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\Administrator\Bureaublad\SCRIPT\products\PcBase Writer 1.au3(4,31) : ERROR: $cdlOFNExplorer: undeclared global variable.

$Flags = BitOR($cdlOFNExplorer,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\Administrator\Bureaublad\SCRIPT\products\PcBase Writer 1.au3(4,55) : ERROR: $cdlOFNOverwritePrompt: undeclared global variable.

$Flags = BitOR($cdlOFNExplorer, $cdlOFNOverwritePrompt,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\Administrator\Bureaublad\SCRIPT\products\PcBase Writer 1.au3(4,73) : ERROR: $cdlOFNLongNames: undeclared global variable.

$Flags = BitOR($cdlOFNExplorer, $cdlOFNOverwritePrompt, $cdlOFNLongNames,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\Administrator\Bureaublad\SCRIPT\products\PcBase Writer 1.au3(4,95) : ERROR: $cdlOFNPathMustExist: undeclared global variable.

$Flags = BitOR($cdlOFNExplorer, $cdlOFNOverwritePrompt, $cdlOFNLongNames, $cdlOFNPathMustExist,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\Administrator\Bureaublad\SCRIPT\products\PcBase Writer 1.au3(4,115) : ERROR: $cdlOFNNoChangeDir: undeclared global variable.

$Flags = BitOR($cdlOFNExplorer, $cdlOFNOverwritePrompt, $cdlOFNLongNames, $cdlOFNPathMustExist, $cdlOFNNoChangeDir)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~^

C:\Documents and Settings\Administrator\Bureaublad\SCRIPT\products\PcBase Writer 1.au3(56,37) : ERROR: $DialogError: undeclared global variable.

$oMyError = $DialogError

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\Administrator\Bureaublad\SCRIPT\products\PcBase Writer 1.au3(55,136) : ERROR: _FileDialog(): undefined function.

$file = _FileDialog ($s_text, "Bestand Opslaan Als...", @MyDocumentsDir, "", "Documenten (*.rtf;*.pbw)", 1, $Flags, $Dialog)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\Administrator\Bureaublad\SCRIPT\products\PcBase Writer 1.au3 - 8 error(s), 6 warning(s)

Link to comment
Share on other sites

Can somebody please send the file: FileDialog.au3 to me, because it is not in my examples directory from the autoit beta. I have already made the script in the autoit beta/edxamples directory.

Edited by PcExpert
Link to comment
Share on other sites

Can somebody please send the file: FileDialog.au3 to me, because it is not in my examples directory from the autoit beta. I have already made the script in the autoit beta/edxamples directory.

go to here http://www.autoitscript.com/forum/index.ph...ndpost&p=165404

download the file

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Thanks, how can I do the same, but then to open a file?

look at this file, it's the test file for the file dialog http://www.autoitscript.com/forum/index.ph...pe=post&id=7687

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Thanks, is there a page on the internet or something simillar that explains how to extend it with more functions? Or can I use the functions from the ActiveX Edit Control in the helpfile?

Edited by PcExpert
Link to comment
Share on other sites

I'm trying to extend it. I'm now busy with a combobox where the user can select the frontsize. This is my code, but it isn't working.

Line 21, 22 and 24 are new

#include <GuiConstants.au3>

#Include <GuiStatusBar.au3>

#include <Array.au3>

#include "FileDialog.au3"

Opt("MustDeclareVars", 1)

_Main_EditControl()

Func _Main_EditControl()

Local $file, $gui, $ctrl_Edit, $btn_file, $msg, $StatusBar1, $btn_save, $s_text

Local $Caption = "Bestand Openen...", $Default_File = ""

Local $Filter = "Documenten (*.pbw;*.rtf)"

Local $Default_Index = 1

Local $Dialog = 0 ; show open

Local $Flags = BitOR($cdlOFNExplorer, $cdlOFNFileMustExist, $cdlOFNLongNames, $cdlOFNPathMustExist, $cdlOFNNoChangeDir)

$gui = GUICreate("PcBase Writer", 600, 600)

$ctrl_Edit = GUICtrlCreateEdit("", 10, 70, 580, 500, -1, $WS_EX_CLIENTEDGE)

$btn_file = GUICtrlCreateButton("Bestand Openen", 10, 10, 90, 20)

$btn_save = GUICtrlCreateButton("Bestand Opslaan", 120, 10, 90, 20)

$StatusBar1 = _GuiCtrlStatusBarCreate ($gui, -1, "")

$cmb_pnt = GUICtrlCreateCombo("12", 230, 10)

GUICtrlSetData($cmb_pnt, "6|8|10|12|14|16|18|20|", "12")

GUICtrlSetFont($ctrl_Edit, $btn_Pnt)

GUISetState(@SW_SHOW)

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $btn_file

$file = _FileDialog ($ctrl_Edit, $Caption, @ScriptDir, $Default_File, $Filter, $Default_Index, $Flags, $Dialog, 3)

If @error Then

_GuiCtrlStatusBarSetText ($StatusBar1, $DialogError.description, 0)

Else

_GuiCtrlStatusBarSetText ($StatusBar1, $file, 0)

EndIf

Case $msg = $btn_save

$Flags = BitOR($cdlOFNExplorer, $cdlOFNOverwritePrompt, $cdlOFNLongNames, $cdlOFNPathMustExist, $cdlOFNNoChangeDir)

$Dialog = 1 ; show save

$s_text = GUICtrlRead($ctrl_Edit)

$file = _FileDialog ($s_text, $Caption, @ScriptDir, $Default_File, $Filter, $Default_Index, $Flags, $Dialog)

If @error Then

_GuiCtrlStatusBarSetText ($StatusBar1, $DialogError.description, 0)

Else

_GuiCtrlStatusBarSetText ($StatusBar1, $file, 0)

EndIf

Case Else

;;;;;;;

EndSelect

WEnd

GUIDelete()

EndFunc ;==>_Main_EditControl

Func _DialogError()

MsgBox(0, "File Dialog", "Intercepted an Error !" & @CRLF & @CRLF & _

"err.description is: " & @TAB & $DialogError.description & @CRLF & _

"err.number is: " & @TAB & Hex($DialogError.number, 8) & @CRLF & _

"err.scriptline is: " & @TAB & $DialogError.scriptline & @CRLF)

EndFunc ;==>_DialogError

Kind Regards,

PcExpert

Edited by PcExpert
Link to comment
Share on other sites

Looks like most of it is from the test dialog script, anyways here you go:

#include <GuiConstants.au3>
#Include <GuiStatusBar.au3>
#include <Array.au3>
#include "FileDialog.au3"
Opt("MustDeclareVars", 1)

_Main_EditControl()

Func _Main_EditControl()
    Local $file, $gui, $ctrl_Edit, $btn_file, $msg, $StatusBar1, $btn_save, $s_text
    Local $Caption = "Bestand Openen...", $Default_File = ""
    Local $Filter = "Documenten (*.pbw;*.rtf)"
    Local $Default_Index = 1
    Local $Dialog = 0; show open
    Local $Flags = BitOR($cdlOFNExplorer, $cdlOFNFileMustExist, $cdlOFNLongNames, $cdlOFNPathMustExist, $cdlOFNNoChangeDir)
    Local $cmb_pnt
    $gui = GUICreate("PcBase Writer", 600, 600)
    $ctrl_Edit = GUICtrlCreateEdit("", 10, 70, 580, 500, -1, $WS_EX_CLIENTEDGE)
    $btn_file = GUICtrlCreateButton("Bestand Openen", 10, 10, 90, 20)
    $btn_save = GUICtrlCreateButton("Bestand Opslaan", 120, 10, 90, 20)
    $StatusBar1 = _GuiCtrlStatusBarCreate ($gui, -1, "")
    $cmb_pnt = GUICtrlCreateCombo("12", 230, 10)
    GUICtrlSetData($cmb_pnt, "6|8|10|12|14|16|18|20|", "12")
    
    GUICtrlSetFont($ctrl_Edit, GUICtrlRead($cmb_pnt))
    
    GUISetState(@SW_SHOW)
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $btn_file
                $file = _FileDialog ($ctrl_Edit, $Caption, @ScriptDir, $Default_File, $Filter, $Default_Index, $Flags, $Dialog, 3)
                If @error Then
                    _GuiCtrlStatusBarSetText ($StatusBar1, $DialogError.description, 0)
                Else
                    _GuiCtrlStatusBarSetText ($StatusBar1, $file, 0)
                EndIf
            Case $msg = $btn_save
                $Flags = BitOR($cdlOFNExplorer, $cdlOFNOverwritePrompt, $cdlOFNLongNames, $cdlOFNPathMustExist, $cdlOFNNoChangeDir)
                $Dialog = 1; show save
                $s_text = GUICtrlRead($ctrl_Edit)
                $file = _FileDialog ($s_text, $Caption, @ScriptDir, $Default_File, $Filter, $Default_Index, $Flags, $Dialog)
                If @error Then
                    _GuiCtrlStatusBarSetText ($StatusBar1, $DialogError.description, 0)
                Else
                    _GuiCtrlStatusBarSetText ($StatusBar1, $file, 0)
                EndIf
            Case $msg = $cmb_pnt
                GUICtrlSetFont($ctrl_Edit, GUICtrlRead($cmb_pnt))
            Case Else
            ;;;;;;;
        EndSelect
    WEnd
    GUIDelete()
    
EndFunc  ;==>_Main_EditControl

Func _DialogError()
    MsgBox(0, "File Dialog", "Intercepted an Error !" & @CRLF & @CRLF & _
            "err.description is: " & @TAB & $DialogError.description & @CRLF & _
            "err.number is: " & @TAB & Hex($DialogError.number, 8) & @CRLF & _
            "err.scriptline is: " & @TAB & $DialogError.scriptline & @CRLF)
EndFunc  ;==>_DialogError

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

I've got a problem, if I want that the text "Table" is size 18 and I want that the text "other tables" is size 14, then I select The text "table", but then all the text is size 18. So is there a way to make the text "table" size 18 and the text "other tables" size 14?

Kind Regards,

PcExpert

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...