Jump to content

_FileWriteToLine not taking variable


Recommended Posts

1st code:

This one works

$tester = _FileWriteToLine(@ScriptDir & "\netstat.log", 2, "123", 1)

2nd code

This one DOESNT work

$tester = _FileWriteToLine($fileLog, 2, $rnd3, 1)

My "checkers" so to speak

These codes below returns the value 100%

MsgBox(0,"",$fileLog); <---these 2 Boxes are placed DIRECTLY BELOW the 2nd code...
MsgBox(0,"",$rnd3)

Is there something i'm missing as it seems that the FIRST code (without the variables) works, but as soon as i replace it with $fileLog or $rnd3 (as can be seen in the 2nd code) it doesnt work...Can someone maybe explain me whats wrong?

#include <File.au3> IS in the header...

Edited by MariusN
Link to comment
Share on other sites

Hi,

we can't debug your 2nd code. How are the variables $fileLog and $rnd3 declared?

Post more code.

;-))

Stefan

@Edit This fails, if file is empty. If not it works perfect, if you want line 2 to be overwritten:

#include <file.au3>
$fileLog = @ScriptDir & "\test.log"
$rnd3 = "Some text"
$tester = _FileWriteToLine($fileLog, 2, $rnd3, 1)
ShellExecute ("notepad.exe", $fileLog)
Edited by 99ojo
Link to comment
Share on other sites

  • Moderators

MariusN,

What exactly is in the $fileLog variable when you test it? Does it include the full path? :mellow:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hi,

we can't debug your 2nd code. How are the variables $fileLog and $rnd3 declared?

Post more code.

;-))

Stefan

@Edit This fails, if file is empty. If not it works perfect:

#include <file.au3>
$fileLog = @ScriptDir & "\test.log"
$rnd3 = "Some text"
$tester = _FileWriteToLine($fileLog, 2, $rnd3, 1)
ShellExecute ("notepad.exe", $fileLog)

What boggles my brain is the fact that the "messageboxes" displays the correct info...know what i mean?

The code is still VERY sloppy as i'm still in the beginning stadges of this program so obviously there will be bugs, but here goes...my complete code so far...

#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <File.au3>

Opt('MustDeclareVars', 1)
Opt("TrayMenuMode", 3)


Global $h_gui, $i_edit, $h_edit, $receive, $send, $fileLog, $fileLog2, $open1, $i_timer2, $MSG, $view, $var3, $open4, $open5, $read3
Global $s_stdout, $i_pid, $i_timer, $i_edit2, $var1, $var2, $rnd1, $rnd2, $exititem, $log, $open2, $open3, $read1, $read2, $rnd3
Global $s_ip = @IPAddress1
Global $i_sec = 1
Global $tester
$fileLog = (@ScriptDir & "\netstat.log")
If FileExists(@ScriptDir & "\netstat.log") Then ;will keep CURRENT + HISTORY (netstat.log) bytes added together
Else
    _FileCreate(@ScriptDir & "\netstat.log")
EndIf
$fileLog2 = (@SystemDir & "\netbackup.txt")
If FileExists(@SystemDir & "\netbackup.txt") Then ;Backs-Up bytes in netstat.log
Else
    _FileCreate(@SystemDir & "\netbackup.txt")
EndIf

$view = TrayCreateItem("View Live Feed")
$log = TrayCreateItem("View Log")
$exititem = TrayCreateItem("Exit")



