Sign in to follow this  
Followers 0
Kiesp

Problem with fileread

4 posts in this topic

My problem is when i add a line to my list using my gui it wont read that line until i restart my script.. any ideas how to fix it ?

sry that im not describing very good.. but my mom is annying saying: " I WANT THE NET NOW!!!! ROOOOAR!! FEEEL MY WRATH!!" (she is very annoying :s)

#include <file.au3>
if not FileExists("film.ini") Then
    FileInstall("film.ini","film.ini")
EndIf
$fn = "film.ini"
$file = fileopen($fn,0)
$noline = _FileCountLines("film.ini")
$content = FileReadLine($file)
GUICreate("Film index")
$winsize = WinGetClientSize("Film index")
;$sog =GUICtrlCreateInput("",5,10,100,20)
;$sogbtn = GUICtrlCreateButton("Søg",110,9,50,20)
$list = GUICtrlCreateList("",5,50,$winsize[0] -10,$winsize[1] -100)
$add = GUICtrlCreateinput("",10,370,100,20)
$addbtn = GUICtrlCreateButton("Tilføj",120,370,50,20)
GUICtrlCreateGroup("",325,370,75,27)
$counter = GUICtrlCreateLabel("Antal film:",330,380,65,15)
for $i = 1 to $noline
GUICtrlSetData($list,$content)
$content = FileReadLine($file)
Next
GUICtrlSetData($counter,"Antal film:" & $noline - 30)
GUISetState()

while 1
    $msg = GUIGetMsg()
    Select
        case $msg = -3
            fileclose($file)
            Exit
        case $msg = $addbtn
            $addnavn = GUICtrlRead($add)
            $file = FileOpen($fn,1)
            FileWrite($file,$addnavn & @CRLF)
            FileClose($fn)
            GUICtrlDelete($list)
            $file = FileOpen($fn,0)
            $noline = _FileCountLines("film.ini")
            for $i = 0 to $noline
            GUICtrlSetData($list,$content)
            $content = FileReadLine($file)
            Next
    EndSelect
    sleep(1)
WEnd

http://www.autoitscript.com/forum/index.php?showtopic=69911 <-- Best hacker ever :D

Share this post


Link to post
Share on other sites



a few problems

1 you should not use an "ini" file with repeated fileread() useage

2 Lists have taken on new controls

3 set the name of the file at the begining of the script

#include <file.au3>
#include <GuiList.au3>


Global $filename = @ScriptDir & "\film.txt"
Global $aRecords

; for testing
if not FileExists($filename) Then FileWriteLine($filename, "Grease" )

if not FileExists($filename) Then
    FileInstall("film.txt",$filename)
EndIf

GUICreate("Film index")
$winsize = WinGetClientSize("Film index")
;$sog =GUICtrlCreateInput("",5,10,100,20)
;$sogbtn = GUICtrlCreateButton("Søg",110,9,50,20)
$list = GUICtrlCreateList("",5,50, $winsize[0] -10,$winsize[1] -100)
$add = GUICtrlCreateinput("",10,370,100,20)
$addbtn = GUICtrlCreateButton("Tilføj",120,370,50,20)
GUICtrlCreateGroup("",325,370,75,27)
$counter = GUICtrlCreateLabel("Antal film:",330,380,65,15)

Set_List()

GUICtrlSetData($counter,"Antal film:" & $aRecords[0] - 30)
GUISetState()

while 1
    $msg = GUIGetMsg()
    Select
        case $msg = -3
            Exit
        case $msg = $addbtn
            $addnavn = GUICtrlRead($add)
            If $addnavn = "" Then ContinueLoop
            FileWriteLine($filename,$addnavn)
            Set_List()
            GUICtrlSetData($counter,"Antal film:" & $aRecords[0] - 30)
    EndSelect
    sleep(1)
WEnd


Func Set_List()
    Dim $aRecords
    GUICtrlSetData($list, "")
If Not _FileReadToArray($filename,$aRecords) Then
   MsgBox(4096,"Error", " Error reading log to Array     error:" & @error)
   Exit
EndIf
For $x = 1 to $aRecords[0]
    
   If $aRecords <> "" Then _GUICtrlListAddItem ( $list, $aRecords[$x] )
    
Next
    
EndFunc

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

My problem is when i add a line to my list using my gui it wont read that line until i restart my script.. any ideas how to fix it ?

sry that im not describing very good.. but my mom is annying saying: " I WANT THE NET NOW!!!! ROOOOAR!! FEEEL MY WRATH!!" (she is very annoying :s)

First things first... Do what your Mom tells you! :)

Now, on to lesser things...

If the data is, or can be, formatted as a real INI file then you could make the whole thing simpler and easier by learning to use the IniRead() and IniWrite() functions in AutoIt. Having to open files, count lines, loop through file reads, etc. is all pretty silly when you have much more powerful tools available.

Can you post an example of the film.ini file contents?

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

a few problems

1 you should not use an "ini" file with repeated fileread() useage

2 Lists have taken on new controls

3 set the name of the file at the begining of the script

ok... i listen and learn ^^ but just some questions to ur answers (just so i can learn more about autoit :))

1. why cant i use an ini file ?

2. what do u mean with that? are u refering to the function u added ?

3. i dont know why i didnt set the name at the start.. :) i see now that not doing it is pretty dumb :P

and then i have a fourth question.. why is it that u use global/dim to declare something ? i normally just use "$variable = '' " is there any difference ?

First things first... Do what your Mom tells you! huh.gif

Now, on to lesser things...

If the data is, or can be, formatted as a real INI file then you could make the whole thing simpler and easier by learning to use the IniRead() and IniWrite() functions in AutoIt. Having to open files, count lines, loop through file reads, etc. is all pretty silly when you have much more powerful tools available.

Can you post an example of the film.ini file contents?

I did do what my mom told me to.. dont worry ^^

and about the ini file.. i could post it but it just contains 279 names of movies my mom got.. and they are not formatted as a real ini file.. i just used the ini file so my mom wouldnt accidentally open up the file containing all the names and mess up somthing..

Edited by Kiesp

http://www.autoitscript.com/forum/index.php?showtopic=69911 <-- Best hacker ever :D

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
Sign in to follow this  
Followers 0