SorryButImaNewbie

Same code, different results

13 posts in this topic

Hello everyone!

Today I seemed to run in to an old nemesis of mine, PDFCreator 1.7.1 . I had some problems with it in the past, and I thought that nowadays im kind of okey with it at least, but today It seems like a snippet of mine doesn't work as i intend it to. More exactly, the problem is that the last PDF isn't being renamed like the others, while I use the "same" code, and the others in the chain are good and working.

Maybe you guys see something I dont, here is the code

;2. PDF
    Sleep(1000)
    WinActivate("PDFCreator 1.", "")
    WinWaitActive("PDFCreator 1.", "")
    ;WinKill("MozillaWindowClass", "")
    Local $TopUpName = "TopUpEURFeltöltés_" & $TopUpDate
    ControlCommand("PDFCreator 1.", "", "[CLASSNN:ThunderRT6TextBox6]", "EditPaste", $TopUpName & "(2)")
    ControlSetText("PDFCreator 1.", "", "[CLASSNN:ThunderRT6TextBox6]", $TopUpName & "(2)")
    ControlClick("PDFCreator 1.", "", "[CLASSNN:ThunderRT6CommandButton7]")
    $WindowWaitCheck = WinWaitActive("Mentés másként", "", 5)
    If $WindowWaitCheck = 0 Then
        ControlClick("PDFCreator 1.", "", "[CLASSNN:ThunderRT6CommandButton7]")
    EndIf
    WinActivate("Mentés másként", ""); Kell-e ez ide?
    WinMove("Mentés másként", "", 0, 0)
    MouseClick("", 565, 50)
    Send("{BS}" & $PDFmentesPath & "{Enter}")
    ControlClick("Mentés másként", "", "[CLASSNN:Button1]")
    ;3. PDF
    WinActivate("PDFCreator 1.", "")
    WinWaitActive("PDFCreator 1.", "")
    Local $TopUpName = "TopUpEURFeltöltés_(számla)" & $TopUpDate
    ;WinKill("MozillaWindowClass", "")
    ControlCommand("PDFCreator 1.", "", "[CLASSNN:ThunderRT6TextBox6]", "EditPaste", $TopUpName)
    ControlSetText("PDFCreator 1.", "", "[CLASSNN:ThunderRT6TextBox6]", $TopUpName)
    ControlClick("PDFCreator 1.", "", "[CLASSNN:ThunderRT6CommandButton7]")
    $WindowWaitCheck = WinWaitActive("Mentés másként", "", 5)
    If $WindowWaitCheck = 0 Then
        ControlClick("PDFCreator 1.", "", "[CLASSNN:ThunderRT6CommandButton7]")
    EndIf
    WinActivate("Mentés másként", ""); Kell-e ez ide?
    WinMove("Mentés másként", "", 0, 0)
    MouseClick("", 565, 50)
    Send("{BS}" & $PDFmentesPath & "{Enter}")
    ControlClick("Mentés másként", "", "[CLASSNN:Button1]")

    ;4. PDF
    WinActivate("PDFCreator 1.", "")
    WinWaitActive("PDFCreator 1.", "")
    Local $TopUpName = "TopUpEURFeltöltés_(számla)" & $TopUpDate
    ;WinKill("MozillaWindowClass", "")
    ControlCommand("PDFCreator 1.", "", "[CLASSNN:ThunderRT6TextBox6]", "EditPaste", $TopUpName & "(2)") ;ControlSend?
    ControlSetText("PDFCreator 1.", "", "[CLASSNN:ThunderRT6TextBox6]", $TopUpName & "(2)")
    ControlClick("PDFCreator 1.", "", "[CLASSNN:ThunderRT6CommandButton7]")
    $WindowWaitCheck = WinWaitActive("Mentés másként", "", 5)
    If $WindowWaitCheck = 0 Then
        ControlClick("PDFCreator 1.", "", "[CLASSNN:ThunderRT6CommandButton7]")
    EndIf
    WinActivate("Mentés másként", ""); Kell-e ez ide?
    WinMove("Mentés másként", "", 0, 0)
    MouseClick("", 565, 50)
    Send("{BS}" & $PDFmentesPath & "{Enter}")
    ControlClick("Mentés másként", "", "[CLASSNN:Button1]")

The 4. PDF doesn't rename  the file and is basicly stuck there. According to the console in debug mode, the code was read/executed, it doesn't show anything else then what it should show.

Thank you users of the Forum AutoIt!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Nothing seems obvious to me.

You really should make a function and reduce that code by about three quarters.

