TheDcoder

Simple Problem, Can't find the answer

6 posts in this topic

#1 ·  Posted (edited)

Hello, Please look at the code:

; As always, this is a decoy script ;)

Global $sNum = Random(1, 4, 1) & "E"

Switch $sNum
    Case "1E" And "2E"
        MsgBox(64, "TEST", "1E or 2E")
    Case "3E" And "4E"
        MsgBox(64, "TEST", "3E or 4E")
EndSwitch

MsgBox(64, "TEST", "The number was: " & $sNum)

If $sNum = 1E or 2E it works, but when $sNum = 3E or 4E it shows the MsgBox for 1st Case

How can I get it to work?

Thanks In Advance

TD :)

Edited by TheDcoder

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites



Remove the "And"

 
Global $sNum = Random(1, 4, 1) & "E"
 
 
 
Switch $sNum
 
    Case "1E","2E"
 
        MsgBox(64, "TEST", "1E or 2E")
 
    Case "3E", "4E"
 
        MsgBox(64, "TEST", "3E or 4E")
 
EndSwitch
 
 
 
MsgBox(64, "TEST", "The number was: " & $sNum)
1 person likes this

NEWHeader1.png

Share this post


Link to post
Share on other sites

$sNum = 1E or 2E

You correctly describe what you want, but code something different.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanks Valuater :)

P.S Comma in programming languages?, thats something new for for me >_<

Edited by TheDcoder

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

Why new, have a look at the help file!


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

