Jump to content

Recommended Posts

Posted (edited)

Hello guys, 

I have this sample of code : 

Func _EnumBoites ()
    Local $cKey ="HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Search"
    Local $sSubKey = "", $sEnumBoite = $cKey & @CRLF & @CRLF , $sEnumBoiteFTV
    ; Loop from 1 to 20 times, displaying registry keys at the particular instance value.
    $ListView2 = GUICtrlCreateTreeView ( 260,150,200,100)
    $cCombo0002 = GUICtrlCreateCombo ("Choisir une boite"  ,300,260 , 150 , 50 )
    For $i = 1 To 20
;~      MsgBox(0, "debug $i boite:", $i)
        $sSubKey = RegEnumVal("HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Search", $i)
;~      MsgBox(0, "Debug SubKey", $sSubKey)
            If @error Then ExitLoop
            $StringRight = StringRight ( ""&$sSubKey , 4 )
;~          MsgBox(0, "Debug StringTrim", $StringRight)
        If $StringRight = ".ost" Or $StringRight = ".pst" Then
                If $StringRight = ".ost" Then $NombreBoites += 1
                If $StringRight = ".pst" Then $NombrePst += 1
        ==========================================================================      
                ;~  MsgBox(0, "Debug", @UserName)
;~              $StringToFind = @UserName
;~              $StringCount = StringInStr ( ""&$sSubKey, ""&$StringToFind ,0,1 , 11)
;~              MsgBox(0, "Debug", $debug)
;~              If $StringCount > 0 Then $MailPrincipal = ""
        GUICtrlSetBkColor ( $cLabel00013 , 0x00FF01 )
        GUICtrlSetData ( $cLabel0004 , "Nombre de PST : "&$NombrePst )
        $sEnumBoite &= "#" & $i & @TAB & $sSubKey & @CRLF
        $sEnumBoiteFTV = $cKey & "\" & $sSubKey & @TAB  & @CRLF
        GUICtrlCreateTreeViewItem($sSubKey,$ListView2)
        GUICtrlSetData($cCombo0002, ""&$sSubKey)
;~      MsgBox(0, "Debug", $sEnumBoite)
            Else

            EndIf
    Next
    $_EnumBoites = 1

EndFunc

I want to make a line to replace ============================ by a variable $Var

 

I want to say :

If $StringRight = ".pst" Then 
    $NombrePst += 1
    $PstNumero1 = $sSubKey
EndIF

My problem is here how to increment $PstNumero1 at each for loop

And say PstNumero2 PstNumero3 etc...

 

 

I did that : 

If $StringRight = ".ost" Or $StringRight = ".pst" Then
                If $StringRight = ".ost" Then $NombreBoites += 1
                If $StringRight = ".pst" Then $NombrePst += 1
                    If $NombrePst = 1 Then 
                        $PstNumero1 = $sSubKey
                    ElseIf $NombrePst = 2
                        $PstNumero2 = $sSubKey
                    ElseIf $NombrePst = 3
                        $PstNumero3 = $sSubKey
                    ElseIf $NombrePst = 4
                        $PstNumero4 = $sSubKey
                    ElseIf $NombrePst = 5
                        $PstNumero5 = $sSubKey
                    ElseIf $NombrePst = 6
                        $PstNumero6 = $sSubKey
                    ElseIf $NombrePst = 7
                        $PstNumero7 = $sSubKey
                    ElseIf $NombrePst = 8
                        $PstNumero8 = $sSubKey
                    ElseIf $NombrePst = 9
                        $PstNumero9 = $sSubKey
                    EndIf
                ;~  MsgBox(0, "Debug", @UserName)
;~              $StringToFind = @UserName
;~              $StringCount = StringInStr ( ""&$sSubKey, ""&$StringToFind ,0,1 , 11)
;~              MsgBox(0, "Debug", $debug)
;~              If $StringCount > 0 Then $MailPrincipal = ""
        GUICtrlSetBkColor ( $cLabel00013 , 0x00FF01 )

Maybe there is a better way to do same ? 

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Posted

Here is the full code: 

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.5
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include <GUIConstantsEx.au3>
#include <ColorConstantS.au3>
#include <WindowsConstants.au3>

