Jump to content

How to auto save a file in File Save Dialog Window in the desired folder


Recommended Posts

  • 7 months later...
FileSaveDialog("save as",@ProgramFilesDir &"\Epson\JavaPOS\SetupPOS",'XML(*.xml)',0,"Jpos.xml")
WinActivate("Save ")
$wnd=WinGetHandle('Save','')

ControlSend($wnd,'','','!')

;ControlSend($wnd,"",'[CLASS:Button; INSTANCE:2;Text:Save]',"s")
;ControlClick($wnd,'', 'button2')


$hWND = WinWait("[CLASS:DirectUIHWND; INSTANCE:2]")
WinActivate($hWnd)
Controlsend("[CLASS:DirectUIHWND; INSTANCE:2]", "", "[CLASS:Button; INSTANCE:2]","!s")
Send("{enter}")

 I am not able to click on the save button on windows 10, however windows7  work fine any help is appreciated

saveasCapture.JPG

Link to comment
Share on other sites

NO can do for me, would be kind to post your full code. here is my  code where did I go wrong

FileSaveDialog("save as",@ProgramFilesDir &"\Epson\JavaPOS\SetupPOS",'XML(*.xml)',0,"Jpos.xml")
WinActivate("Save as ")
$wnd=WinGetHandle('Save as','')



ControlSend($wnd,"",'[CLASS:Button; INSTANCE:2;Text:Save]',"!s")
ControlClick($wnd,'', 'button2')

 

Link to comment
Share on other sites

Reason is,  this is part of a  bigger script, I am working  with an XML file,  however after making changes within the xml file, the changes appear to update only  if I save it as in that same directory. unless there is another way to save xml file

;*********************************************************Routine to add Ip address to pc.properties and  jpos.xml (printers and cash drawer); Sept 6 2017
Global $Jpos=@ProgramFilesDir&"\Epson\JavaPOS\SetupPOS\"&"Jpos.xml"
FileSetAttrib($Jpos & '\JPOS.xml', "-R")
 $ipvalue= "10.229.117.188" ;$tabprinter
 $xml = $Jpos




$pdata = FileRead($xml)



Local $posa1 = StringInStr($pdata, '"CashDrawer">')
_Replace($posa1, $ipvalue,$xml)
$pdata = FileRead($xml)

Local $posa2 = StringInStr($pdata, '"POSPrinter">')
_Replace($posa2, $ipvalue,$xml)


FileSetAttrib($Jpos & '\JPOS.xml', "+R")
FileClose($xml)
;~Local $hFileOpen = FileOpen($pdata, $FO_APPEND)
;~FileWriteLine($hFileOpen, "" & @CRLF & @CRLF)
;~FileClose($hFileOpen)






;************************************************************function to replace ip inside xlm s Epson********************


Func _Replace($PosData,$ipvalue,$xml)
$pos1 = $PosData


if $pos1>0 Then
    $pos2 = StringInStr($pdata, '</JposEntry', 0, 1, $pos1)
    if $pos2 > 0 Then
        $mdata = StringMid($pdata, $pos1, $pos2-$pos1)

        $p1 = StringInStr($pdata, 'name="PortName"', 0, 1, $pos1)
        if $p1<=$pos2 Then
            $p2 = StringInStr($pdata, '>', 0, 1, $p1)
            if $p2>0 Then
                $txt = StringMid($pdata, $p1, $p2-$p1)
                ;MsgBox(0, '1', $txt)
                $tmp = _StringBetween($txt, 'value="', '"')
                if not @error Then
                    $txt2 = StringReplace($txt, $tmp[0], $ipvalue)
                EndIf
                ;MsgBox(0, '2', $txt2)

                $mdata2 = StringReplace($mdata, $txt, $txt2)
                $pdata = StringReplace($pdata, $mdata, $mdata2)
                ConsoleWrite($pdata & @CRLF)

                $file = FileOpen($xml, 2)
                FileWrite($file, $pdata)
                ;FileSetAttrib(@ScriptDir & '\JPOS.xml', "+R")
                ;FileClose($file)
            EndIf
        EndIf
    EndIf
EndIf

EndFunc

 

Edited by antonioj84
update
Link to comment
Share on other sites

1 minute ago, Danp2 said:

I see you are already using FileOpen and FileWrite. Is that not working for you?

No it does not, the file will show kB = 0 even  though the data is updated,  once i do the "saves as" the  file size will show kb =11.  Is there something more I need to add in the code make sure its updated ?

Link to comment
Share on other sites

here is my solution. I created  dialogsaveas.exe  I anyone can improve on my code, you are welcome, let me know.

;;;;;; DialogSaveas.exe
Global $Jpos=@ProgramFilesDir&"\Epson\JavaPOS\SetupPOS\"&"Jpos.xml" ;path
FileSetAttrib($Jpos & '\JPOS.xml', "-R")  ; make file editable
FileSaveDialog("save as",@ProgramFilesDir &"\Epson\JavaPOS\SetupPOS",'XML(*.xml)',0,"Jpos.xml") ; create a save as dialog box
exit
;;;;; DialogSaveas.exe



Run('dialogSaveas.exe',@ScriptDir,@SW_HIDE) ; hide save dialog box
Sleep(250)   ;* sleep time require

WinActive("save as ")  
$Wnd=WinGetHandle('save as','')

while winExist($Wnd)
 ControlSend($Wnd,"",'[CLASS:Button; INSTANCE:2]',"!s")
Wend


;~if WinExists($Wnd) Then ControlSend($Wnd,"",'[CLASS:Button; INSTANCE:2]',"!s")
FileSetAttrib($Jpos & '\JPOS.xml', "+R") ; set read only

 

Edited by antonioj84
error
Link to comment
Share on other sites

If this works for you, great! I just don't see why it needs to be so convoluted. I would rewrite your original code something like this --

Local $Jpos=@ProgramFilesDir&"\Epson\JavaPOS\SetupPOS\"&"Jpos.xml"
Local $ipvalue= "10.229.117.188" ;$tabprinter

Local $pdata = FileRead($Jpos)
Local $posa1 = StringInStr($pdata, '"CashDrawer">')
_Replace($pdata, $posa1, $ipvalue)
Local $posa2 = StringInStr($pdata, '"POSPrinter">')
_Replace($pdata, $posa2, $ipvalue)

FileSetAttrib($Jpos, "-R")
Local $hFileOpen = FileOpen($pdata, $FO_OVERWRITE)
FileWrite($hFileOpen, $pdata)
FileClose($hFileOpen)
FileSetAttrib($Jpos, "+R")

so that all of the file reading, writing, etc occurs in the main code. Then the _Replace function only needs to change the IP address for the string that is already loaded into memory. This also reduces the file operations down to a single read/write combination.

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...