Jump to content

filewrite


Recommended Posts

hii

i am new here...

i have problem with my program

i didn't finish the program but the depositing need to work...

he read the number but he dont write it on the txt...

#include <GUIConstantsEx.au3>


$file1 = fileopen("userinfo.txt")


$numt = 1
GUICreate("user panel", 400, 400)
GUISetState()



$radiod = GUICtrlCreateRadio("depositing", 160, 200, 80, 20)
$radiop = GUICtrlCreateRadio("", 160, 220, 80, 20)
$input = GUICtrlCreateInput("the sum...", 160, 240, 80, 20)
$go = GUICtrlCreateButton("go", 180, 300, 40, 30)
$readf = FileReadLine($file1, 1)
$label = GUICtrlCreateLabel("welcome to Bank User Panel System" &@CRLF&@CRLF& "you bank status: "& $readf &@CRLF& "your loan status: " &@CRLF& "in total: " &@CRLF, 100, 50, 200, 100)
While 1
    
    
    
    
    
    $msg = GUIGetMsg()
    Select
        case $msg = $GUI_EVENT_CLOSE 
            exit        
        case $msg = $go
            $file1 = fileopen("userinfo.txt"); open the file in reading status
            $readd = GUICtrlRead($radiod); read the radio
            $readp = GUICtrlRead($radiop)
            if $readd == $GUI_CHECKED Then ; if the depositing is checked so:
                $readi = GUICtrlRead($input) ; he read the number in the input
                $readf = FileReadLine($file1, 1); he read the number is already in the txt
                $Write = $readf+$readi;addition
                msgbox(0,"",$write); msgbox the sum
                $file1 = fileopen("userinfo.txt", 2); open the file in write erase mode
                FileWrite($file1, $Write);writing, this is the problem, in the writing...
                
                _refresh(); refresh the data in the panel
            EndIf
            
        
    EndSelect
    
WEnd

Func _refresh()
    $file1 = fileopen("userinfo.txt")
    $readf = FileReadLine($file1, 1)
    GUICtrlSetData($label,"welcome to Bank User Panel System" &@CRLF&@CRLF& "you bank status: "& $readf &@CRLF& "your loan status: " &@CRLF& "in total: " &@CRLF) 
EndFunc 

FileClose($file)

plz help

Link to comment
Share on other sites

he read the number but he dont write it on the txt...

Hello,

I think you should close the file before open it in another mode ;-). I also added $file1 as Global and in the last line your script was closing $file instead $file1 (I guess it was a typo).

I've tested below code and it seems to work:

#include <GUIConstantsEx.au3>


Global $file1 = fileopen("userinfo.txt")


$numt = 1
GUICreate("user panel", 400, 400)
GUISetState()



$radiod = GUICtrlCreateRadio("depositing", 160, 200, 80, 20)
$radiop = GUICtrlCreateRadio("", 160, 220, 80, 20)
$input = GUICtrlCreateInput("the sum...", 160, 240, 80, 20)
$go = GUICtrlCreateButton("go", 180, 300, 40, 30)
$readf = FileReadLine($file1, 1)
$label = GUICtrlCreateLabel("welcome to Bank User Panel System" &@CRLF&@CRLF& "you bank status: "& $readf &@CRLF& "your loan status: " &@CRLF& "in total: " &@CRLF, 100, 50, 200, 100)
While 1





    $msg = GUIGetMsg()
    Select
        case $msg = $GUI_EVENT_CLOSE
            exit
        case $msg = $go
            FileClose($file1)
            $file1 = fileopen("userinfo.txt"); open the file in reading status
            $readd = GUICtrlRead($radiod); read the radio
            $readp = GUICtrlRead($radiop)
            if $readd == $GUI_CHECKED Then ; if the depositing is checked so:
                $readi = GUICtrlRead($input) ; he read the number in the input
                $readf = FileReadLine($file1, 1); he read the number is already in the txt
                $Write = $readf+$readi;addition
                msgbox(0,"",$write); msgbox the sum
                FileClose($file1)
                $file1 = fileopen("userinfo.txt", 2); open the file in write erase mode
                FileWrite($file1, $Write);writing, this is the problem, in the writing...
                FileClose($file1)
                _refresh(); refresh the data in the panel
            EndIf


    EndSelect

WEnd

Func _refresh()
    $file1 = fileopen("userinfo.txt")
    $readf = FileReadLine($file1, 1)
    FileClose($file1)
    GUICtrlSetData($label,"welcome to Bank User Panel System" &@CRLF&@CRLF& "you bank status: "& $readf &@CRLF& "your loan status: " &@CRLF& "in total: " &@CRLF)
EndFunc

FileClose($file1)

Regards,

sahsanu

Link to comment
Share on other sites

