Jump to content

FileWrite Error


Recommended Posts

Do an _ArrayDisplay on $aArray. Does $aArray[0] hold the information you expect it to

​still the same error, sometimes i have this error ,sometimes script work well

Edited by ruxer100
Link to comment
Share on other sites

This error tells you that _StringBetween was not successful and didn't create an array.
Check the return value of _StringBeetween and see if there happened an error.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

This error tells you that _StringBetween was not successful and didn't create an array.
Check the return value of _StringBeetween and see if there happened an error.

​_StringBetween return 0 and filewrite error.  when i use this function first time error not shown but use this function second time error shown

Edited by ruxer100
Link to comment
Share on other sites

Add error checking to your script, if _StringBetween() returns an error, try repeating the _IEBodyReadHTML() part of the script a couple tomes until _StringBetween() either works or until it has failed a few times and exit the script with your own error stating this.

Link to comment
Share on other sites

Yup, I would check the array and contents prior to the file ops

If IsArray($aArray) Then
    If stringlen($aArray[0]) = 0 Then $aArray[0] = "No Data"
    ; FileOpen
    ; FileWrite
    ; FileClose
EndIf

 

 

 

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

I have that 

Do
       Local $sHTML = _IEBodyReadHTML($oIE)
      $serwer = GUICtrlRead($serwer)
      $start = "<h2>Świat " & $serwer & " </h2>"
      $end = "</p>"
     Local $aArray = _StringBetween($sHTML, $start, $end)
     Until $aArray = 0
 If $aArray = 0 then
     MsgBox(0, "", "work")
     $handle=FileOpen("odbiorcy.txt",2)
      FileWrite($handle,$aArray[0])
      FileClose($handle)
     EndIf

and when $aArray = 0 shows this same error, MsgBox shows after close him shows error

Edited by ruxer100
Link to comment
Share on other sites

That loop exits as soon as _StringBetween fails. Didn't you mean to have the loop exit as soon as it succeeds instead? Something like...

$attemptCount = 0

Do
    $attemptCount += 1
    If $attemptCount > 1 Then Sleep(1000)
    Local $sHTML = _IEBodyReadHTML($oIE)
    $serwer = GUICtrlRead($serwer)
    $start = "<h2>Swiat " & $serwer & " </h2>"
    $end = "</p>"
    Local $aArray = _StringBetween($sHTML, $start, $end)
Until IsArray($aArray) ; or: Until @error = 0, or: Until $aArray <> 0

;If $aArray = 0 Then  ; <-- this check isn't necessary any more if you make sure you only reach this point if and when the _StringBetween returned an array
MsgBox(0, "", "work")
$handle = FileOpen("odbiorcy.txt", 2)
FileWrite($handle, $aArray[0])
FileClose($handle)
;EndIf

/edit: you may also want to throw a Sleep(1000) in that loop to wait a second between each check.

/edit 2: indentation in codebox above is broken for some reason.

Edited by SadBunny

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

That loop exits as soon as _StringBetween fails. Didn't you mean to have the loop exit as soon as it succeeds instead? Something like...

$attemptCount = 0

Do
    $attemptCount += 1
    If $attemptCount > 1 Then Sleep(1000)
    Local $sHTML = _IEBodyReadHTML($oIE)
    $serwer = GUICtrlRead($serwer)
    $start = "<h2>Swiat " & $serwer & " </h2>"
    $end = "</p>"
    Local $aArray = _StringBetween($sHTML, $start, $end)
Until IsArray($aArray) ; or: Until @error = 0, or: Until $aArray <> 0

;If $aArray = 0 Then  ; <-- this check isn't necessary any more if you make sure you only reach this point if and when the _StringBetween returned an array
MsgBox(0, "", "work")
$handle = FileOpen("odbiorcy.txt", 2)
FileWrite($handle, $aArray[0])
FileClose($handle)
;EndIf

/edit: you may also want to throw a Sleep(1000) in that loop to wait a second between each check.

/edit 2: indentation in codebox above is broken for some reason.

​This works but when i click button second time nothing do.

Link to comment
Share on other sites

  • Developers

​This works but when i click button second time nothing do.

​Maybe show your script so we can see?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

​Maybe show your script so we can see?

Jos

#include <string.au3>
#include <Array.au3>
#include <File.au3>
#include <IE.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=c:\users\szymon\desktop\margospam.kxf
$MargoSpam = GUICreate("MargoSpam", 438, 292, 284, 204)
$Trescwiadomosci = GUICtrlCreateInput("Treść wiadomości", 112, 168, 257, 21)
$serwer = GUICtrlCreateInput("serwer", 288, 72, 121, 21)
$normal = GUICtrlCreateButton("normal", 56, 72, 75, 25)
$priv = GUICtrlCreateButton("priv", 160, 72, 75, 25)
$START = GUICtrlCreateButton("START", 160, 224, 155, 41)
$czas = GUICtrlCreateInput("", 288, 136, 41, 21)
$labeltaki = GUICtrlCreateLabel("Odstępy między wiadomościami", 24, 136, 207, 17)
$Label1 = GUICtrlCreateLabel("w sekundach", 180, 136, 108, 17)
Global $oIE =  _IECreate("http://www.margonem.pl/?task=stats")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg

    Case $GUI_EVENT_CLOSE
            Exit
case $normal
       normalny()
    EndSwitch
 WEnd


func normalny()
$attemptCount = 0

Do
    $attemptCount += 1
    If $attemptCount > 1 Then Sleep(1000)
    Local $sHTML = _IEBodyReadHTML($oIE)
    $serwer = GUICtrlRead($serwer)
    $start = "<h2>Świat " & $serwer & " </h2>"
    $end = "</p>"
    Local $aArray = _StringBetween($sHTML, $start, $end)
Until IsArray($aArray)

MsgBox(0, "", "work")
$handle = FileOpen("odbiorcy.txt", 2)
FileWrite($handle, $aArray[0])
FileClose($handle)

EndFunc

 

Link to comment
Share on other sites

  • Developers

Somehow I get the feeling this is for an online game ....right?
Did you actually read our forum rules you were pointed to on Monday in this post?

Jos

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

You are making a spam bot?! Yuck, that's just purely for clickbaiting and/or trolling and it makes you look like a total asshole in any game. And you break two forum rules (game / removing first post)? And you are ungrateful. Come on man... Don't be that guy.

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

  • Moderators

SadBunny, as you are quoting the rules, I would have you look at item 4 regarding flaming users, as well as the section regarding reporting. You've been around long enough to know that you should let it lie and allow the Mods to handle an issue once they've intervened.

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Developers

Guess what .. it is already handled and the OP has gotten a couple of days vacation to read them properly.

*click*

Jos

@Melbe23: Great minds ........ etc

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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