BrAiNee Posted January 26, 2021 Share Posted January 26, 2021 Hello im Newbi in Programming with arrays or Multible if Or Statements. I have a Code that is secured by HWID, so i have Multible HWIDs and i will put them in one line maybe an array? I don't whant to change my IF Statement every Time a New HWID is comming. How can i do this is in a nice way ? Here my code. Local Const $hw1 = "42421425" ;mark Local Const $hw2 = "85738578" ;monte Local Const $hw3 = "84885282" ;heinz Local Const $hw4 = "98573857" ;tobi If _GetHWID() == $hw1 Or _GetHWID() == $hw2 Or _GetHWID() == $hw3 Or _GetHWID() == $hw4 Then $hwid_ok = True Else Local $hwid_input = InputBox("HWID_ERROR", "Contact Support!", _GetHWID(), "", 270, 150) If @error Then Exit Else ClipPut(_GetHWID()) Exit EndIf EndIf in this state i have to change my if statement and this can get very long. How to make it easy? Link to comment Share on other sites More sharing options...
Musashi Posted January 26, 2021 Share Posted January 26, 2021 (edited) 4 hours ago, BrAiNee said: How to make it easy? There are several ways to do it. Here a solution via array : #include <Array.au3> #include <File.au3> Global $aHWIDList, $sFilePath, $bHWIDFound, $sHWIDInput $sFilePath = @ScriptDir & "\HWIDList.txt" $bHWIDFound = False _FileReadToArray($sFilePath, $aHWIDList, $FRTA_NOCOUNT, ";") _ArrayDisplay($aHWIDList) ; *** just for display during test For $i = 0 To UBound($aHWIDList) - 1 If _GetHWID() = $aHWIDList[$i][0] Then MsgBox(0, "HWID found", "HWID=" & $aHWIDList[$i][0] & " Name=" & $aHWIDList[$i][1] & @CRLF) $bHWIDFound = True ExitLoop EndIf Next If Not $bHWIDFound Then $sHWIDInput = InputBox("HWID_ERROR", "Contact Support!", _GetHWID(), "", 270, 150) If @error Then Exit Else ClipPut(_GetHWID()) Exit EndIf EndIf ; naked function for testing : Func _GetHWID() Local $sHWID = "" ; ... put the real GetHWID statements here $sHWID = "85738578" ; only for test Return $sHWID EndFunc HDWIList.txt (save it in your script folder) or use the attached file : 42421425;mark 85738578;monte 84885282;heinz 98573857;tobiData HWIDList.txt Edited January 26, 2021 by Musashi typo "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 26, 2021 Moderators Share Posted January 26, 2021 Moved to the appropriate forum, as the Developer General Discussion forum very clearly states: Quote General development and scripting discussions. Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums. Moderation Team Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
BrAiNee Posted January 26, 2021 Author Share Posted January 26, 2021 (edited) @Musashi that looks interesting can you show me how to make it in the code without the extra .txt file ? please make it simple regards BrAiNee Edited January 26, 2021 by BrAiNee Link to comment Share on other sites More sharing options...
Musashi Posted January 26, 2021 Share Posted January 26, 2021 1 hour ago, BrAiNee said: @Musashi that looks interesting can you show me how to make it in the code without the extra .txt file ? The benefit of maintaining the data in an external file (here the .txt) is, that you can make additions without having to constantly change the script itself. Here is an example which contains both variants (comment out the unwanted one) : expandcollapse popup#include <Array.au3> #include <File.au3> ; ====> Comment out variant 1 or 2 depending on your needs ; ----> Variant 1 : Read data from a file : -------------- ;~ Global $aHWIDList, $sFilePath, $bHWIDFound, $sHWIDInput ;~ $sFilePath = @ScriptDir & "\HWIDList.txt" ;~ $bHWIDFound = False ;~ _FileReadToArray($sFilePath, $aHWIDList, $FRTA_NOCOUNT, ";") ; ----- End of Variant 1 --------------------------------- ; ----> Variant 2 : array within the script : ------------ Global $bHWIDFound, $sHWIDInput Global $aHWIDList[4][2] = [["42421425", "mark"], _ ["85738578", "monte"], _ ["84885282", "heinz"], _ ["98573857", "tobiData"]] $bHWIDFound = False ; ----- End of Variant 2 --------------------------------- _ArrayDisplay($aHWIDList, "Test : Output") ; *** just for display during test For $i = 0 To UBound($aHWIDList) - 1 If _GetHWID() = $aHWIDList[$i][0] Then MsgBox(0, "HWID found", "HWID=" & $aHWIDList[$i][0] & " Name=" & $aHWIDList[$i][1] & @CRLF) $bHWIDFound = True ExitLoop EndIf Next If Not $bHWIDFound Then $sHWIDInput = InputBox("HWID_ERROR", "Contact Support!", _GetHWID(), "", 270, 150) If @error Then Exit Else ClipPut(_GetHWID()) Exit EndIf EndIf ; naked function for testing : Func _GetHWID() Local $sHWID = "" ; ... put the real GetHWID statements here $sHWID = "84885282" ; only for test Return $sHWID EndFunc BrAiNee 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
BrAiNee Posted January 27, 2021 Author Share Posted January 27, 2021 @Musashi thank you that helps me allot. 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