Jump to content

file write failed


Recommended Posts

MsgBox(0, "Result", "Pass", 10) 


$text = WinGetText("Result")
If StringInStr($text, "Pass") > 0 Then


;Local $resultFile = FileOpen(@ScriptDir & "\result.txt", 1);1 = Write mode (append to end of file) 
 $resultFile = FileOpen(@ScriptDir & "\result.txt", 1);1 = Write mode (append to end of file)


FileWriteLine($resultFile, "")
FileWriteLine($resultFile, "testing 1 2 3 : Pass")


FileClose($resultFile)
Else
    MsgBox(0, "Result", "failed", 10)
EndIf

Exit

i run this script but i don't get the expected output.

the expected output is : -

when popup box show "Pass", it will write the line that i want into result.txt file.

please show me what is wrong with this script...

Link to comment
Share on other sites

hi rizal,

Looks to me that MsgBox is closing before WinGetText can capture the text.

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to comment
Share on other sites

Whatever timer you put, when the MsgBox instruction terminates, it means that the message box has been closed.

So there is no window having this title when control passes to WinGetText.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Whatever timer you put, when the MsgBox instruction terminates, it means that the message box has been closed.

So there is no window having this title when control passes to WinGetText.

could u suggest solutions for this script?

Link to comment
Share on other sites

if i where you i would use an inputbox instead, somthing like this:

$var = InputBox("Title", "Enter what you want to put in the file")

then you can write $var to a file

i'm running a software that will popup "Pass' box if the test case success. so that why i need to get the text from the message box.

the script that i shared is just part of the whole script.

Link to comment
Share on other sites

it is simething weird because the Msgbox of sucess you call it arbitrarily so the sucess is always. but the msgbox that you are using don`t allow to you the use you want to give it. You don`t define a sucess by the window that told you "You have succeed", you define the sucess by something else.

I suggest to you create your own wondow, but mostly i suggest that tell us what sucess or fail. a better approach of what you really want to do.

Maybe i have misspelled a few things, sorry.

Edited by monoscout999
Link to comment
Share on other sites

then you might have to ether make a gui pop-up and get the text of the gui before it closes, or you could just make a variable = to "pass". the second option can be used with the msgbox but it might not be what you want. the gui is just more code. i could make an example gui if you want

[spoiler]My UDFs: Login UDF[/spoiler]

Link to comment
Share on other sites

then you might have to ether make a gui pop-up and get the text of the gui before it closes, or you could just make a variable = to "pass". the second option can be used with the msgbox but it might not be what you want. the gui is just more code. i could make an example gui if you want

can u show me the example using gui

Link to comment
Share on other sites

Hi rizal

Simple work around is to create another script with just

MsgBox(0, "Result", "Pass")
and complied it. Run it but don't click ok so as to keep it there. Then you can get on with your main script.

Totally fake.

The scripts will pause while the msgbox is open.

The real question to rizal is: What determine your sucess?

Edited by monoscout999
Link to comment
Share on other sites

@rizal

im sure you will have some questions on the script. remember that the help file is your best firend :) and if you cant find it in the help file feel free to ask here on the form

#include <WindowsConstants.au3>
$Form1 = GuiCreate("Result")
$label1 = GuiCtrlCreateLabel("Pass", 55, 30)
$button1 = GuiCtrlCreateButton("OK", 50, 50)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GuiGetMsg()
    Switch $nMsg
      Case $GUI_EVENT_CLOSE
    Exit
      Case $button1
    _function(WinGetText("Result"))
WEnd

Func _function($text)
    If StringInStr($text, "Pass") > 0 Then

        ;Local $resultFile = FileOpen(@ScriptDir & "\result.txt", 1);1 = Write mode (append to end of file) 
        $resultFile = FileOpen(@ScriptDir & "\result.txt", 1);1 = Write mode (append to end of file)

        FileWriteLine($resultFile, "")
        FileWriteLine($resultFile, "testing 1 2 3 : Pass")

        FileClose($resultFile)
    Else
        MsgBox(0, "Result", "failed", 10)
    EndIf

    Exit
EndFunc

the code is untested however im sure it works great. if the button is in a odd position then just change the "50, 50" part in the GuiCtrlCreateButton()

Edited by pieeater

[spoiler]My UDFs: Login UDF[/spoiler]

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