Jump to content

Read 2 times from file will fail


Jack023
 Share

Recommended Posts

Hey all,

Iam making a gui atm and made a function

At the moment on my mobile phone but just some help would be fine , no coding needed.

Let's say i have a label in a gui called : $label1 = "label1"

And a button called $buton1

I have a function what reads from a site, filewrite to a txt file on desktop, fileopen("thefile on the desktop")

$test = Filereadline(..., 2)

Then i do this to change the label1

Guictrlsetdata($label1, $test)

Filedelete("thefile on the desktop)

Endfunc

So right now when i click the button it will change the label1 to the $test, this works

When i press the button again it will make it empty , just nothing inside the label.

But why?

Link to comment
Share on other sites

Not enough information for me, but maybe you readfile again and so $test bcomes an empty string?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

This line "Filedelete("thefile on the desktop)" might have something to do with it, seeing as how you delete the file when you run the script, there's nothing there for the script to read from the second time. Unless you're reading from the site and recreating the file, which isn't clear from your lack of posted code.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Alright I'm home

This is the label that i want to change:

$Label2 = GUICtrlCreateLabel("15Ja16.75)", 184, 32, 100, 20)

then my gui $button code looks like this:

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            _PayoutDate()
    EndSwitch
WEnd

then as final the functionm: _PayoutDate()

Func _PayoutDate()
    $PaymentDay = "http:/www.site.com"
    $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
    $oHTTP.Open("GET", $PaymentDay, 0)
    $oHTTP.Send()
    $txt = $oHTTP.Responsetext
    FileWrite("payout.txt", $txt)
    $payoutopen = FileOpen("payout.txt")
    $dateline = FileReadLine($payoutopen, "2")
    $amountline = FileReadLine($payoutopen, "3")
    $strip = _StringStripChars($dateline, '{":"},')
    $strip2 = _StringStripChars($amountline, '{":"},')
    $trim = StringTrimLeft($strip, 9)
    $trim2 = StringTrimLeft($strip2, 11)
    GUICtrlSetData($Label2, $trim & "  ($" & $trim2 & ")")
    FileDelete("payout.txt")
EndFunc

As i told before, 

I want change $label2 to the data of $trim & " ($" & $trim2 & ")"

When i click the button at first time it works,

Change to the good value,

When i click the button again it will make the data nothing just  " " <-- like this without the "marks

 

When i stop the GUI and restart it and press the button then it will work.

and when i press it again - same problem as i explained before

Any solution?

Edited by Jack023
Link to comment
Share on other sites

It looks like that it won't delete the text file while the GUI is openend.. 

UPDATE:

New code:

Func _PayoutDate()
    $PaymentDay = "http://www.site.com"
    $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
    $oHTTP.Open("GET", $PaymentDay, 0)
    $oHTTP.Send()
    $txt = $oHTTP.Responsetext
    FileWrite("payout.txt", $txt)
    $payoutopen = FileOpen("payout.txt")
    $dateline = FileReadLine($payoutopen, "2")
    $amountline = FileReadLine($payoutopen, "3")
    $strip = _StringStripChars($dateline, '{":"},')
    $strip2 = _StringStripChars($amountline, '{":"},')
    FileClose($payoutopen)
    FileDelete($payoutopen)
    $trim = StringTrimLeft($strip, 9)
    $trim2 = StringTrimLeft($strip2, 11)
    GUICtrlSetData($Label2, $trim & "  ($" & $trim2 & ")")
EndFunc

Still not working :(

Edited by Jack023
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...