Made a few changes that should point you in the right direction.

#include <GUIConstantsEx.au3>
;
Global $file1 = FileOpen(@ScriptDir & "\userinfo.txt", 1); <-- Same folder as script or executable and open for write
Global $readf, $label; <-- Need to declare function variables
$numt = 1; <-- Not Used?
;
$GUI0 = GUICreate("user panel", 400, 400)
$radiod = GUICtrlCreateRadio("depositing", 160, 200, 80, 20)
$radiop = GUICtrlCreateRadio("", 160, 220, 80, 20)
$input = GUICtrlCreateInput("the sum...", 160, 240, 80, 20)
$go = GUICtrlCreateButton("go", 180, 300, 40, 30)
$readf = FileReadLine($file1, 1)
$label = GUICtrlCreateLabel("welcome to Bank User Panel System" & @CRLF & @CRLF & "you bank status: " & $readf & @CRLF & "your loan status: " & @CRLF & "in total: " & @CRLF, 100, 50, 200, 100)
GUISetState(@SW_SHOW, $GUI0)
;
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $go
            ;$file1 = FileOpen("userinfo.txt"); <--- File is already open!
            $readd = GUICtrlRead($radiod); read the radio
            $readp = GUICtrlRead($radiop)
            If $readd == $GUI_CHECKED Then ; if the depositing is checked so:
                $readi = GUICtrlRead($input) ; he read the number in the input
                $readf = FileReadLine($file1, 1); he read the number is already in the txt
                $Write = $readf + $readi;addition
                MsgBox(0, "", $Write); msgbox the sum
                ;$file1 = FileOpen("userinfo.txt", 2); <--- File is already open!
                FileWrite($file1, $Write);writing, this is the problem, in the writing...
                _refresh(); refresh the data in the panel
            EndIf
    EndSwitch
WEnd
FileClose($file1)
GUIDelete($GUI0)
Exit
;
Func _refresh()
    ;$file1 = FileOpen("userinfo.txt") <-- File is already open!
    $readf = FileReadLine($file1, 1)
    GUICtrlSetData($label, "welcome to Bank User Panel System" & @CRLF & @CRLF & "you bank status: " & $readf & @CRLF & "your loan status: " & @CRLF & "in total: " & @CRLF)
EndFunc
;
Edited by ripdad

"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

Welcome DrDrOn,

While sahsanu may have a working script, I did see some basic error checking and code cleanup needed. For instance is using FileReadLine() and not checking the file handle returned from FileOpen() seems useless when you can just use FileReadLine() without FileOpen() and it will open, read the line and close the file in one function call. The rest was code cleanup with comments added starting with ;***.

#include <GUIConstantsEx.au3>

;* this is your info file. Once named and never changed
Const $file_userinfo = "userinfo.txt"
;* i guess you have your reason for $numt
$numt = 1

GUICreate("user panel", 400, 400)
$radiod = GUICtrlCreateRadio("depositing", 160, 200, 80, 20)
$radiop = GUICtrlCreateRadio("", 160, 220, 80, 20)
$input = GUICtrlCreateInput("the sum...", 160, 240, 80, 20)
$go = GUICtrlCreateButton("go", 180, 300, 40, 30)
$label = GUICtrlCreateLabel("", 100, 50, 200, 100)
;*** read file and set data to $label handle used above
_refresh()
GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            GUIDelete();*** optional cleanup call
            Exit
        Case $msg = $go
            $readd = GUICtrlRead($radiod); read the radio
            $readp = GUICtrlRead($radiop)
            If $readd = $GUI_CHECKED Then ; if the depositing is checked so:
                $readi = GUICtrlRead($input) ; he read the number in the input
                $readf = FileReadLine($file_userinfo); he read the number is already in the txt
                ;*** if $readf contains "" or 0 then skip block of code as unrequired to do otherwise
                If $readf Then
                    $file1 = FileOpen($file_userinfo, 2); open the file in write erase mode
                    ;*** check the file handle if valid to use
                    If $file1 = -1 Then
                        ;*** show error message some how that unable to open handle to write
                    Else
                        $Write = $readf + $readi; addition
                        MsgBox(0, "", $Write); msgbox the sum
                        FileWrite($file1, $Write); writing, this is the problem, in the writing...
                        FileClose($file1)
                        _refresh(); refresh the data in the panel
                    EndIf
                EndIf
            EndIf
    EndSelect
WEnd

Func _refresh()
    $readf = FileReadLine($file_userinfo)
    GUICtrlSetData($label, "welcome to Bank User Panel System" & @CRLF _
            & @CRLF _
            & "you bank status: " & $readf & @CRLF _
            & "your loan status: " & @CRLF _
            & "in total: " & @CRLF)
EndFunc

:(

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