Func _Start()

    GUICreate("Network Monitor on  IP: " & $s_ip, 250, 150, -1, 20)
    GUICtrlCreateLabel("Receive: (Mb)", 20, 30, 120, 20)
    GUICtrlCreateLabel("Send: (Mb)", 130, 30, 120, 20)
    GUICtrlCreateLabel("Total: (Mb)", 90, 80, 120, 20)
    $i_edit = GUICtrlCreateLabel("", 20, 50, 200, 20, $SS_SUNKEN)
    $i_edit2 = GUICtrlCreateLabel("", 70, 100, 100, 20, $SS_SUNKEN)


    GUISetState()
    $h_edit = GUICtrlGetHandle($i_edit)
    $i_timer = TimerInit()

    While 1
        $MSG = GUIGetMsg()
        Select
            Case $MSG = $GUI_EVENT_CLOSE
                ExitLoop
        EndSelect

        If TimerDiff($i_timer) / 1000 > 1 Then
            $i_pid = Run(@ComSpec & " /c netstat -e", @SystemDir, @SW_HIDE, 6)
            While 1
                $s_stdout &= StdoutRead($i_pid)
                If @error Then ExitLoop
            WEnd
            If $s_stdout Then
                $receive = StringMid($s_stdout, 100, 17)
                $send = StringMid($s_stdout, 115, 17)

                WinSetState($h_edit, "", @SW_LOCK)
                GUICtrlSetData($i_edit, "")
                $var1 = $receive / 1048576
                $rnd1 = Round($var1, 3)
                $var2 = $send / 1048576
                $rnd2 = Round($var2, 3)
                $rnd3 = $rnd1 + $rnd2
                GUICtrlSetData($i_edit, "    " & $rnd1 & "                         " & $rnd2)
                GUICtrlSetData($i_edit2, "    " & $rnd3);$rnd1 + $rnd2)
                WinSetState($h_edit, "", @SW_UNLOCK)
                $open1 = FileOpen($fileLog, 2)
                FileWrite($fileLog, $rnd1 + $rnd2 & @CRLF)
                FileClose($open1)
            EndIf
            $s_stdout = ""
            $i_timer = TimerInit()
        EndIf
    WEnd
    GUIDelete()
EndFunc   ;==>_Start

Func _log()
    $i_pid = Run(@ComSpec & " /c netstat -e", @SystemDir, @SW_HIDE, 6)
    While 1
        $s_stdout &= StdoutRead($i_pid)
        If @error Then ExitLoop
    WEnd
    If $s_stdout Then
        $receive = StringMid($s_stdout, 100, 17)
        $send = StringMid($s_stdout, 115, 17)

        WinSetState($h_edit, "", @SW_LOCK)
        GUICtrlSetData($i_edit, "")
        $var1 = $receive / 1048576
        $rnd1 = Round($var1, 3)
        $var2 = $send / 1048576
        $rnd2 = Round($var2, 3)
        $rnd3 = $rnd1 + $rnd2
        GUICtrlSetData($i_edit, "    " & $rnd1 & "                         " & $rnd2)
        GUICtrlSetData($i_edit2, "    " & $rnd3);$rnd1 + $rnd2)
        WinSetState($h_edit, "", @SW_UNLOCK)
        $open1 = FileOpen($fileLog, 2)
        FileWrite($fileLog, $rnd1 + $rnd2 & @CRLF)
        FileClose($open1)
    EndIf
EndFunc   ;==>_log

_tray()
Func _tray()
    TraySetState()
    While 1
        $MSG = TrayGetMsg()
        If TimerDiff($i_timer) / 1000 > 30 Then
            $i_pid = Run(@ComSpec & " /c netstat -e", @SystemDir, @SW_HIDE, 6)
            While 1
                $s_stdout &= StdoutRead($i_pid)
                If @error Then ExitLoop
            WEnd
            If $s_stdout Then
                $receive = StringMid($s_stdout, 100, 17)
                $send = StringMid($s_stdout, 115, 17)

                WinSetState($h_edit, "", @SW_LOCK)
                GUICtrlSetData($i_edit, "")
                $var1 = $receive / 1048576
                $rnd1 = Round($var1, 3)
                $var2 = $send / 1048576
                $rnd2 = Round($var2, 3)
                $rnd3 = $rnd1 + $rnd2
                GUICtrlSetData($i_edit, "    " & $rnd1 & "                         " & $rnd2)
                GUICtrlSetData($i_edit2, "    " & $rnd1 + $rnd2)
                WinSetState($h_edit, "", @SW_UNLOCK)
                _Replace()
            EndIf
            $s_stdout = ""
            $i_timer = TimerInit()
        EndIf
        Select
            Case $MSG = 0
                ContinueLoop
            Case $MSG = $view
                _Start()
            Case $MSG = $log
                _log()
                Sleep(10)
                Run("notepad.exe " & @ScriptDir & "\netstat.log")
            Case $MSG = $exititem
                Exit
        EndSelect
    WEnd