Global $ScanOutlook
Global $PresenceOutlook= "" , $PresenceProfilOutlook = "" , $i = "" , $Background = 0 , $_EnumBoites = 0 , $NombreBoites = 0 , $NombrePst = 0,$PstNumero1 = "",$PstNumero2 = "",$PstNumero3 = "",$PstNumero4 = "",$PstNumero5 = "",$PstNumero6 = "",$PstNumero7 = "",$PstNumero8 = "",$PstNumero9 = "",$PstNumero10 = "",

$hGUI = GUICreate ( "ITMigra", 600 , 600 )
$Tab01 = GUICtrlCreateTab ( 5,5 )
$Tabitem00001 = GUICtrlCreateTabItem ("Outlook")
$cLabel0001 = GUICtrlCreateLabel ("Outlook Présent :",10,30)
$cLabel00011 = GUICtrlCreateLabel ("",250,30)
$cLabel0002 = GUICtrlCreateLabel ("Profil Outlook Présent :",10,60)
$cLabel00012 = GUICtrlCreateLabel ("",250,60)
$cLabel0003 = GUICtrlCreateLabel ("Présence de PST :",10,90,100,100)
$cLabel00013 = GUICtrlCreateLabel ("",250,90)
$cLabel0004 = GUICtrlCreateLabel ("Nombre de PST :",10,120,100,100)
GUISetBkColor($COLOR_RED)
GUISetState( @SW_SHOW , $hGUI )

; 0x00FF01 );Vert vif
; 0xFB1924 );Rouge vif
; 0x4486FA );Bleu google
; 0x00A2E8 );Bleu autre

While 1
    Sleep (10)
    _ScanComputer ()

    $msg = GUIGetMsg ()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _ScanComputer ()
    If $PresenceOutlook= "" Then
        _ScanOutlook ()
    EndIf
    If $PresenceOutlook= "Oui" Then
        GUICtrlSetBkColor ( $cLabel00011 , 0x00FF01 );Vert vif
    Else
        GUICtrlSetBkColor ( $cLabel00011 , 0xFB1924 );Rouge vif
    EndIf

    If $PresenceProfilOutlook = "" Then
        _EnumProfil ()
    EndIf
    If $PresenceProfilOutlook = "Oui" Then
        GUICtrlSetBkColor ( $cLabel00012 , 0x00FF01 );Vert vif
    Else
        GUICtrlSetBkColor ( $cLabel00012 , 0xFB1924 );Rouge vif
    EndIf
    $Background += 1
    If $Background > 100 Then
    If $PresenceOutlook= "Oui" And $PresenceProfilOutlook = "Oui" Then
        GUISetBkColor ( 0x00A2E8)
;~      MsgBox ( 0 , "debug GUI COLOR" , 'Color should be Green' )
    Else
        GUISetBkColor ( 0xFB1924)
    EndIf
    $Background = 0
    EndIf
    If $_EnumBoites = 0 Then
    _EnumBoites ()
    EndIf
EndFunc

Func _ScanOutlook ()
    $ScanOutlook = _RegKeyExists("HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Profiles")
    If $ScanOutlook = "" Then $PresenceOutlook= "Oui"
;~  MsgBox ( 0 , "debug" , '$PresenceOutlook= "Oui"' )
EndFunc

Func _EnumProfil ()
    Local $cKey ="HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Profiles"
    Local $sSubKey = "", $sEnumKey = $cKey & @CRLF & @CRLF , $sEnumKeyFTV
    ; Loop from 1 to 10 times, displaying registry keys at the particular instance value.
    $ListView1 = GUICtrlCreateTreeView ( 30,150,200,100)
    $cCombo0001 = GUICtrlCreateCombo ("Choose a Profil"  ,30,260 , 150 , 50 )
    For $i = 1 To 10
;~      MsgBox(0, "debug $i:", $i)
        $sSubKey = RegEnumKey("HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Profiles", $i)
            If @error Then ExitLoop
        $sEnumKey &= "#" & $i & @TAB & $sSubKey & @CRLF
        $sEnumKeyFTV = $cKey & "\" & $sSubKey & @TAB  & @CRLF
        GUICtrlCreateTreeViewItem($sEnumKeyFTV,$ListView1)
        GUICtrlSetData($cCombo0001, ""&$sEnumKeyFTV)
    Next
    _i ()
;~     MsgBox(0, "Profils:", $sEnumKey)
    If $i = 0 Then
;~      MsgBox(0, "Debug", '$PresenceProfilOutlook = "Non"')
        $PresenceProfilOutlook = "Non"
    Else
;~      MsgBox(0, "Profils:", $sEnumKey)
        $PresenceProfilOutlook = "Oui"