It will also help with troubleshooting.

Basically, you can just add a parameter to the Function call for each PDF.

i.e.

RenamePDF("Pdf_1")
RenamePDF("Pdf_2")
RenamePDF("Pdf_3")
RenamePDF("Pdf_4")


Func RenamePDF($pdf)

     $name = $pdf

     ; Your one lot of repeated code here.

     ;

EndFunc

Instead of repeating each function call for each pdf (RenamePDF("Pdf_1")), you could create a loop, but as it is only four lines I probably wouldn't bother.

P.S. I would ignore the $name variable, and just use $pdf where you need to.

$name was only added to make you think.

Likewise Pdf_1 etc. Just use your equivalents.

Edited by TheSaint
1 person likes this

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Wouldn't this be much easier|quicker|reliable to rename a file?

FileMove
Edited by jdelaney
1 person likes this

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Thanks both of you!

@TheSaint

Yeah its a good time to start use functions with variable calls (never done it before really, and I too wanted to shorten my code somehow!)

@jdelaney

Thx, I never used FileMove before, probably will look into these functions :) , but after just checking the help file, I don't see how can I rename a file with it (also it says so in the help file, that I can and should use it to that too :) )

Share this post


Link to post
Share on other sites

From the Help file for FileMove

 
Remarks

See FileFindFirstFile() for a discussion about wildcards.

If the source and destination paths are on different volumes a copy and delete operation is performed rather than a move.

Because AutoIt lacks a "FileRename" function, use FileMove() to rename a file!

The destination directory must already exist, except using with flag value $FC_CREATEPATH (8).
For instance the combined flag $FC_OVERWRITE (1) + $FC_CREATEPATH (8) overwrites the target file and prechecks for the destination directory structure and if it doesn't exist creates it automatically.

Some file attributes can make the overwriting impossible, if this is the case look at FileSetAttrib() to change the attributes of a file.
 


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Yup, thats what I talk about,

I read this as well, but dont understand how to change the name of the file, where do I set the new name?  Maybe its just my english, but I don't see how do I rename it

Edit: In the main time I checked around the forums and got this >thread (quiet quickly I might add :)

$sFileOld = "MyFile.au3"
$sFileRenamed = "MyNewFile.au3"
FileMove($sFileOld, $sFileRenamed)

or

$sFileOld = "C:MyFiles"
$sFileRenamed = "C:MyNewFiles"
DirMove($sFileOld, $sFileRenamed)

These helped me understand how to do it, I would implement them to the help files :)

Edit2: "and filename of the moved file." description of the dest parameters what I missed

Edited by SorryButImaNewbie

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

or simply...

local $ret = filemove(@scriptdir & '\rename_test.txt', @scriptdir & '\rename_newname.txt')
if $ret <> 1 then exit msgbox(0,'ERROR','Error renaming file')

if the destintation dir changes then see the flag parm for FileMove.

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

@SorryButImaNewbie

Just wondering why you automate interface ?
You can do it in the background, look here.
 
mLipok
Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

You can always roll your own wrapper funcs to do the renaming.

eg:

