Jump to content

A little help with this if statement


Recommended Posts

What can I add to this to make it that if no windows exist of "- Chat Window" then do a specific event.

;Only reads visible windows that have "- Chat Window" in its name
If $var[$i][0] <> "- Chat Window" AND IsVisible($var[$i][1]) Then
    $Text = ControlGetText($var[$i][0], "", "RichEdit20W1")
    $array = StringSplit($text,@lf)
EndIf
Link to comment
Share on other sites

What can I add to this to make it that if no windows exist of "- Chat Window" then do a specific event.

;Only reads visible windows that have "- Chat Window" in its name
If $var[$i][0] <> "- Chat Window" AND IsVisible($var[$i][1]) Then
    $Text = ControlGetText($var[$i][0], "", "RichEdit20W1")
    $array = StringSplit($text,@lf)
EndIf

Check your @error after the call to WinList() that's not in the segment you've provided
Link to comment
Share on other sites

My WinList() is

$var = WinList("- Chat Window")

How would I set the @error?

I am looking at the help file though am I to use SetError or something? I really have no clue right now.

oops, winlist doesn't set error... just check

if ubound($var) = 1 ;no results

***edit*** changed my variable name to match yours

Edited by cameronsdad
Link to comment
Share on other sites

If I understand you correctly, this would work...I am not familiar with IsVisible. Is this your own function?

Opt('WinTitleMatchMode', 4)
$Var = WinList("[REGEXPTITLE:(?i)- Chat Window]")
If $Var[0][0] = 0 Then
    ;No Windows with "- Chat Window" exists...Do Your Stuff Here
Else
    For $i = 1 To $Var[0]
        If Not BitAND(WinGetState($Var[$i][1]), 2) Then ContinueLoop ;If Not Visible, go to Next Window Occurence
        $Text = ControlGetText($Var[$i][0], "", "RichEdit20W1")
        $Array = StringSplit($Text, @LF)
    Next
EndIf
Link to comment
Share on other sites

IsVisible was from the help file I think.

Okay, after frustraighting through all this work to figure out what is going on with the no window stuff. Aparently if there is no windows everything inside

For $i = 1 To $var[0][0]

Does not activate.

After experimenting again. Its kind of wierd but I had to move everything to the bottom of the While 1 section. For it to work properly of reading text and executing them they had to be inside that for command, but it would glitch if there was no windows. I moved the for down to the bottom of the While 1 section and added the ones that would read text from windows into the for section, Which made it work

For $i = 1 To $var[0][0]
        ; Only display visble windows that have a title
        If $var[$i][0] <> "- Chat Window" And IsVisible($var[$i][1]) Then
            ;MsgBox(0, "Details", "Title=" & $var[$i][0] & @LF & "Handle=" & $var[$i][1])
            $Text = ControlGetText($var[$i][0], "", "RichEdit20W1")
            $array = StringSplit($Text, @LF)
        EndIf

        If $array[0] > 1 Then
            $lastline = $array[$array[0]]
        Else
            $lastline = $array[1]
        EndIf

        Select
            Case StringInStr($lastline, $Nickname);You activate a command
                _DoSomething($lastline)
            Case Not StringInStr($lastline, $Nickname);Client sends you a command
                _DoSomething2($lastline)
        EndSelect
    Next

And of course if there are no windows everything in that for loop does nothing so in the While 1 this still exists since I still have to set the variables. Cant set variables if the for isnt called so this stays in the While 1 above the For section.

$lastline = ""
$Text = ""
$array = StringSplit($Text, @LF)

Any thoughts on why(if what I typed was not confusing) This happened?

Link to comment
Share on other sites

did you see my last post about checking Ubound($var) = 1?

Yes, it did not work because of the For Statement. When ever there was no window everything with in the For next statement got disabled. Its fixed now that I set everything in the right places but I dont know why everything in the for next statement got disabled when no windows were there. Both codings could have probably worked if I had my For Next statement in the right places(which I just noticed) but I already have it fixed in my way. I just still dont know about why it disabled everything in the for next statement.

Edited by KurogamineNox
Link to comment
Share on other sites

Yes, it did not work because of the For Statement. When ever there was no window everything with in the For next statement got disabled. Its fixed now that I set everything in the right places but I dont know why everything in the for next statement got disabled when no windows were there. Both codings could have probably worked if I had my For Next statement in the right places(which I just noticed) but I already have it fixed in my way. I just still dont know about why it disabled everything in the for next statement.

ok... i meant...

If Ubound($var) <> 1 Then
;your loop
Else
;not found do something else
Endif
Link to comment
Share on other sites

your For loop would not run if no matching windows were found, so it wouldn't ruin anything...

It ruined my coding because I had everything basically inside it, which kept causing my program to not function properly when there where no windows. All the coding had to be moved and put the for next statement under it and only have the code needed for that statement inside it.

Link to comment
Share on other sites

It ruined my coding because I had everything basically inside it, which kept causing my program to not function properly when there where no windows. All the coding had to be moved and put the for next statement under it and only have the code needed for that statement inside it.

Only loop what needs to be looped, and only run the loop when the conditions are right, everything else can be outside of the if, but within the while...
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...