EndFunc   ;==>_tray

Func _Replace()
    $rnd3 = $rnd1 + $rnd2
    $open1 = FileOpen($fileLog, 2)
    FileWrite($fileLog, $rnd3 & @CRLF)
    FileClose($open1)

    $open2 = FileOpen($fileLog, 0)
    $read1 = FileReadLine($open2, 1)
    $read2 = FileReadLine($open2, 2)
    FileClose($open2)

    If $read1 <> "" Or $read1 > 0 Then
        FileOpen($fileLog,1)
        $tester = _FileWriteToLine($fileLog, 2, $rnd3, 1)<---Here is the prob!!!
        MsgBox(0,"",$fileLog)
        MsgBox(0,"",$rnd3)
        $open3 = FileOpen($fileLog2, 0)
        $read3 = FileReadLine($open3, 1)
        FileClose($open3)
        Sleep(20)

        If $read2 < $read3 Then
            $open4 = FileOpen($fileLog2, 2)
            FileWriteLine($fileLog2, $read2)

            FileClose($open4)
        Else
            $open5 = FileOpen($fileLog2, 2)
            FileWriteLine($fileLog2, $read1)
            FileClose($open5)
        EndIf
    EndIf

EndFunc

The TRAY and REPLACE section is my concern as its running in the background...the other stuff ill sort out later

Edited by MariusN
Link to comment
Share on other sites

Hi,

we can't debug your 2nd code. How are the variables $fileLog and $rnd3 declared?

Post more code.

;-))

Stefan

@Edit This fails, if file is empty. If not it works perfect, if you want line 2 to be overwritten:

#include <file.au3>
$fileLog = @ScriptDir & "\test.log"
$rnd3 = "Some text"
$tester = _FileWriteToLine($fileLog, 2, $rnd3, 1)
ShellExecute ("notepad.exe", $fileLog)

Seems this code of yours also doesnt want to work...so i guess ill check my pc and reinstall AutoIt :mellow: Edited by MariusN
Link to comment
Share on other sites

  • Moderators

MariusN,

It looks as if you are trying to open an already open file: :mellow:

FileOpen($fileLog,1)
$tester = _FileWriteToLine($fileLog, 2, $rnd3, 1)<---Here is the prob!!!
You open the file with FileOpen and then _FileWriteToLine finds that the file is locked. Did you check the return value of $tester?By the way, you are mixing up file names and file handles in your various FileWrite commands - you should only use one or the other. From the Help file for FileWrite:Note: Do not mix filehandles and filenames, i.e., don't FileOpen a file and then use a filename in this function. Either use filehandles or filenames in your routines, not both.You currently use:
$open1 = FileOpen($fileLog, 2)FileWrite($fileLog, $rnd3 & @CRLF)FileClose($open1)You should use one of these:

$open1 = FileOpen($fileLog, 2)
FileWrite($open1, $rnd3 & @CRLF)
FileClose($open1)

; or

FileWrite($fileLog, $rnd3 & @CRLF)

Of course, when you use the _FileWrite style commands, you must use a file name only.

