Sign in to follow this  
Followers 0
ameer

help with stringtrimleft

7 posts in this topic

what i want to do is get the name of currently connected network adapter. (exp ; "Wireless Network Connection" )

#Include <process.au3>

Global $GET = _GetNetName()
;MsgBox(0, "Result", "Network Name : " & $GET)


Func _GetNetName()
Dim $line = 4
;_RunDOS("netsh inter show interface > c:\connections.txt")
$variable = Run(@ComSpec & " /u /c " & 'netsh inter show interface > c:\connections.txt', @SystemDir, @SW_HIDE, 6) ; Same As $STDERR_CHILD + $STDOUT_CHILD
$Filepath = "C:\Connections.txt"
While 1
$text = FileReadLine($Filepath, $line)
If @error = -1 Then ExitLoop

If StringinStr($text, "Connected      Dedicated") Then MsgBox(0, "", StringTrimLeft($text, 47))


$line = $line + 1

WEnd

EndFunc

This however works perfectly, but how do i create a variable for that result?

I dont want the results in msgbox, i want it in variable, so i can call it later.

Thanks

Share this post


Link to post
Share on other sites



I didn't run your script, but if everything is working correctly, but you don't want the msgbox and want to have what you see in the message box into a var... its

If StringinStr($text, "Connected Dedicated") Then $myvar = StringTrimLeft($text, 47)
 
You should also exit the loop/function at that point, but its up to you.

While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

Share this post


Link to post
Share on other sites

I tried just like that earlier it wont work. It says need to declare, even if i dim $myvar, the result returns 0. Thanks someone

Share this post


Link to post
Share on other sites

I guess I'm not understanding what doesn't work for you. This works just fine for me:

#Include <process.au3>

Global $var, $GET = _GetNetName()
MsgBox(0, "", $var)


Func _GetNetName()
Dim $line = 4
$variable = Run(@ComSpec & " /u /c " & 'netsh inter show interface > c:\connections.txt', @SystemDir, @SW_HIDE, 6) ; Same As $STDERR_CHILD + $STDOUT_CHILD

$Filepath = "C:\Connections.txt"

While 1
$text = FileReadLine($Filepath, $line)
    If @error = -1 Then ExitLoop

    If StringinStr($text, "Connected      Dedicated") Then
        $var = StringTrimLeft($text, 47)
        ExitLoop
    EndIf
$line = $line + 1
WEnd
EndFunc

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

maybe also >this could interest
(see lines 47-55 for a way to parse the output of netsh)


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

 

I guess I'm not understanding what doesn't work for you. This works just fine for me:

#Include <process.au3>

Global $var, $GET = _GetNetName()
MsgBox(0, "", $var)


Func _GetNetName()
Dim $line = 4
$variable = Run(@ComSpec & " /u /c " & 'netsh inter show interface > c:\connections.txt', @SystemDir, @SW_HIDE, 6) ; Same As $STDERR_CHILD + $STDOUT_CHILD

$Filepath = "C:\Connections.txt"

While 1
$text = FileReadLine($Filepath, $line)
    If @error = -1 Then ExitLoop

    If StringinStr($text, "Connected      Dedicated") Then
        $var = StringTrimLeft($text, 47)
        ExitLoop
    EndIf
$line = $line + 1
WEnd
EndFunc

Thanks JLogan3o13

I changed to

Global $var, $GET = _GetNetName()
MsgBox(0, "", $var)

and $var works like a charm.

Why it doesnt work before?

Chimp,I checked that out, and now i have better understanding, tks alot !!

Share this post


Link to post
Share on other sites

I am guessing you did not have the variable declared before entering the function. You have to either declare the variable outside the function using Global (if you need it to be used throughout your code), or declare the variable inside the Function as an temp variable, and return the value before exiting the function, like so:

#Include <process.au3>

Global $GET = _GetNetName()

Func _GetNetName()
Dim $line = 4
$variable = Run(@ComSpec & " /u /c " & 'netsh inter show interface > c:\connections.txt', @SystemDir, @SW_HIDE, 6) ; Same As $STDERR_CHILD + $STDOUT_CHILD

$Filepath = "C:\Connections.txt"

While 1
$text = FileReadLine($Filepath, $line)
    If @error = -1 Then ExitLoop

    If StringinStr($text, "Connected      Dedicated") Then
        Local $var = StringTrimLeft($text, 47)
            MsgBox(0, "", $var)
        ExitLoop
    EndIf
$line = $line + 1
WEnd
EndFunc

√-1 2^3 ∑ π, and it was delicious!

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