Jump to content
Sign in to follow this  
MariusN

_StringBetween maybe not the correct function?

Recommended Posts

MariusN

Where am i going wrong?

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <String.au3>

Opt("MustDeclareVars", 1)

Local $gui, $MSG, $test, $string, $send, $read, $test2, $menu6,$data,$data2,$data3
$gui = GUICreate("Bandwidth Monitor", 355, 250)

$test = GUICtrlCreateButton('Test', 40, 60, 80, 20, $BS_DEFPUSHBUTTON)

GUISetState()

While 1
    $MSG = GUIGetMsg()
    Select
        Case $MSG = $GUI_EVENT_CLOSE
            FileDelete(@WindowsDir & "\burn.ico")
            ExitLoop
        Case $MSG = $test
            status()

    EndSelect
WEnd

Func Status()
    Global $h_gui, $i_edit, $h_edit
    Global $s_stdout, $i_pid, $i_timer
    Global $s_ip = @IPAddress1
    Global $i_sec = 1

    $h_gui = GUICreate("Current Connections on  IP: " & $s_ip, 540, 400, -1, 20)
    $i_edit = GUICtrlCreateEdit("", 10, 10, 520, 380)
    GUISetState()
    $h_edit = GUICtrlGetHandle($i_edit)
    $i_timer = TimerInit()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch

        If TimerDiff($i_timer) / 1000 >= $i_sec 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
                WinSetState($h_edit, "", @SW_LOCK)
                GUICtrlSetData($i_edit, "")
                $data = GUICtrlSetData($i_edit, $s_stdout)
                $data2 = GUICtrlRead($i_edit,1)
                $data3 = _StringBetween($data2, "Bytes", "Unicast packets",-1); <---here lies my prob
                MsgBox(0,"",$data2); <---here is a test that ahows "$data2" is correct
MsgBox(0,"",$data3); <--- Shows an empty box
                WinSetState($h_edit, "", @SW_UNLOCK)
            EndIf
            $s_stdout = ""
            $i_timer = TimerInit()
        EndIf
    WEnd
    GUIDelete()
EndFunc

If you look above, i am trying to get ONLY the figures between the "Bytes" and "Unicast packets"...this is the SEND and RECEIVING bytes...maybe i'm using the _StringBetween wrong?

Edited by MariusN

Share this post


Link to post
Share on other sites
PsaltyDS

The function _StringBetween() returns and array. Use _ArrayDisplay() instead of MsgBox() to check it out.

:mellow:


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
jchd

What does your string look like?


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
MariusN

The function _StringBetween() returns and array. Use _ArrayDisplay() instead of MsgBox() to check it out.

:mellow:

will do thx PsaltyDS...Just for interest sakes, i saw this in another thread

$MIB_TCPSTATS=DllStructCreate("dword[15]")
DllCall("Iphlpapi.dll","int","GetTcpStatistics","ptr",DllStructGetPtr($MIB_TCPSTATS))

$sent=DllStructGetData($MIB_TCPSTATS,1,11) ; dwOutSegs
$resent=DllStructGetData($MIB_TCPSTATS,1,10) ;dwRetransSegs

MsgBox(0,"Total uploaded",$sent&" packets.")
MsgBox(0,"Total Downloaded",$resent&" packets.")

(ok, ive played around with the 1,11 and 1,10)

It seems so easy...Is there any site you could recomment where i could get more info on the "DllStructCreate, etc" stuff? I'm very unfimmiliar with this :(

Share this post


Link to post
Share on other sites
PsaltyDS

Start from the help file of course, then start checking out how the DLL calls are done in the various UDFs. For example, the _WinAPI_* functions.

:mellow:


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

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  

×