Take care using any file commands and make sure you are using the correct syntax - it often catches you out! :(

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

MariusN,

It looks as if you are trying to open an already open file: :(

FileOpen($fileLog,1)
$tester = _FileWriteToLine($fileLog, 2, $rnd3, 1)<---Here is the prob!!!
You open the file with FileOpen and then _FileWriteToLine finds that the file is locked. Did you check the return value of $tester?By the way, you are mixing up file names and file handles in your various FileWrite commands - you should only use one or the other. From the Help file for FileWrite:Note: Do not mix filehandles and filenames, i.e., don't FileOpen a file and then use a filename in this function. Either use filehandles or filenames in your routines, not both.You currently use:
$open1 = FileOpen($fileLog, 2)FileWrite($fileLog, $rnd3 & @CRLF)FileClose($open1)You should use one of these:

$open1 = FileOpen($fileLog, 2)
FileWrite($open1, $rnd3 & @CRLF)
FileClose($open1)

; or

FileWrite($fileLog, $rnd3 & @CRLF)

Of course, when you use the _FileWrite style commands, you must use a file name only.

Take care using any file commands and make sure you are using the correct syntax - it often catches you out! :lol:

M23

Yes...the $filelog was only a test M23...

Btw, the above code posted by 99ojo also doesnt want to work...so i think i got some $%## going on on my pc :mellow:

I have uninstalled AND reinstalled AutIt + Scite, but to no avail...The thing i can think of is a corrupted <file.au3> or a background debugger im running (Syser Loader)

...but thanks for all the help guys...much appreciated...

PS: the reason for the code looking VERU UP RO Sh*t is because of all the different "styles" i tried to get this freakin "_FileWriteToLine" to work...

OOPS...my correction...You said a guy HAS to use a filename and NOT a VAR as a filename...

Edited by MariusN
Link to comment
Share on other sites

  • Moderators

MariusN,

What are you talking about? :mellow:_FileWriteToLine works perfectly well with variables. Run this:

#Include <File.au3>

$hFile = FileOpen(@ScriptDir & "\test.txt", 2)
FileWrite($hFile, "Line 1" & @CRLF & "Line 2" & @CRLF & "Line 3")
FileClose($hFile)

MsgBox(0, "Pause", "Go and read the file!")

_FileWriteToLine(@ScriptDir & "\test.txt", 1, "Replacing Line 1", 1)

MsgBox(0, "Pause", "Go and read the file!")

$sFilename = @ScriptDir & "\test.txt"
_FileWriteToLine($sFilename, 2, "Replacing Line 2", 1)

MsgBox(0, "Pause", "Go and read the file!")

$sText = "Replacing Line 3"
_FileWriteToLine($sFilename, 3, $stext, 1)

MsgBox(0, "Pause", "Go and read the file!")

I have told you what your problem is - you are trying to open an already open file. Go and put your various FileWrite and _FileWriteToLine commands in the corerct syntax and make sure you close the files if you have opened them. :(

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

MariusN,

What are you talking about? :mellow:_FileWriteToLine works perfectly well with variables. Run this:

#Include <File.au3>

$hFile = FileOpen(@ScriptDir & "\test.txt", 2)
FileWrite($hFile, "Line 1" & @CRLF & "Line 2" & @CRLF & "Line 3")
FileClose($hFile)

MsgBox(0, "Pause", "Go and read the file!")

_FileWriteToLine(@ScriptDir & "\test.txt", 1, "Replacing Line 1", 1)

MsgBox(0, "Pause", "Go and read the file!")

$sFilename = @ScriptDir & "\test.txt"
_FileWriteToLine($sFilename, 2, "Replacing Line 2", 1)

MsgBox(0, "Pause", "Go and read the file!")

$sText = "Replacing Line 3"
_FileWriteToLine($sFilename, 3, $stext, 1)

MsgBox(0, "Pause", "Go and read the file!")

I have told you what your problem is - you are trying to open an already open file. Go and put your various FileWrite and _FileWriteToLine commands in the corerct syntax and make sure you close the files if you have opened them. :(

M23

Okkkk....fair...Laugh your backsides off, LOL, but you wont believe this...I have done as you said BY THE LETTER...

This is what happens 2 me now...With this code (after fixing al the "open files and closing them neatly", the

""$tester = _FileWriteToLine(c:\myfile.txt, 2, $rnd3, 1)"" line won't accept the ""$rnd3"" entry....BUT, as soon as i ADD (""&) (the digits between the brackets) just in front of the ""$rnd3"" entry..., it works 100%....Now TRUELY i think i got some software probs...either my <File.au3> or something else...Thing is why i say this, is either something works, or not...not so?

Anyways M23...i really appreciate the help, but not 2 worry...i think my PC's software needs attention, as sometimes, believe it or not, if i'm IN Scite, clicking on a function, and then hit F1, nothing works...Then, if i move to ANOTHER function (lets say +- 2 or so line below and do the EXACT same thing), Scite will respond...Aint this weired???

but not 2 worry eh? nothing is "unrepairable" :lol:

Link to comment
Share on other sites

  • Moderators

MaruisN,

So show me the code now you have "fixed it" and I will take aother look. I very much doubt you have a corrupted AutoIt installation. :mellow:

M23

P.S. When you reply please use the "Add Reply" button at the top and bottom of the page rather then the "Reply" button in the post itself. That way you do not get the contents of the previous post quoted in your reply and the whole thread becomes easier to read.

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Ok M23...Now i want you to look ate the bottom of the code...thats what i cant figure out...It's working now with the ""& i have added just infront of $rnd3 (weird but true)

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=..\..\Icons\Aeon_Icon_Pack\Misc\Search.ico
#AutoIt3Wrapper_Outfile=BandMon.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <File.au3>

Opt('MustDeclareVars', 1)
Opt("TrayMenuMode", 3)


Global $h_gui, $i_edit, $h_edit, $receive, $send, $fileLog, $fileLog2, $open1, $i_timer2, $MSG, $view, $var3, $open4, $open5, $read3
Global $s_stdout, $i_pid, $i_timer, $i_edit2, $var1, $var2, $exititem, $log, $open2, $open3, $read1, $read2,$rnd1, $rnd2, $rnd3
Global $s_ip = @IPAddress1
Global $i_sec = 1
Global $tester
$rnd3 = $rnd1 + $rnd2
$fileLog = (@ScriptDir & "\netstat.log")
If FileExists(@ScriptDir & "\netstat.log") Then ;will keep CURRENT + HISTORY (netstat.log) bytes added together
Else
    _FileCreate(@ScriptDir & "\netstat.log")
EndIf
$fileLog2 = (@SystemDir & "\netbackup.txt")
If FileExists(@SystemDir & "\netbackup.txt") Then ;Backs-Up bytes in netstat.log
Else
    _FileCreate(@SystemDir & "\netbackup.txt")
EndIf

$view = TrayCreateItem("View Live Feed")
$log = TrayCreateItem("View Log")
$exititem = TrayCreateItem("Exit")



Func _Start()

    GUICreate("Network Monitor on  IP: " & $s_ip, 250, 150, -1, 20)
    GUICtrlCreateLabel("Receive: (Mb)", 20, 30, 120, 20)
    GUICtrlCreateLabel("Send: (Mb)", 130, 30, 120, 20)
    GUICtrlCreateLabel("Total: (Mb)", 90, 80, 120, 20)
    $i_edit = GUICtrlCreateLabel("", 20, 50, 200, 20, $SS_SUNKEN)
    $i_edit2 = GUICtrlCreateLabel("", 70, 100, 100, 20, $SS_SUNKEN)


    GUISetState()
    $h_edit = GUICtrlGetHandle($i_edit)
    $i_timer = TimerInit()

    While 1
        $MSG = GUIGetMsg()
        Select
            Case $MSG = $GUI_EVENT_CLOSE
                ExitLoop
        EndSelect

        If TimerDiff($i_timer) / 1000 > 1 Then
            $i_pid = Run(@ComSpec & " /c netstat -e", @SystemDir, @SW_HIDE, 6)
            While 1
                $s_stdout &= StdoutRead($i_pid)
                If @error Then ExitLoop
            WEnd
            If $s_stdout Then
                $receive = StringMid($s_stdout, 100, 17)
                $send = StringMid($s_stdout, 115, 17)

                WinSetState($h_edit, "", @SW_LOCK)
                GUICtrlSetData($i_edit, "")
                $var1 = $receive / 1048576
                $rnd1 = Round($var1, 3)
                $var2 = $send / 1048576
                $rnd2 = Round($var2, 3)
                GUICtrlSetData($i_edit, "    " & $rnd1 & "                         " & $rnd2)
                GUICtrlSetData($i_edit2, "    " & $rnd3);$rnd1 + $rnd2)
                WinSetState($h_edit, "", @SW_UNLOCK)
            EndIf
            $s_stdout = ""
            $i_timer = TimerInit()
        EndIf
    WEnd
    GUIDelete()
EndFunc   ;==>_Start

_tray()
Func _tray()
    TraySetState()
    While 1
        $MSG = TrayGetMsg()
        If TimerDiff($i_timer) / 1000 > 2 Then
            $i_pid = Run(@ComSpec & " /c netstat -e", @SystemDir, @SW_HIDE, 6)
            While 1
                $s_stdout &= StdoutRead($i_pid)
                If @error Then ExitLoop
            WEnd
            If $s_stdout Then
                $receive = StringMid($s_stdout, 100, 17)
                $send = StringMid($s_stdout, 115, 17)

                WinSetState($h_edit, "", @SW_LOCK)
                GUICtrlSetData($i_edit, "")
                $var1 = $receive / 1048576
                $rnd1 = Round($var1, 3)
                $var2 = $send / 1048576
                $rnd2 = Round($var2, 3)
                GUICtrlSetData($i_edit, "    " & $rnd1 & "                         " & $rnd2)
                GUICtrlSetData($i_edit2, "    " & $rnd1 + $rnd2)
                WinSetState($h_edit, "", @SW_UNLOCK)
                _Replace()
            EndIf
            $s_stdout = ""
            $i_timer = TimerInit()
        EndIf
        Select
            Case $MSG = 0
                ContinueLoop
            Case $MSG = $view
                _Start()
            Case $MSG = $log
                Run("notepad.exe " & @ScriptDir & "\netstat.log")
            Case $MSG = $exititem
                Exit
        EndSelect
    WEnd
EndFunc   ;==>_tray

Func _Replace()
    $rnd3 = $rnd1 + $rnd2
    $open2 = FileOpen($fileLog, 0)
    $read1 = FileReadLine($open2, 1)
    $read2 = FileReadLine($open2, 2)
    FileClose($open2)
    If $read1 <> "" Or $read1 > 0 Then
        _FileWriteToLine(@ScriptDir & "\netstat.log", 2, ""&$rnd3, 1);<---check the ""&
        $open3 = FileOpen($fileLog2, 0)
        $read3 = FileReadLine($open3, 1)
        FileClose($open3)
        Sleep(20)

        If $read2 < $read3 Then
            $open4 = FileOpen($fileLog2, 2)
            FileWriteLine($open4, $read2)
            FileClose($open4)
        Else
            $open5 = FileOpen($fileLog2, 2)
            FileWriteLine($open5, $read1)
            FileClose($open5)
        EndIf
    Else
        $open1 = FileOpen($fileLog, 1)
        FileWrite($open1, $rnd3 & @CRLF)
        FileClose($open1)


    EndIf
EndFunc   ;==>_Replace
Link to comment
Share on other sites

  • Moderators

MariusN,

Works for me both with and without the ""&. Must be magic! :(

Anyway, you have it working and that is the main thing. :mellow:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

you wont believe it, but this was driving me NUTS!

I'm still going to get to the bottom of this as it doesnt make sense, eh?

lol

Thx for your help anyways M23 :mellow:

PS: it still needs a hell of a lot of coding, calculations, etc....then youre going to watch this baby fly :(

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