Jump to content

Need Help Multible const in an "If Or" Statement - (Moved)


BrAiNee
 Share

Recommended Posts

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

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 by Musashi
typo

Musashi-C64.png

"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

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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) :

#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

 

Musashi-C64.png

"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

  • Melba23 changed the title to Need Help Multible const in an "If Or" Statement - (Moved)

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