;~      MsgBox(0, "Debug", '$PresenceProfilOutlook = "Oui"')
    EndIf
EndFunc

Func _i ()
    If $i = 1 Then
        $i=0
;~      MsgBox(0, "Debug $i", "I WAS 1 now IT IS 0")
    Else

    EndIf
EndFunc

Func _EnumBoites ()
    Local $cKey ="HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Search"
    Local $sSubKey = "", $sEnumBoite = $cKey & @CRLF & @CRLF , $sEnumBoiteFTV
    ; Loop from 1 to 20 times, displaying registry keys at the particular instance value.
    $ListView2 = GUICtrlCreateTreeView ( 260,150,200,100)
    $cCombo0002 = GUICtrlCreateCombo ("Choisir une boite"  ,300,260 , 150 , 50 )
    For $i = 1 To 20
;~      MsgBox(0, "debug $i boite:", $i)
        $sSubKey = RegEnumVal("HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Search", $i)
;~      MsgBox(0, "Debug SubKey", $sSubKey)
            If @error Then ExitLoop
            $StringRight = StringRight ( ""&$sSubKey , 4 )
;~          MsgBox(0, "Debug StringTrim", $StringRight)
        If $StringRight = ".ost" Or $StringRight = ".pst" Then
                If $StringRight = ".ost" Then $NombreBoites += 1
                If $StringRight = ".pst" Then $NombrePst += 1
                    If $NombrePst = 1 Then 
                        $PstNumero1 = $sSubKey
                    ElseIf $NombrePst = 2
                        $PstNumero2 = $sSubKey
                    ElseIf $NombrePst = 3
                        $PstNumero3 = $sSubKey
                    ElseIf $NombrePst = 4
                        $PstNumero4 = $sSubKey
                    ElseIf $NombrePst = 5
                        $PstNumero5 = $sSubKey
                    ElseIf $NombrePst = 6
                        $PstNumero6 = $sSubKey
                    ElseIf $NombrePst = 7
                        $PstNumero7 = $sSubKey
                    ElseIf $NombrePst = 8
                        $PstNumero8 = $sSubKey
                    ElseIf $NombrePst = 9
                        $PstNumero9 = $sSubKey
                    EndIf
                ;~  MsgBox(0, "Debug", @UserName)
;~              $StringToFind = @UserName
;~              $StringCount = StringInStr ( ""&$sSubKey, ""&$StringToFind ,0,1 , 11)
;~              MsgBox(0, "Debug", $debug)
;~              If $StringCount > 0 Then $MailPrincipal = ""
        GUICtrlSetBkColor ( $cLabel00013 , 0x00FF01 )
        GUICtrlSetData ( $cLabel0004 , "Nombre de PST : "&$NombrePst )
        $sEnumBoite &= "#" & $i & @TAB & $sSubKey & @CRLF
        $sEnumBoiteFTV = $cKey & "\" & $sSubKey & @TAB  & @CRLF
        GUICtrlCreateTreeViewItem($sSubKey,$ListView2)
        GUICtrlSetData($cCombo0002, ""&$sSubKey)
;~      MsgBox(0, "Debug", $sEnumBoite)
            Else

            EndIf
    Next
    $_EnumBoites = 1

EndFunc

Func _RegKeyExists($_sRegKey)
    Local $sDefault = RegRead($_sRegKey, "") ;~ Try to read default value
    Switch @error
        Case 1, 2
            ;~ Unable to open requested key | Unable to open requested main key
            Return SetError(@error, 0, 'Error: Registry Key: "' & $_sRegKey & '" does not exist.')
        Case Else
            ; Registry Key Exists | Return (Default) value
            Return SetError(0, 0, $sDefault)
    EndSwitch
EndFunc

 

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Posted

I want to be able to select each return after the function have finished. 

 

For obvius reason. 

 

I want to record each pst in a $variable. like that with the return value : 

PSTnumero1 = C:\blablabalblaa

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Posted

Yeah i thought about an array but I was wondering if there is a "trick" to do it with some lines easyer that store everything in an array.

 

Seem like to be the best way ... hmmm

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Posted (edited)

Ah yeah i will give it a try i am going to do : 

 

Assign ("PSTNumero"&$NombrePst , ""&$sSubKey )

Will be very good for my case. 

@Jos Yeah no time to reply xD Thanks ;) 

Thanks all. 

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

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
×
×
  • Create New...