Sign in to follow this  
Followers 0
Iznogoud

TreeView: Read variables from a txt file

29 posts in this topic

Is it possible to create a TreeView with item wich are read from a txt file?

I want to try to make a TreeView with A,B,C,D,E,F,G,H, etc. with customer names beneath the starting letter and combine this wich a application with specific internet information to start.

Example:

Customer: B, and i want to start remote support for an example

TreeView looks like:

B

- (customername wich starts with a B offcourse)

As soon as i click on the customers name some programm will start like Remote Desktop.

But it would be nice if the program reads the values from a txt file so i dont have to compile it every time i want to add a customer.

Is this easy for AutoIT noob to do with some help of you guys?

Share this post


Link to post
Share on other sites



If I were you I'd look at the following in the helpfile:

FileReadLine for reading out the customers' names

_FileCountLines for seeing the amount of lines

For for creating a loop to store the names in array

StringLeft for checking the customer's first letter

GuiCtrlCreateTreeViewItem for adding the names to the treeview.

If you still need help, let us know :D

Alzo


Don't take my pic to serious...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You Looked, but you did not see!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Share this post


Link to post
Share on other sites

For create treeview from text I'm using ini file. If you search treeview and ini file, you found a post with your answer !

Share this post


Link to post
Share on other sites

I was thinking of a ini file where eacht letter has his own section. I will search the forum for your post and look at the helpfile.

Share this post


Link to post
Share on other sites

I found a great post of Valuater: http://www.autoitscript.com/forum/index.ph...l=ini++treeview

This is the code from him:

Global $macrolist[10], $macrolistdata[50]
#include <GUIConstants.au3>
#Include <Constants.au3>
#include <array.au3>
; need this for my testing..... ok???
Dim $Location = "C:\Temp\sections.ini"
Dim $Location2 = "C:\Temp\pagedetails.ini"

;===================================> GUI <=======================================

GUICreate("Macro v1.0", 400, 460)
$filemenu = GUICtrlCreateMenu("File")
$optionsmenu = GUICtrlCreateMenu("Options")
$helpmenu = GUICtrlCreateMenu("?")
$fileitem = GUICtrlCreateMenuItem("Exit", $filemenu)
$button = GUICtrlCreateButton("New", 335, 15, 60)

$btnsave = GUICtrlCreateButton("Save", 335, 145, 60)


$treeview = GUICtrlCreateTreeView(6, 6, 200, 250, BitOR($tvs_hasbuttons, $tvs_haslines, $tvs_linesatroot, $tvs_disabledragdrop, $tvs_showselalways), $ws_ex_clientedge)
$sections = IniReadSectionNames($Location)
If @error Then
MsgBox(4096, "", "Error occured, probably no INI file.")
Else
For $i = 1 To $sections[0]
$keys = IniReadSection($Location, $sections[$i])
$item = GUICtrlCreateTreeViewItem($sections[$i], $treeview)
For $x = 1 To $keys[0][0]
GUICtrlCreateTreeViewItem($keys[$x][0], $item)
Next
Next
EndIf

GUISetState()
;================================> End GUI <======================================


While 1
$msg = GUIGetMsg()

Select
;Case $msg = -3 Or $msg = -1 Or $msg = $cancelbutton
Case $msg = $gui_event_close
ExitLoop
Case $msg = $button
Call("Set_PageDetails")

EndSelect

Sleep(10)

WEnd


; ------------------------------- Functions --------------------------------

Func Set_PageDetails()
; read the selection
$item1 = GUICtrlRead($treeview)
$item2 = GUICtrlRead($item1, 1)

; read the ini portion rerquested
$name = IniRead($Location2, $item2[0], "Name", "NotFound")
$page = IniRead($Location2, $item2[0], "Page", "NotFound")
$topic = IniRead($Location2, $item2[0], "Topic", "NotFound")
$status = IniRead($Location2, $item2[0], "UserStatus", "NotFound")
$editstatus = IniRead($Location2, $item2[0], "EditStatus", "NotFound")
$duedate = IniRead($Location2, $item2[0], "Due", "NotFound")

