Jump to content

Recommended Posts

Posted

Good day,

Most of my scripts employ "Switch|Case"...however the following appears to only work as an "If|Then".

; -----------------------------------------------
; Example4a
_DoesRegKeyExist()
; -----------------------------------------------
Func _DoesRegKeyExist()
    Local $sKeyname = "HKEY_CURRENT_USER\Software\FabFilter"
    ; -----------------------------------------------
    RegRead($sKeyname, "")
    ; -----------------
    If @error = 1 Then
        SplashTextOn("NOTICE!!", "The registry key " & $sKeyname & " does not exist!", 800, 50, -1, -1)
        Sleep(3000)
        SplashOff()
    Else
        SplashTextOn("NOTICE!!", "The registry key " & $sKeyname & " does exist!", 800, 50, -1, -1)
        Sleep(3000)
        SplashOff()
    EndIf
EndFunc   ;==>_DoesRegKeyExist
; -----------------------------------------------

Is there any way in which to get the above to work with "Switch|Case"? For example:

; -----------------------------------------------
; Example4b
_DoesRegKeyExist()
; -----------------------------------------------
Func _DoesRegKeyExist()
    Local $sKeyname = "HKEY_CURRENT_USER\Software\FabFilter"
    ; -----------------------------------------------
    Local $Result = RegRead($sKeyname, "")
    ; -----------------
    Switch $Result
        Case 0
            $Result = "The Registry Keys data...[" & $sKeyname & "]...does not exist!"
        Case 1
            $Result = "The Registry Keys data...[" & $sKeyname & "]...does exist!"
    EndSwitch

EndFunc   ;==>_DoesRegKeyExist
; -----------------------------------------------

Please advise...and thank you for your time.

Posted (edited)

Good dya,

I have been able to get this snippet to work...

; -----------------------------------------------
; With the assistance of...and the gratitude of...ioa747!
; Date: September 15th, 2024
; -----------------------------------------------
#include <FileConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
_CheckRegKeys()
; -----------------------------------------------
Func _CheckRegKeys()
    ; Source data
    Local $sKeyname[3] = [2]
    $sKeyname[1] = "HKEY_CURRENT_USER\Software\FabFilter"
    $sKeyname[2] = "HKEY_LOCAL_MACHINE\SOFTWARE\FabFilter"
    ; -----------------------------------------------
    Local $sMessage = "Verify Registry Keys data..." & @CRLF & @CRLF
    ; -----------------------------------------------
    For $i = 1 To $sKeyname[0]
        Local $Result = RegRead($sKeyname[$i], "")
        If @error = 1 Then
            $Result = "The registry key [" & $sKeyname[$i] & "] does not exist!"
        Else
            $Result = "The registry key [" & $sKeyname[$i] & "] does exist!"
        EndIf
        ; -----------------
        $sMessage &= $Result & @CRLF
    Next
    ; -----------------------------------------------
    $sMessage &= @CRLF & "Verify Registry Keys data completed..." & @CRLF
    ; -----------------------------------------------
    SplashTextOn("NOTICE!!", $sMessage, 675, 157, -1, -1, 4, "FuturaBQ-DemiBold", 14)
    Sleep(3000)
    SplashOff()
EndFunc   ;==>_CheckRegKeys
; -----------------------------------------------

...sooooo, maybe...all is Okay?!?

Edited by mr-es335
Posted
ConsoleWrite("This " & @CRLF)
Switch @error
    Case 0
        ConsoleWrite("works" & @CRLF)
    Case Else
        ConsoleWrite("fails" & @CRLF)
EndSwitch

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...