Queener Posted May 15, 2013 Share Posted May 15, 2013 (edited) 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 May 15, 2013 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 More sharing options...
Moderators JLogan3o13 Posted May 15, 2013 Moderators Share Posted May 15, 2013 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 More sharing options...
Queener Posted May 15, 2013 Author Share Posted May 15, 2013 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 More sharing options...
Moderators JLogan3o13 Posted May 15, 2013 Moderators Share Posted May 15, 2013 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 More sharing options...
Queener Posted May 15, 2013 Author Share Posted May 15, 2013 (edited) 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 May 15, 2013 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 More sharing options...
Moderators Solution JLogan3o13 Posted May 15, 2013 Moderators Solution Share Posted May 15, 2013 (edited) 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 May 15, 2013 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 More sharing options...
Moderators JLogan3o13 Posted May 15, 2013 Moderators Share Posted May 15, 2013 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 More sharing options...
Queener Posted May 15, 2013 Author Share Posted May 15, 2013 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 More sharing options...
nassarfateen37 Posted May 15, 2013 Share Posted May 15, 2013 Right on. Thanks a lot on such a helpful guideline. ________________ Physician Billing Company Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now