; display the info just read
GUICtrlCreateLabel("Assigned To: ", 10, 280, 100, 20, 0x1000)
GUICtrlCreateInput($name, 10, 300, 100, 20)
GUICtrlCreateLabel("Page #: ", 120, 280, 100, 20, 0x1000)
GUICtrlCreateInput($page, 120, 300, 100, 20)
GUICtrlCreateLabel("Topic: ", 10, 330, 100, 20, 0x1000)
GUICtrlCreateInput($topic, 10, 350, 100, 20)
GUICtrlCreateLabel("Status: ", 120, 330, 100, 20, 0x1000)
GUICtrlCreateInput($status, 120, 350, 100, 20)
GUICtrlCreateLabel("EditStatus: ", 10, 380, 100, 20, 0x1000)
GUICtrlCreateInput($editstatus, 10, 400, 100, 20)
GUICtrlCreateLabel("DUE: ", 120, 380, 100, 20, 0x1000)
GUICtrlCreateInput($duedate, 120, 400, 100, 20)
EndFunc;==>Set_PageDetails

Only i can't get the button NEW to work.

If i press it AutoIT give this error: Incorrect number of parameters in function call.:

$item2 = GUICtrlRead($item1, 1)

What am i doing wrong?

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

$item2 = GUICtrlRead($item1, 1)

requires the beta version

Thats weird, because i have Beta, I run in syntax check of Beta and this give no error, but if i run it in Beta i get that error.

My bad, it does run. Don't know what i did wrong but it works now. I will study the code ..... thx

Edited by Iznogoud

Share this post


Link to post
Share on other sites

I have one small question, i am doing something wrong but i can't find what.

If one of the treeviewitems are selected and you press a button, how can i read that value from the ini and use it later on in the script?

I know it has to be done with GuiCtrlRead() but i tried all the variables etc, but still it doesn't give me the values, only numbers.

What am i doing wrong?

Share this post


Link to post
Share on other sites

I think you are GuiCtrlReading the treeviewitem without the , 1 parameter, this returns the state ID of the selected treeview item, you need to use GuiCtrlRead($item, 1) to return the text of the selected item. Or even simpler: GuiCtrlRead($treeview, 1)

Alzo


Don't take my pic to serious...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You Looked, but you did not see!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Share this post


Link to post
Share on other sites

I think you are GuiCtrlReading the treeviewitem without the , 1 parameter, this returns the state ID of the selected treeview item, you need to use GuiCtrlRead($item, 1) to return the text of the selected item. Or even simpler: GuiCtrlRead($treeview, 1)

Alzo

In this test fase i want to see the value in a MsgBox so i can see if its returning the correct value, but i the variable is nothing, in other words i don't get an result.

I have adjusted the code alot to the only thing i need. This is my code at the moment:

#include <GUIConstants.au3>
#Include <Constants.au3>
#include <array.au3>

Dim $Location = "MSTSC.ini"
;===================================> GUI <=======================================

GUICreate("", 400, 508)
GUICtrlCreatePic("mstsc.jpg",0,0, 400,70)
GUISetBkColor (0xECE9D8)

$button = GUICtrlCreateButton("Ok", 75, 420, 100)

$treeview = GUICtrlCreateTreeView(6, 76, 388, 200, BitOR($tvs_hasbuttons, $tvs_haslines, $tvs_linesatroot, $tvs_disabledragdrop, $tvs_showselalways), $ws_ex_clientedge)

;===================================> Labels <====================================
$Gebruikersnaam=GUICtrlCreateLabel ("Gebruikersnaam :",50 ,320 ,85 ,20)
$Wachtwoord=GUICtrlCreateLabel ("Wachtwoord :",50 ,360 ,85 ,20)

;===================================> Input Fields <==============================
$GebruikersnaamValue=GuiCtrlCreateInput("",150, 318, 150, 20)
$WachtwoordValue=GuiCtrlCreateInput("",150, 358, 150, 20, $ES_PASSWORD)

;===================================> Read INI <==================================

$sections = IniReadSectionNames($Location)
If @error Then
MsgBox(4096, "", "Error occured, probably no INI file.")
Else
For $i = 1 To $sections[0]
$keys = IniReadSection($Location, $sections[$i])
$item = GUICtrlCreateTreeViewItem($sections[$i], $treeview)
For $x = 1 To $keys[0][0]
GUICtrlCreateTreeViewItem($keys[$x][0], $item)
Next
Next
EndIf

GUISetState()
;================================> End GUI <======================================
While 1
$msg = GUIGetMsg()

Select

    Case $msg = $gui_event_close
    ExitLoop

    Case $msg = $button
    msgbox(0,"Value", GUICtrlRead($treeview, 1))

EndSelect

Sleep(10)

WEnd

