Jump to content

[Solved]_Variable Q


Recommended Posts

Purpose of this code is very simple, to remove the default selection from the Tree item: you click on any treeitem & it should unselect

Im not shure why this isnt working, I thoughti set the variables correctly but, well maybe someone can see the problem?

$i = 1

Edit: k lets put it this way: How to create a variable $var & '$i' = 'hello' & then consolewrite($var1) ?

For $i = 1 to 2
        $Treeitem = GUICtrlCreateTreeViewItem('Item' & $i, $generalitem); create treeitem
        $Treeitem = Eval($Treeitem & $i)  
    Next
    $Treeitem1 = GUICtrlRead($Treeitem1, 1)
    ConsoleWrite($Treeitem1  & @CRLF)oÝ÷ Ù&¦¦WºÚ"µÍÚ[ÛYH ÑÕRPÛÛÝ[Ñ^]LÉÝÂÚ[ÛYH ÕÚ[ÝÜÐÛÛÝ[Ë]LÉÝÂÚ[ÛYH ÕYUY]ÐÛÛÝ[Ë]LÉÝÂÚ[ÛYH    ÔÝ]XÐÛÛÝ[Ë]LÉÝÂÜ
    ][ÝÑÕRSÛ][[ÙI][ÝËJHÈÚ[ÙHÈÛ][[ÙBÛØ[   ÌÍÙÙ[[][BÑÕRSPRÑJ
HßOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOB[ÈÑ[ÕYJ
BÜ ÌÍÚHHHÈ ÌÍÕYZ][HH][
    ÌÎNÒ][IÌÎNÈ   [È ÌÍÚJB    ÌÍÕYZ][HHÕRPÝÜX]UYUY]Ò][J    ÌÎNÒ][IÌÎNÈ   [È ÌÍÚK ÌÍÙÙ[[][JHÈÜX]HYZ][BÕRPÝÙ]Û][
    ÌÍÕYZ][K ][Ý×Õ[Ù[XÝ ][ÝÊBY    ÌÎNÒ][IÌÎNÈ   [È ÌÍÚHH    ÌÎNÒ][LÌÎNÈ[ÕRPÝÙ]ÐÛÛÜLKYYJB^ÕRPÝÙ]Ý]J ÌÍÙÙ[[][K]Ô    ÌÍÑÕRWÑVS  ÌÍÑÕRWÑQUÓJHÈ^[H ][ÝÑÙ[[  ][ÝËZ][H[Z[[Û[[ÂßOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOB[ÈÕ[Ù[XÝ

B   ÌÍÝH][
    ][ÝÒ][L][ÝÊBÕRPÝÙ]ÐÛÛÜ   ÌÍÝ  ÌÍÑÕRWÐÐÓÓÔÕSÔTS
HÈ[Ù[XÝYH][BÛÛÛÛUÜ]JÕRPÝXY
    ÌÍÝJH    [ÈÔB[[ÂßOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOBÚ[HBÛY
L
BÑ[[ÈÑÕRSPRÑJ
BÌÍÑÜLHHÕRPÜX]J   ][ÝÉ][ÝËÌÍÍËÌLËÍJB   ÌÍÝY]Y]ÈHÕRPÝÜX]UYUY]Ê
MKË]Ô ÌÍÕ×ÒTÐUÓË  ÌÍÕ×ÒTÓSTË   ÌÍÕ×ÓSTÐUÓÕ ÌÍÕ×ÑTÐPQQÑÔ    ÌÍÕ×ÔÒÕÔÑSSÐVTÊK ÌÍÕÔ×ÑVÐÓQSQÑJB    ÌÍÙÙ[[][HHÕRPÝÜX]UYUY]Ò][J  ][ÝÑÙ[[  ][ÝË  ÌÍÝY]Y]ÊBÕRPÝÙ]ÛÛÜLKÌ
BÑ[ÕYJ
BÕRTÙ]Ý]JÕ×ÔÒÕÊHÕRTÙ]Û][
    ÌÍÑÕRWÑUSÐÓÔÑK ][Ý×ÐÓÔÑPÛXÚÙY ][ÝÊB[[Â[ÈÐÓÔÑPÛXÚÙY

B^][[
Edited by goldenix
My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]
Link to comment
Share on other sites

Purpose of this code is very simple, to remove the default selection from the Tree item: you click on any treeitem & it should unselect

Im not shure why this isnt working, I thoughti set the variables correctly but, well maybe someone can see the problem?

$i = 1

Edit: k lets put it this way: How to create a variable $var & '$i' = 'hello' & then consolewrite($var1) ?

Modified example from help file for Assign().

CODE
Global $var1, $i = 1

Assign("var" & $i, "Hello")

MsgBox(4096, "", $var1) ; Will print "Hello"

Also

ConsoleWrite("$var1 = " & $var1 & @CRLF)

Has more meaning when read at console.

Edit: This probably isn't what you need to store some data in a variable. and, Look up Eval() in help.

Edited by Malkey
Link to comment
Share on other sites

Purpose of this code is very simple, to remove the default selection from the Tree item: you click on any treeitem & it should unselect

Im not shure why this isnt working, I thoughti set the variables correctly but, well maybe someone can see the problem?

Well, this removes the Assign/Eval foolishness, but I have no idea what you mean about removing an item since all your code does is set a background:
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#include <StaticConstants.au3>

Opt("GUIOnEventMode", 1); Change to OnEvent mode

Global $Form1, $treeview
Global $avItems[3]; Array of TreeViewItems, [0] = 'General'

_GUIMAKE()

While 1
    Sleep(1000)
WEnd


Func _GUIMAKE()
    $Form1 = GUICreate("", 300, 377, 313, 365)
    $iTVStyle = BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS)
    $treeview = GUICtrlCreateTreeView(2, 40, 161, 227, $iTVStyle, $WS_EX_CLIENTEDGE)
    $avItems[0] = GUICtrlCreateTreeViewItem("General", $treeview)
    GUICtrlSetColor(-1, 0x0000C0)
    _Fill_Tree()
    GUISetState(@SW_SHOW)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_CLOSEClicked")
EndFunc  ;==>_GUIMAKE


Func _Fill_Tree()
    For $i = 1 To 2
        $avItems[$i] = GUICtrlCreateTreeViewItem('Item' & $i, $avItems[0]); create treeitem
        GUICtrlSetOnEvent(-1, "_Unselect")
        If $i = 2 Then GUICtrlSetBkColor(-1, 0xd9d9d9)
    Next
    GUICtrlSetState($avItems[0], BitOR($GUI_EXPAND, $GUI_DEFBUTTON)); Expand the "General"-item and paint in bold
EndFunc  ;==>_Fill_Tree


Func _Unselect()
    GUICtrlSetBkColor($avItems[2], $GUI_BKCOLOR_TRANSPARENT); "Unselect" tree sub item 2?
    ConsoleWrite(GUICtrlRead($avItems[2], 1) & @LF)
EndFunc  ;==>_Unselect


Func _CLOSEClicked()
    Exit
EndFunc  ;==>_CLOSEClicked

muttley

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Well, this removes the Assign/Eval foolishness, but I have no idea what you mean about removing an item since all your code does is set a background: muttley

I think you misread my post a little, the purpose of this was to remove the default selection from treeitem by setting its background to transparent.

And thank you for the code, this solved my issue, Hire is the code, suit for my needs & modified for a bit more advanced use.

This lists all files in your dir in a treeview & selects 1 tree item. Better you run this from a folder with at least 2 files in it.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#include <StaticConstants.au3>
#include <Array.au3>

Opt("GUIOnEventMode", 1); Change to OnEvent mode

Global $Form1
Global $generalitem

_GUIMAKE()
;~ ==========================================================================
Func _Fill_Tree()
    
    Global $avArray[1][2] ;1 Row & 4 columns at the beginning 
    Global $Currently_Selected
    
    $search = FileFindFirstFile("*.*")  

    For $x = 1 To 99999999999999999999999
        $file = FileFindNextFile($search) 
        If @error Then ExitLoop
        
        $iRow = UBound($avArray)    ;add Rows
        $iCol = UBound($avArray, 2) ;Add Columns
        
        ReDim $avArray[$iRow + 1][$iCol]    ; add more rows +1 ; ReDim $avArray[$iRow + 1][$iCol + 1] - Adds both
            
        $file =  StringTrimRight($file,4) ; remove file extension
            
        $avArray[$x][0] = GUICtrlCreateTreeViewItem($file, $generalitem) ; make treeitem
        GUICtrlSetOnEvent(-1, "_Unselect")
        
        $avArray[$x][1] = $file ; add treeitem name to array
            
        If $avArray[$x][0] = 5 Then 
            GUICtrlSetBkColor(-1, 0xd9d9d9) ;select Group
            $Currently_Selected = $avArray[$x][1]
        EndIf
                
    Next
    FileClose($search)
    _ArrayDisplay($avArray, "Class List of Active Window")
    GUICtrlSetState($generalitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON)); Expand the "General"-item and paint in bold
EndFunc  ;==>_Fill_Tree
;~ ==========================================================================
Func _Unselect()
    For $i = 1 To UBound($avArray) - 1
        If $avArray[$i][1] = $Currently_Selected Then
            GUICtrlSetBkColor($avArray[$i][0], $GUI_BKCOLOR_TRANSPARENT); "Unselect" tree sub item 2?
            ExitLoop
        EndIf
    Next
EndFunc  ;==>_Unselect
;~ ==========================================================================


Func _CLOSEClicked()
    Exit
EndFunc  ;==>_CLOSEClicked

Func _GUIMAKE()
    $Form1 = GUICreate("", 300, 377, 313, 365)
    $iTVStyle = BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS)
    $treeview = GUICtrlCreateTreeView(2, 40, 161, 227, $iTVStyle, $WS_EX_CLIENTEDGE)
    $generalitem = GUICtrlCreateTreeViewItem("General", $treeview)
    GUICtrlSetColor(-1, 0x0000C0)
    _Fill_Tree()
    GUISetState(@SW_SHOW)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_CLOSEClicked")
EndFunc  ;==>_GUIMAKE

While 1
    Sleep(1000)
WEnd
Edited by goldenix
My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list]
Link to comment
Share on other sites

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