By
D3fr0s7
I'm trying to make one tray item delete another, but when I do this, all tray items that were created after the deleted item don't work as intended, as if their controlID's were all shifted down one value, and their corresponding tray items now (after deletion) run the code of the tray item before it. Am I missing something? Is there a better way to accomplish what I'm trying to do?
#include <TrayConstants.au3>
#include <Array.au3>
HotKeySet ( "{ESC}", "Abort" )
Opt ( "TrayMenuMode", 3 )
TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu.
Global $aTray[8] ; Defines array to hold tray items.
$aTray[0] = TrayCreateItem ( "Test 1 (Name Test 5)" )
$aTray[1] = TrayCreateItem ( "Test 2 (Delete Test 5)" )
$aTray[2] = TrayCreateItem ( "Test 3 (Restore Test 5)" )
$aTray[3] = TrayCreateItem ( "Test 4 (Check if Test 5 is blank or space)" )
$aTray[4] = TrayCreateItem ( "Test 5 Delete Me" )
$aTray[5] = TrayCreateItem ( "Test 6 (Check Test 5 Text)" )
$aTray[6] = TrayCreateItem ( "Test 7 (Read Values)" )
$aTray[7] = TrayCreateItem ( "Test 8 (Count Blanks)" )
While 1
Switch TrayGetMsg()
Case $aTray[0] ; "Test 1" Change Test 5 Text.
If TrayItemGetText ( $aTray[0] ) <> "" Then
Global $TrayText = InputBox ( "Test", "Choose text for Test 5", "Test 5 Delete Me" )
TrayItemSetText ( $aTray[4], $TrayText)
EndIf
Case $aTray[1] ; "Test 2" Deletes "Test 5".
If TrayItemGetText ( $aTray[1] ) <> "" Then
Global $TrayDeletedName = TrayItemGetText ( $aTray[4] )
TrayItemDelete ( $aTray[4] )
_ArrayInsert ( $aTray, 4 )
EndIf
Case $aTray[2] ; "Test 3" Restores "Test 5".
If TrayItemGetText ( $aTray[2] ) <> "" Then
$aTray[4] = TrayCreateItem ( $TrayDeletedName )
EndIf
Case $aTray[3] ; "Test 4" Check if Test 5 value is blank, space, or filled.
If TrayItemGetText ( $aTray[3] ) <> "" Then
If TrayItemGetText ( $aTray[4] ) = "" Then
MsgBox ( 0, "Test", "Test 5 is blank" )
ElseIf TrayItemGetText ( $aTray[4] ) = " " Then
MsgBox ( 0, "Test", "Test 5 is not blank (space)" )
Else
MsgBox ( 0, "Test", "Test 5 is assigned a value" )
EndIf
EndIf
Case $aTray[4] ; "Test 5" (Item to test for, during, and after deletion).
If TrayItemGetText ( $aTray[4] ) <> "" Then
MsgBox ( 0, "Test", "I'm here!" )
EndIf
Case $aTray[5] ; "Test 6" Displays Text from Test 5 item.
If TrayItemGetText ( $aTray[5] ) <> "" Then
$Test5Text = TrayItemGetText ( $aTray[4] )
MsgBox ( 0, "Test", "Test 5 Text: " & $Test5Text )
EndIf
Case $aTray[6] ; "Test 7" Displays all item values.
If TrayItemGetText ( $aTray[6] ) <> "" Then
MsgBox ( 0, "Test", "$aTray[0]: " & $aTray[0] & @CRLF & _
"$aTray[1]: " & $aTray[1] & @CRLF & _
"$aTray[2]: " & $aTray[2] & @CRLF & _
"$aTray[3]: " & $aTray[3] & @CRLF & _
"$aTray[4]: " & $aTray[4] & @CRLF & _
"$aTray[5]: " & $aTray[5] & @CRLF & _
"$aTray[6]: " & $aTray[6] & @CRLF & _
"$aTray[7]: " & $aTray[7] & @CRLF )
EndIf
Case $aTray[7] ; "Test 8" Counts all blanks in tray values.
If TrayItemGetText ( $aTray[7] ) <> "" Then
Global $blankCount = _ArrayFindAll ( $aTray, "" )
If $blankCount = -1 Then
If @error = 6 Then
MsgBox ( 0, "Test", "Error, No blanks present")
EndIf
Else
MsgBox ( 0, "Test", "# of blanks: " & $blankCount )
EndIf
EndIf
EndSwitch
WEnd
Func Abort()
Exit
EndFunc
Here is a test script I created to try to troubleshoot the problem on my own, with no luck. pay specific attention to "Test 2" ($aTray[1]), "Test 5" ($aTray[4]), and how every tray item after "Test 5" ($aTray[4]) behaves after deletion. Clicking "Test 2" will delete tray item "Test 5", after deletion every item runs the code of the tray item that was established before it (ex. "Test 3" and "Test 4" run their respective code, "Test 5" no longer exists, "Test 6" runs "Test 7", "Test 7" runs "Test 8"), and the last item ("Test 8" $aTray[7]) has no effect when the tray item is clicked.
I understand that deleting the tray item changes the controlID, but I don't know in what way it does, and therefore how I can fix it to be able to achieve what I want it to. I appreciate any help or guidance with this problem.
To clarify, what I'm ultimately trying to do is create a 'while' loop with switch case functions that can exist without necessarily being linked to a tray item, so that I can add and delete them at liberty using the script's functions, without having to differentiate switch case functions with if functions (if $aTray[x] exists, then use this set of switch case functions, etc.).
Please, I am in pain. Water come school me again pls