I have tried $treeview and $item, but both aren't working.

I have seen an example script where you can click on a treeview item and it automatic popups a msgbox. Do you know a way to create this so i can adjust it to my needs. In example if you click a treeviewitem it automatic fill the input fields with the correct information?

This is my example ini file

[A]
A1=A1
[B]
B2=B2
[C]
C1=C1
C2=C2

Share this post


Link to post
Share on other sites

You mean zoals this:

#include <GUIConstants.au3>
#Include <Constants.au3>
#include <array.au3>

Dim $Location = "MSTSC.ini"
;===================================> GUI <=======================================

GUICreate("", 400, 508)
GUICtrlCreatePic("mstsc.jpg",0,0, 400,70)
GUISetBkColor (0xECE9D8)

$button = GUICtrlCreateButton("Ok", 75, 420, 100)

$treeview = GUICtrlCreateTreeView(6, 76, 388, 200, BitOR($tvs_hasbuttons, $tvs_haslines, $tvs_linesatroot, $tvs_disabledragdrop, $tvs_showselalways), $ws_ex_clientedge)

;===================================> Labels <====================================
$Gebruikersnaam=GUICtrlCreateLabel ("Gebruikersnaam :",50 ,320 ,85 ,20)
$Wachtwoord=GUICtrlCreateLabel ("Wachtwoord :",50 ,360 ,85 ,20)

;===================================> Input Fields <==============================
$GebruikersnaamValue=GuiCtrlCreateInput("",150, 318, 150, 20)
$WachtwoordValue=GuiCtrlCreateInput("",150, 358, 150, 20, $ES_PASSWORD)

;===================================> Read INI <==================================

$sections = IniReadSectionNames($Location)
If @error Then
MsgBox(4096, "", "Error occured, probably no INI file.")
Else
For $i = 1 To $sections[0]
$keys = IniReadSection($Location, $sections[$i])
$item = GUICtrlCreateTreeViewItem($sections[$i], $treeview)
For $x = 1 To $keys[0][0]
GUICtrlCreateTreeViewItem($keys[$x][0], $item)
Next
Next
EndIf

GUISetState()
;================================> End GUI <======================================
While 1
$msg = GUIGetMsg()
$mouseinfo = GUIGetCursorInfo()

Select

    Case $msg = $gui_event_close
    ExitLoop

    Case $mouseinfo[4] = $treeview And $mouseinfo[2] = 1
        $value = GUICtrlRead(GUICtrlRead($treeview), 1)
        GUICtrlSetData($GebruikersnaamValue, $value[0])
        $pass = IniRead($Location, StringLeft($value[0], 1), $value[0], "Not Found")
        GUICtrlSetData($WachtwoordValue, $pass)

EndSelect

Sleep(10)

WEnd

What it does now is read the value from the selected treeview item whenever the treeview is clicked, and it reads the password from the ini as well and puts it into the password input.

Hope this is more or less what you're looking for :D

Alzo


Don't take my pic to serious...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You Looked, but you did not see!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Yes, you are the man :D

I was working on with the script and i added an extra input label. I am strugling to get the code working with "|" to read 2 or more values from the ini file.

This is my code so far:

#include <GUIConstants.au3>
#Include <Constants.au3>
#include <array.au3>

Dim $Location = "MSTSC.ini"
;===================================> GUI <=======================================

GUICreate("Verbinding met extern bureaublad", 400, 508)
GUICtrlCreatePic("mstsc.jpg",0,0, 400,70)
GUISetBkColor (0xECE9D8)

;===================================> Buttons <===================================
$Connectbutton = GUICtrlCreateButton("Verbinding maken", 30, 460, 150)
$Cancelbutton = GUICtrlCreateButton("Annuleren", 205, 460, 150)

;===================================> Create Treeview <===========================
$treeview = GUICtrlCreateTreeView(6, 76, 388, 200, BitOR($tvs_hasbuttons, $tvs_haslines, $tvs_linesatroot, $tvs_disabledragdrop, $tvs_showselalways), $ws_ex_clientedge)

;===================================> Labels <====================================
$IP=GUICtrlCreateLabel ("IP Adres :",50 ,320 ,85 ,20)
$Gebruikersnaam=GUICtrlCreateLabel ("Gebruikersnaam :",50 ,360 ,85 ,20)
$Wachtwoord=GUICtrlCreateLabel ("Wachtwoord :",50 ,400 ,85 ,20)

