Jump to content

wildcard with GUICTRLREAD label


Go to solution Solved by JLogan3o13,

Recommended Posts

I search a couple post, but those method are only for searching for files.

What I'm doing here is a little different. I want the button to prompt a message "This is a server PC!" if the label contain starting Text "CT".

Label will randomly change because Label is getting hostname by TCPIPTONAME.

This is what I got so far, but not working as expected:

If StringInStr($Label, "CT", 0, 1) Then
    MsgBox(0, "Test", "This is a Server PC, you cannot change its name!")
Else
    MsgBox(0,"", "End!")
EndIf
Edited by asianqueen

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Link to comment
Share on other sites

  • Moderators

Well, without your code it is a little difficult to follow, but if your label contains the text CT, you should be able to do a StringinStr.

If StringInStr(GUICtrlRead($label), "CT") Then MsgBox(0, "", "Blah blah")

"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

Should have bang my head against the wall.... I missed GUICTRLREAD.... it works now...

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Link to comment
Share on other sites

  • Moderators

Glad it is working for you. You can mark the post resolved yourself now, no need to change the title any longer.

"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

and this can be done as an array too?

I tried with

Local $keywords[2]
$keywords[0] = "CT"
$keywords[1] = "MIS"

For $i = 1 To $keywords
Next
If StringInStr(GUICtrlRead($Label), $keywords[$i]) Then
    MsgBox(0, "Test", "This is a Server PC, you cannot change its name!")

Else
    MsgBox(0,"", "End!")
EndIf

But Only CT is currently working. So if label display MissServer; it wouldn't even trigger the first message.

And if I put Next after Endif, It works, but I get two message.

Edited by asianqueen

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
Link to comment
Share on other sites

  • Moderators
  • Solution

Try something like this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Local $msg

GUICreate("Test", 300, 300)
$label = GUICtrlCreateLabel("CT", 10, 10, 50, 40)
$button = GUICtrlCreateButton("Go", 10, 70, 40, 40)

GUISetState(@SW_SHOW)

    While 1
        $msg = GUIGetMsg()
       Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $button
            Local $akeywords[2]
                $akeywords[0] = "CT"
                $akeywords[1] = "MIS"

                    Select
                       Case StringInStr(GUICtrlRead($label), $akeywords[0])
                    MsgBox(0, "", "CT Blah Blah")
                   Case StringInStr(GUICtrlRead($label), $akeywords[1])
                    MsgBox(0, "", "MIS Blah Blah")
                   Case Else
                    MsgBox(0, "", "End!")
                EndSelect

EndSelect WEnd GUIDelete()

Edit: Actually, that would give you the same results. Updated code

Edited by JLogan3o13

"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

  • Moderators

Ok, forum is really screwing me up when trying to edit a code block. THIS is what I meant:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Local $msg

GUICreate("Test", 300, 300)
$label = GUICtrlCreateLabel("CT", 10, 10, 50, 40)
$button = GUICtrlCreateButton("Go", 10, 70, 40, 40)

GUISetState(@SW_SHOW)

    While 1
        $msg = GUIGetMsg()
            Select
                Case $msg = $GUI_EVENT_CLOSE
                    ExitLoop
                Case $msg = $button
                    Local $akeywords[2]
                        $akeywords[0] = "CT"
                        $akeywords[1] = "MIS"

                        Select
                            Case StringInStr(GUICtrlRead($label), $akeywords[0])
                                MsgBox(0, "", "CT Blah Blah")
                            Case StringInStr(GUICtrlRead($label), $akeywords[1])
                                MsgBox(0, "", "MIS Blah Blah")
                            Case Else
                                MsgBox(0, "", "End!")
                        EndSelect
            EndSelect
    WEnd

GUIDelete()

"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

good idea. I finally know how the array are communicating... When I actually test

 
Local $keywords[2]
$keywords[0] = "CT"
$keywords[1] = "MIS"

 

The reason it gives me two msgbox prompt because it was comparing from input to 0 and then to 1. If I use elseif 0 then elseif 1; I would only get prompted once.

Msgbox(0, "Hate", "Just hate it when I post a question and find my own answer after a couple tries. But if I don't post the question, I can't seem to resolve it at all.")
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...