Jump to content

help with stringtrimleft


Recommended Posts

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

Link to comment
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
Link to comment
Share on other sites

  • Moderators

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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 !!
Link to comment
Share on other sites

  • Moderators

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

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