;===================================> Input Fields <==============================
$IPValue=GuiCtrlCreateInput("",150, 318, 150, 20)
$GebruikersnaamValue=GuiCtrlCreateInput("",150, 358, 150, 20)
$WachtwoordValue=GuiCtrlCreateInput("",150, 398, 150, 20);, $ES_PASSWORD

;===================================> Read INI <==================================

$sections = IniReadSectionNames($Location)
If @error Then
MsgBox(4096, "", "Error occured, probably no INI file.")
Else
For $i = 1 To $sections[0]
$keys = IniReadSection($Location, $sections[$i])
$item = GUICtrlCreateTreeViewItem($sections[$i], $treeview)
For $x = 1 To $keys[0][0]
GUICtrlCreateTreeViewItem($keys[$x][0], $item)
Next
Next
EndIf

GUISetState()
;================================> End GUI <======================================
While 1
$msg = GUIGetMsg()
$mouseinfo = GUIGetCursorInfo()

Select

    Case $msg = $gui_event_close
    ExitLoop

    Case $msg = $Connectbutton
    ExitLoop;Some action will come here instead of exitloop
    
    Case $msg = $Cancelbutton
    ExitLoop
    
    Case $mouseinfo[4] = $treeview And $mouseinfo[2] = 1
        $value = GUICtrlRead(GUICtrlRead($treeview), 1)
        GUICtrlSetData($GebruikersnaamValue, $value[0])
        $pass = IniRead($Location, StringLeft($value[0], 1), $value[0], "")
        GUICtrlSetData($WachtwoordValue, $pass)

EndSelect

Sleep(10)

WEnd

The ini fould must be change for an example in this:

[A]
Displayname=IPadress|Username|Password
[B]
Customername=xxx.xxx.xxx.xxx|Test|Password1

I know it has to be done with StringSplit for as far i know. What i am quesing is that i have to replace Stringleft with Stringsplit?

I will keep trying but if you have some info wich would help me i would thankfull.

zoals means like for the people who are reading it and think WTF?

Edited by Iznogoud

Share this post


Link to post
Share on other sites

Did what you were looking for (I think), note that this does assume that the "Gebruikersnaam" is an actual name.

#include <GUIConstants.au3>
#Include <Constants.au3>
#include <array.au3>

Dim $Location = @DesktopDir &  "\MSTSC.ini"
;===================================> GUI <=======================================

GUICreate("Verbinding met extern bureaublad", 400, 508)
GUICtrlCreatePic("mstsc.jpg",0,0, 400,70)
GUISetBkColor (0xECE9D8)

;===================================> Buttons <===================================
$Connectbutton = GUICtrlCreateButton("Verbinding maken", 30, 460, 150)
$Cancelbutton = GUICtrlCreateButton("Annuleren", 205, 460, 150)

;===================================> Create Treeview <===========================
$treeview = GUICtrlCreateTreeView(6, 76, 388, 200, BitOR($tvs_hasbuttons, $tvs_haslines, $tvs_linesatroot, $tvs_disabledragdrop, $tvs_showselalways), $ws_ex_clientedge)

;===================================> Labels <====================================
$IP=GUICtrlCreateLabel ("IP Adres :",50 ,320 ,85 ,20)
$Gebruikersnaam=GUICtrlCreateLabel ("Gebruikersnaam :",50 ,360 ,85 ,20)
$Wachtwoord=GUICtrlCreateLabel ("Wachtwoord :",50 ,400 ,85 ,20)

;===================================> Input Fields <==============================
$IPValue=GuiCtrlCreateInput("",150, 318, 150, 20)
$GebruikersnaamValue=GuiCtrlCreateInput("",150, 358, 150, 20)
$WachtwoordValue=GuiCtrlCreateInput("",150, 398, 150, 20);, $ES_PASSWORD

;===================================> Read INI <==================================

$sections = IniReadSectionNames($Location)
If @error Then
MsgBox(4096, "", "Error occured, probably no INI file.")
Else
For $i = 1 To $sections[0]
$keys = IniReadSection($Location, $sections[$i])
$item = GUICtrlCreateTreeViewItem($sections[$i], $treeview)
For $x = 1 To $keys[0][0]
GUICtrlCreateTreeViewItem($keys[$x][0], $item)
Next
Next
EndIf

GUISetState()
;================================> End GUI <======================================
While 1
$msg = GUIGetMsg()
$mouseinfo = GUIGetCursorInfo()

