Jump to content

FileWrite problem


Recommended Posts

#include <File.au3>

WinWaitActive ( "Untitled" )

While WinExists ("Untitled") = 1

If Random() < 0.5 Then

If FileExists("timer.ini") Then

$file = FileOpen("timer.ini", 1)

FileWrite($file, "0")

FileClose($file)

Else

_FileCreate("timer.ini")

$file = FileOpen("timer.ini", 1)

FileWrite($file, "0")

FileClose($file)

EndIf

EndIf

WEnd

Now it should just put 1 zero into the file timer.ini instead it puts endless amounts..

Edited by pingpong24
Link to comment
Share on other sites

  • Developers

If FileExists("timer.ini") Then

$file = FileOpen("timer.ini", 1)

FileWrite($file, "0")

FileClose($file)

Else

_FileCreate("timer.ini")

$file = FileOpen("timer.ini", 1)

FileWrite($file, "0")

FileClose($file)

EndIf

Now it should just put 1 zero into the file timer.ini instead it puts endless amounts..

If it writes multiple zeros to the file then I am sure theres more code then what you have shown..OR if you want to replace the current content of the file with a Zero you should open the file with 2.(1 means append)

I also don't understand why you just use a single line like:

FileWite("timer.ini",0)

The result is the same as the code you show.

Edited by JdeB

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

#include <Misc.au3>

#include <File.au3>

WinWaitActive ( "Untitled" )

While WinExists ("Untitled") = 1

If _IsPressed('30') = 1 Then

;Sleep(700)

If FileExists("timer.ini") Then

FileWrite("timer.ini", "0")

FileClose("timer.ini")

Else

_FileCreate("timer.ini")

;Sleep(700)

FileWrite("timer.ini", "0")

FileClose("timer.ini")

EndIf

EndIf

WEnd

without sleep it gives too many zeros.. for some unknown reason.. can someone explain.. also if the sleep isnt more then 700.. it does the same.

Edited by pingpong24
Link to comment
Share on other sites

  • Developers

The reason for your problem is that the If is true for the time you press the 0 key.

This logic will only execute the 0 logic one time when you press the 0 key.

#include <Misc.au3>
#include <File.au3>
Global $LastKey = 0
WinWaitActive("Untitled") 

While WinExists("Untitled") = 1
    
    If _IsPressed ('30') Then 
       ;Sleep(700)
        If $LastKey = 0 Then 
            FileWrite("timer.ini", "0")
        EndIf
        $LastKey = 30
    Else
        $LastKey = 0        
    EndIf
WEnd

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

why filewrite to an ini, and not use iniwrite?

IniWrite applies a specific format to the data written to the INI file, IniRead expects the same specific format in an INI file. He apparently wants the 'timer.ini' file with no internal format and a '0' on the first line. Of course he may or may not use the standard format in later operations.

[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

Link to comment
Share on other sites

The reason for your problem is that the If is true for the time you press the 0 key.

This logic will only execute the 0 logic one time when you press the 0 key.

#include <Misc.au3>
#include <File.au3>
Global $LastKey = 0
WinWaitActive("Untitled") 

While WinExists("Untitled") = 1
    
    If _IsPressed ('30') Then 
      ;Sleep(700)
        If $LastKey = 0 Then 
            FileWrite("timer.ini", "0")
        EndIf
        $LastKey = 30
    Else
        $LastKey = 0        
    EndIf
WEnd
THANKS!! you helped me alot, the program is working fine now!! really appreate it.. though i wanted to make it all by my self without anyones help :P
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...