@water post-89462-0-42174900-1428428178.png


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

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

  • Similar Content

    • david1337
      By david1337
      Hey guys
      I hope that I can get a little help with this one
       
      In this GUI example using GUIListViewEx, I have a list based on items found in test.txt.
      _____________________________________________
      item1
      item2
      item3
      ____________________________________________
      etc....
       
      When an item is selected, and I click the GetInfo button, a message will show the text of that item.
      Is it possible to activate a case like that as soon as the item is selected, so I don't need a button to start the case?
       
      #include <GUIConstantsEx.au3> #include <GUIListViewEx.au3> Global $MainGUI_ManageItemList Global $File = "test.txt" Global $FileToArray = FileReadToArray("test.txt") Call ("MainGUI_ManageItemList") Func MainGUI_ManageItemList() Local $Button1 $MainGUI_ManageItemList = GUICreate("Manage Item List", 800, 400, -1, -1) $cLV = GUICtrlCreateListView("[items]", 10, 10, 400, 775, $LVS_NOCOLUMNHEADER) GUICtrlSetFont(-1, 12, 800, 0, "@Arial Unicode MS") _GUICtrlListView_SetColumnWidth($cLV, 0, 378) $Button1 = GUICtrlCreateButton("Button 1", 425, 10, 80, 30) $RemoveItem = GUICtrlCreateButton("Remove Item", 425, 50, 80, 30) $GetInfo = GUICtrlCreateButton("GetInfo", 425, 120, 80, 30) GUISetState(@SW_SHOW, $MainGUI_ManageItemList) ; Intialise ListView Global $iLV_Index = _GUIListViewEx_Init($cLV) ; Insert lines _GUIListViewEx_Insert($FileToArray, True) ; Register required messages _GUIListViewEx_MsgRegister(True, False, False, False) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $Button1 MsgBox(0,"","Button 1 is pressed") Case $RemoveItem _GUIListViewEx_Delete() Case $GetInfo $ItemSelected = _GUICtrlListView_GetSelectedIndices($cLV, True) If IsArray($ItemSelected) And $ItemSelected[0] <> 0 Then ;This part makes sure it doesn't crash when no item is selected. $ItemSelectedText = _GUICtrlListView_GetItemText($cLV, $ItemSelected[1]) msgbox (0, "Selected item", $ItemSelectedText) EndIf EndSwitch WEnd EndFunc ;==>Main  
    • souldjer777
      By souldjer777
      Good Afternoon All
      Let me start by saying... I'm not sure if this belongs in the GUI part of the forum as it's more of a loop / code / dynamic GUI layout issue. I understand if you move it though.
      I have been doing some crazy things in AutoIT lately and one of them just so happens to be an accidental infinite loop.

      I am dynamically populating my GUI labels... so that means if I have a users ip address I create
      $L_PP1_WhoISSearch However, if I assign a function to a non existent label... for instance a user has no ip address or it is invalid, I get an infinite loop / crash.
      The While loop below just goes crazy running ShellExecute.  Since the label $L_PP1_WhoISSearch doesn't exist, the function WhoISSearch() just runs ShellExecute to infinity... What should I do differently??? Is there a trigger I can set in the Gui to ignore missing cases??? Sorry, I can only provide "snippets" of my code since it's for work. Thanks you all!!!
      ; This is my loop of doom if the $L_PP1_WhoISSearch doesn't exist in my gui. While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $L_PP1_DashboardLink DashboardLink01() Case $L_PP1_WhoISSearch WhoISSearch() Case $B_PP1_BACK02 GUIDelete() Gui01_PP_INC() Case $B_PP1_EXIT02 Exit EndSwitch WEnd Func WhoISSearch() ShellExecute('http://whois.arin.net/rest/nets;q=' & $PP1_SourceIPClick01 & '?showDetails=true&showARIN=false&showNonArinTopLevelNet=false') ;MsgBox (0, "", 'WTF') EndFunc ; This is my dynamic label for my Gui. ElseIf $i = 5 Then $L_PP1_SourceIP = GUICtrlCreateLabel($LabelVariable & ' ' & $aArray_Variable_PP_Gui01[$i], 10, $L_PP1_Var_StartHeight, 316, 19) GUICtrlSetFont(-1, 10, 800, 0, "Calibri") $L_PP1_Var_StartHeight += 22 $L_PP1_WhoISSearch = GUICtrlCreateLabel('WhoIS Search: ' & $PP1_SourceIPClick01, 10, $L_PP1_Var_StartHeight, 316, 19) GUICtrlSetFont(-1, 10, 800, 0, "Calibri") GUICtrlSetColor(-1, 0x0000FF) $L_PP1_Var_StartHeight += 22  
    • iCode
      By iCode
      This is a spin-off of >Seeker's function which i rewrote and tried to optimize for doing only sentence casing and for better Unicode handling. Haven't done a lot of testing with it, but it seems to work well so far.
      #include-once ; #FUNCTION# ==================================================================================================================== ; Name ..........: _SentenceCase ; Description ...: Capitalize the first letter of sentences. ; Syntax ........: _SentenceCase(Byref $sString) ; Parameters ....: $sString: [in/out] A string value. ; Return values .: Success: A string is returned. ;                  Failure: Sets @error = 1 and returns 0. ; Author ........: iCode ; Modified ......: 30-MAR-2015 ; Remarks .......: ; Related .......: http://www.autoitscript.com/forum/topic/147086-udf-for-title-case-initial-caps-and-sentence-case/ ; Link ..........: http://www.autoitscript.com/forum/topic/169290-sentence-case-capitalize-first-letter-of-sentences/ ; Example .......: No ; =============================================================================================================================== Func _SentenceCase(ByRef $sString)     Local $aStr = StringRegExp($sString, "(*UCP)(?s)[[:alpha:]].+?(?:[.?!:;]|\z)\s*|[^[:alpha:]]+", 3)     If @error Then Return SetError(1, 0, 0)     Local $sChar, $sRet = ""     For $i = 0 To UBound($aStr) - 1         If StringRegExp($aStr[$i], "(*UCP)(?s)^[[:alpha:]]+.*?[.?!:;]") Then             $sChar = StringLeft($aStr[$i], 1)             If StringIsLower($sChar) Then                 $aStr[$i] = StringUpper($sChar) & StringTrimLeft($aStr[$i], 1)             EndIf         EndIf         $sRet &= $aStr[$i]     Next     Return $sRet EndFunc CHANGE LOG:
      28-MAR-2015 - initial version
      30-MAR-2015 - added more sentence terminition characters ( ; : ) - should probably get these from a variable?
    • MikahS
      By MikahS
      I am having problem. I have script that has a main GUI window that allows you to select which kind of encryption you'd like to use. When I go to start the script, for some reason the case statement for the:
      $iSubmit button for the child GUI runs right away and tried to read the data from the input on the child window, which hasn't been created yet, and then pops up the MsgBox.  
      I have been scouring the forums for something of similar nature, but unsuccessful. I have checked helpfile and it seems I am doing this correct. Here is my script:

      ; includes   #include <GUIConstantsEx.au3> #include <Crypt.au3>   ; vars Local $hGUI, $msg = 0, $hInput, $iButton, $hDecode, $dButton Local $aChkBx[8], $cValue, $iChild, $iMsg, $iPswd, $iMsgBox Local $iPswdBox, $iSubmit ;main line   GUI()   While 1     $msg = GUIGetMsg(1)     Switch $msg[1]         Case $hGUI             Switch $msg[0]                 Case $GUI_EVENT_CLOSE                     Quit()                 Case $iButton                     getCheckbox()                     inputChild()                     ;Crypt(, $cValue)                 Case $dButton                     getCheckbox()              EndSwitch         Case $iChild             Switch $msg[0]                   Case $GUI_EVENT_CLOSE                       GUIDelete($iChild)                   Case $iSubmit                       $iMsg = GUICtrlRead($iMsgBox)                       $iPswd = GUICtrlRead($iPswdBox)                       MsgBox(0, "title", "msg:" & $iMsg & " paswrd:" & $iPswd)             EndSwitch     EndSwitch WEnd   ;functions   Func GUI()     $hGUI = GUICreate("Short-Order Encrypter", 300, 200)     GUICtrlCreateLabel("Encrypt a Message!", 95, 15)     GUICtrlCreateLabel("This is a simple input and output encryption program.", 25, 35)     GUICtrlCreateLabel("You will select which method of encryption, then", 30, 48)     GUICtrlCreateLabel("input your text by pressing the Input button,", 40, 61)     GUICtrlCreateLabel("or you will press the Decode button to", 55, 74)     GUICtrlCreateLabel("decode an encrypted message.", 65, 87)     $iButton = GUICtrlCreateButton("Input", 50, 160, 70, 30)     $dButton = GUICtrlCreateButton("Decode", 160, 160, 70, 30)     $aChkBx[0] = GUICtrlCreateCheckbox("Text", 15, 105)     $aChkBx[1] = GUICtrlCreateCheckbox("3DES", 67, 105)     $aChkBx[2] = GUICtrlCreateCheckbox("AES (128bit)", 122, 105)     $aChkBx[3] = GUICtrlCreateCheckbox("AES (192bit)", 208, 105)     $aChkBx[4] = GUICtrlCreateCheckbox("AES (256bit)", 32, 130)     $aChkBx[5] = GUICtrlCreateCheckbox("DES", 121, 130)     $aChkBx[6] = GUICtrlCreateCheckbox("RC2", 172, 130)     $aChkBx[7] = GUICtrlCreateCheckbox("RC4", 224, 130)     GUISetState(@SW_SHOW) EndFunc ;==>GUI   Func getCheckbox()     Local $i, $readArray, $cCounter = 0     For $i = 0 To UBound($aChkBx) - 1 Step 1         $readArray = GUICtrlRead($aChkBx[$i])         If $readArray = 1 Then              $cCounter += 1              $cValue &= $i         EndIf     Next     If $cCounter > 1 Then         MsgBox(0, "Encryption Type", "Could not specify encryption type due to multiple selections. Please make sure you have only selected on type of encryption")         $cValue = ""         Return     ElseIf $cCounter = 0 Then          MsgBox(0, "Encryption Type", "You must select an encryption type in the Short-Order Encrypter window")          Return     EndIf EndFunc ;==>getCheckbox   Func inputChild()     If $cValue = "" Then          Return     EndIf     $iChild = GUICreate("Input Message", 386, 120, -1, -1, -1, -1, $hGUI)     GUICtrlCreateLabel("Message", 5, 10)     GUICtrlCreateLabel("Password", 200, 10)     $iMsgBox = GUICtrlCreateInput("", 5, 25, 180, 60)     $iPswdBox = GUICtrlCreateInput("", 200, 25, 180, 60)     $iSubmit = GUICtrlCreateButton("Encrypt", 172, 90)     GUISetState() EndFunc ;==>inputChild   #cs Func Crypt($iMsg, $iPass, $iflag)     Local $mFlag[8]     $mFlag[0] = "TEXT"     $mFlag[1] = $CALG_3DES     $mFlag[2] = $CALG_AES_128     $mFlag[3] = $CALG_AES_192     $mFlag[4] = $CALG_AES_256     $mFlag[5] = $CALG_DES     $mFlag[6] = $CALG_RC2     $mFlag[7] = $CALG_RC4 EndFunc ;==>Crypt #ce   Func Quit()     GUIDelete($hGUI)     Exit EndFunc ;==>Quit  
    • Colyn1337
      By Colyn1337
      This code loads the result of a regread into a variable and then parses the result:
      $RegResult = RegRead($HKLM & "\SYSTEM\CurrentControlSet\services\LanmanServer\Parameters", "AutoShareWks") Select Case $RegResult = "" $RegWriteResult = RegWrite($HKLM & "\SYSTEM\CurrentControlSet\services\LanmanServer\Parameters", "AutoShareWks", "REG_DWORD", "0") TrayTip("Registry Read", "AutoShareWks Reg key not found and was created. The read result was: " & $RegResult & " " & @error & _ ". The write result was: " & $RegWriteResult & " " & @error, 5) Case $RegResult = "0" ; 0 indicates sharing is off TrayTip("Registry Read", "Auto Drive Sharing is currently DISABLED.", 5) Case $RegResult = "1" ; 1 indicates sharing is on TrayTip("Registry Read", "Auto Drive Sharing is currently ENABLED", 5) EndSelect The problem is that the value of AutoShareWks is boolean and either 1 or 0.  The documentation for regread states that if failure of the regread, "" is returned.  However it seems to also interpret 0 as "" and trigger a false failure.  Even @error has the same issue.  If the reading value is 0, @error will trigger.
      So, how can I get around this false failure trigger?
      EDIT:
      I figured out a work around like this:
      $RegResult = RegRead($HKLM & "\SYSTEM\CurrentControlSet\services\LanmanServer\Parameters", "AutoShareWks") Select Case $RegResult = "0" ; 0 indicates sharing is off TrayTip("Registry Read", "Auto Drive Sharing is currently DISABLED.", 5) Case $RegResult = "1" ; 1 indicates sharing is on TrayTip("Registry Read", "Auto Drive Sharing is currently ENABLED.", 5) Case Else ; Default Actions TrayTip("Registry Read", "AutoShareWks value not present in registry. Auto Drive Sharing is currently ENABLED.", 5) EndSelect However, still.......  Why is the error process not catching it correctly?