Select

    Case $msg = $gui_event_close
    ExitLoop

    Case $msg = $Connectbutton
    ExitLoop;Some action will come here instead of exitloop
    
    Case $msg = $Cancelbutton
    ExitLoop
    
    Case $mouseinfo[4] = $treeview And $mouseinfo[2] = 1
        $value = GUICtrlRead(GUICtrlRead($treeview), 1)
        GUICtrlSetData($GebruikersnaamValue, $value[0])
        $temp = IniRead($Location, StringLeft($value[0], 1), $value[0], "")
        $data = StringSplit($temp, "|")
        If IsArray($data) And $data[0] <> 1 Then
            GUICtrlSetData($IPValue, $data[1])
            GUICtrlSetData($GebruikersnaamValue, $data[2])
            GUICtrlSetData($WachtwoordValue, $data[3])
        EndIf
EndSelect

Sleep(10)

WEnd

New .ini:

[A]
Ad=IPadress|Ad|Password Ad
[B]
Bart=xxx.xxx.xxx.xxx|Bart|Password Bart

Alzo


Don't take my pic to serious...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You Looked, but you did not see!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

I am trying with this:

Case $msg = $Connectbutton
$value = GUICtrlRead(GUICtrlRead($treeview), 1)
$info = IniRead($Location, StringSplit($value[0], 1, "|"), $value[0], "")
MsgBox(1024, "Test", $info[1])
oÝ÷ Ù8b²­æ§zºè¯­«­¢+Ø)
ÍÀÌØíµÍôÀÌØí
½¹¹ÑÕÑѽ¸(ÀÌØíÙ±ÕôU%
ÑɱI¡U%
ÑɱI ÀÌØíÑÉ٥ܤ°Ä¤(ÀÌØí¥¹¼ôMÑÉ¥¹MÁ±¥Ð ÀÌØíÙ±ÕlÁt°Ä°ÅÕ½ÐíðÅÕ½Ðì¤)5Í  ½à ÄÀÈаÅÕ½ÐíQÍÐÅÕ½Ðì°ÀÌØí¥¹½lÅt¤

This is getting the Displayname, but how i adjust it i won't get the part with IPadress|Username|Password

I know this looks funny to you and you will have a laugh about this code, because i am doing something wrong in the big way. But the array stuff etc is still a blur for me. I have learned alot but still not enough.

Could you guys help me with my stupidity?

-edit-

ARG!

I was doing something wrong but was on the good way :D

The Displayname is not the same as the Username.

Example:

Displayname=IPadress|Username|Password

Iznogoud=xxx.xxx.xxx.xxx|Admin|whatever

Edited by Iznogoud

Share this post


Link to post
Share on other sites

Have a look at my solution, does what you wanted :D


Don't take my pic to serious...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You Looked, but you did not see!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Have a look at my solution, does what you wanted :wacko:

I did, I am, but still it doesn't fill the fields.

I tested with your ini:

[A]
Ad=IPadress|Ad|Password Ad
[B]
Iznogoud=IPadress|Admin|Password Admin

If i click on B then on Iznogoud it only filles the Username field.

In the mean while still looking :D

------------------------------------------------------------------------------------------

The edit wich you may not have seen in my last post:

ARG!

I was doing something wrong but was on the good way

The Displayname is not the same as the Username.

Example:

Displayname=IPadress|Username|Password

Iznogoud=xxx.xxx.xxx.xxx|Admin|whatever

Edited by Iznogoud

Share this post


Link to post
Share on other sites

Yes, of course, because Isnogoud doesn't start with a :D


Don't take my pic to serious...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You Looked, but you did not see!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Share this post


Link to post
Share on other sites

Yes, of course, because Isnogoud doesn't start with a :wacko:

whahahaha, didn't expect that one. :">

Didn't realize that i was checking for that to

Man, sometimes, i could hurt myself when i make these stupid mistakes. :D

Share this post


Link to post
Share on other sites

lol, happened to me too a lot of times :D


Don't take my pic to serious...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You Looked, but you did not see!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Share this post


Link to post
Share on other sites

2 Remarks:

If i select one for an exmple Ad and then i click on an other one then the inputfields stay unchanged.

And if you click somewhere in the TreeView area on the right so you dont click a item the username field is filled with a 0.

I tried alot of things to try to get rid of the 0 but it won't go away.

:D

Share this post


Link to post
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
Sign in to follow this  
Followers 0