If Not FileExists(@ScriptDir & "\000-TestDir-000") Then
    ; create the directory
    DirCreate(@ScriptDir & "\000-TestDir-000")
    ; create a dummy text file
    FileClose(FileOpen(@ScriptDir & "\000-TestDir-000\000.TestFile.000.txt", 2))
    ; change the files name: full path to file excluding file name, file name, new file name
    _FileRename(@ScriptDir & "\000-TestDir-000\", "000.TestFile.000.txt", "123.TestFile.456.txt")
    ; change the directory name: path to parent directory,  name current directory, new directory name
    _DirRename(@ScriptDir, "000-TestDir-000", "987-TestDir-654")
EndIf

Func _FileRename($sPath, $sCurrentFile, $sNewFile, $iFlag = 0, $sSlash = "\")
    ; for flag, see FileMove function in help

    $iFlag =((IsKeyword($iFlag)) ? 0 : $iFlag)
    $sSlash = ((IsKeyword($sSlash)) ? "\" : $sSlash)
    $sPath = StringRegExpReplace($sPath, "[\\/]+$", "")
    
    If Not FileMove($sPath & $sSlash & $sCurrentFile, _
        $sPath & $sSlash & $sNewFile, $iFlag) Then
        Return SetError(1, 0, 0)
    EndIf
    Return 1
EndFunc

Func _DirRename($sPath, $sCurrentDir, $sNewDir, $iFlag = 0, $sSlash = "\")
    ; for flag, see DirMove function in help

    $iFlag =((IsKeyword($iFlag)) ? 0 : $iFlag)
    $sSlash = ((IsKeyword($sSlash)) ? "\" : $sSlash)
    $sPath = StringRegExpReplace($sPath, "^[\\/]+|[\\/]+$", "")

    Local $iRet = DirMove($sPath & $sSlash & $sCurrentDir, _
        $sPath & $sSlash & $sNewDir, $iFlag)
    Return SetError(@error, @extended, $iRet)
EndFunc

.


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.

Share this post


Link to post
Share on other sites

 

@SorryButImaNewbie

Just wondering why you automate interface ?
You can do it in the background, look here.
 
mLipok

 

I'm not sure if there is anyother way mrLipok

I do that because the emphasis isn't on the file creation or the automatization, but the primery goal, now is testing. (The program we use is developed by another company, and its shitty as hell :) ) The program is starting the PDFCreator, when I do some of the specific things (for example pay in money in to an account, its open the PDFCreator to save the invoice) so I thought if its open anyway, I might as well just go with it (since closing would mean the loss of the file, i think).

The link however seems to be very usefull, and will read up on it, but not now, maybe the weekend, (but I planed to polish my SQL). However with a COM object it maybe possible, but since I'm already done with the interface automatization... Will try out next project, if opportunity presents itself :)

(Master) @SmOke_N

Thats looks a bit complicated for first read, but the behind logic as long as I catch it is sound, and would achive the same result i guess, with much less character. I will read throught/analyze this at home, since I don't wanna read the help file at work, for the extent I would need to understand completly of what you are doing there, if nothing else I will learn a method and dig myself in to a few functions I haven't really used so far, so thanks :) (bonus XP is bonus XP :) )

Share this post


Link to post
Share on other sites

The program is starting the PDFCreator, when I do some of the specific things (for example pay in money in to an account, its open the PDFCreator to save the invoice) so I thought if its open anyway, I might as well just go with it (since closing would mean the loss of the file, i think).

 

This works like a 

Find Printer Named "PDFCreator"

Print document to this printer.

But is this program (as I understand a CRM or something like that), it is expected at the end of the print?
Or simply send to the printer (in this case called PDFCreator)?
 
 
 
In the latter case there is no problem.
You can even take a short test.
Try the run START /..../ PDFCreator, in the options, select autosave to some directory and set themselves a name but with the changing part (possibly the document sent to print names differently, eg. The next invoice number, But if the names are sent to printers always with the same title then try in PDFCreator settings as the name of the autosave add timestamp)
 
Try to make a printout of the CRM used in your company.
View contents of the directory.
 
If no PDFCreator window appears then I believe that there is no problem with the automation of the process through COM.
Provided that you can control the intervals between successive print, but rather that you can initiate a print separately?

 

btw.
Of course, I did a similar solution for my client.

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

I think I miss to much to understand Master Lipok :)

I know that PDFCreator can be a default printer (almost sure it is here)

I'm not sure if this programm would count as a CRM, since its only used inside he company, it's basicly allow our employees to search, add, delete, modify many things, in our databases, not only costumer realeted stuffs.

 

 

Try the run START /..../ PDFCreator, in the options, select autosave to some directory and set themselves a name but with the changing part (possibly the document sent to print names differently, eg. The next invoice number, But if the names are sent to printers always with the same title then try in PDFCreator settings as the name of the autosave add timestamp)
 
Try to make a printout of the CRM used in your company.
View contents of the directory.
 

 

I guess here at the first 2 rows, you want me to check if PDFCreator is the default printer? or I don't know, (sorry never used COM gates, so I may be a bit lost in it) :) Well If I would want to check the default printer I would just look in to a word file printing for example. 

What do you mean by "Try to make a printout of the CRM used in your company." ? Print out what? 

The PDFCreator is expected to pop up when I upload some money in to the account of the user (only working on the test servers with test datas so far naturaly) and the program makes an invoice of it automaticly, It tries to print it out, but I just use that PDFCreator window to instead save it to a specified directory (or folder, not sure which one is the right one to use here)

 

Controlling the intervals wouldn't be to much of a problem, since for every action I would know how many PDFs the Creator would want to print, also I could easly make it s that a new order doesn't start till it finishes its buisness with the documentation (I actually dp that with my program right now)

Edited by SorryButImaNewbie

Share this post


Link to post
Share on other sites

"Try to make a printout of the CRM used in your company."

sorry bad translation skills (my own and translate.google.pl )

Please try to do a series of prints, of course after you set AutoSave in PDFCreator.


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
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