Sign in to follow this  
Followers 0
KurogamineNox

A little help with this if statement

16 posts in this topic

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

Share this post


Link to post
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

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

IsVisible was from the help file I think.

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

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


1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

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

Share this post


Link to post
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

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

I think that would work but i still had to fix my For Next Statement because that was what was ruining everything.

Share this post


Link to post
Share on other sites

I think that would work but i still had to fix my For Next Statement because that was what was ruining everything.

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

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
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.

Share this post


Link to post
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...

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

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

Yeah, I learned that the hard way.

Share this post


Link to post
Share on other sites

Yeah, I learned that the hard way.

We never learn from things we do correctly the first time.

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

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