Jump to content

[Solved] I cant find why my script is not showing all ini file data in treeview while it is in the other file.


Recommended Posts

Good day to you all.
I hope that i a m in the right section this time.

I am still working on my image snipper.
I had seen two tutorials on it and am combining both of them.
The file what Dos place the whole ini in the tree is inireader fromdany.au3.
And the Test.aur is the one i want it to work in.
I have bin holding them on two screens to compare the script pf the functions and cant see the thing casing is.
I am new to Autoit my self.

This is file Test.au3 That i want to get working

;*****************************************
;Test.au3 by garguza
;Created with ISN AutoIt Studio v. 1.11
;*****************************************
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <GuiButton.au3>
#include <GuiConstants.au3>
#include <file.au3>

Global $testing = 0

GUICreate("My GUI with treeview", 350, 215)

Local $idTreeview = GUICtrlCreateTreeView(6, 6, 100, 150, BitOR($TVS_HASLINES, $TVS_HASBUTTONS, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
Local $idGeneralitem = GUICtrlCreateTreeViewItem("General", $idTreeview)
GUICtrlSetColor(-1, 0x0000C0)
Local $idDisplayitem = GUICtrlCreateTreeViewItem("Display", $idTreeview)
GUICtrlSetColor(-1, 0x0000C0)
Local $idAboutitem = GUICtrlCreateTreeViewItem("About", $idGeneralitem)
Local $idCompitem = GUICtrlCreateTreeViewItem("Computer", $idGeneralitem)
GUICtrlCreateTreeViewItem("User", $idGeneralitem)
GUICtrlCreateTreeViewItem("Resolution", $idDisplayitem)
GUICtrlCreateTreeViewItem("Other", $idDisplayitem)

Local $idStartlabel = GUICtrlCreateLabel("Image Snipper", 190, 90, 100, 20)
Local $idAboutlabel = GUICtrlCreateLabel("This little scripts demonstates the using of a treeview-control.", 190, 70, 100, 60)
GUICtrlSetState(-1, $GUI_HIDE)     ; Hides the "aboutlabel"-text during initialization
Local $idCompinfo = GUICtrlCreateLabel("Name:" & @TAB & @ComputerName & @CRLF & "OS:" & @TAB & @OSVersion & @CRLF & "SP:" & @TAB & @OSServicePack, 120, 30, 200, 80)
GUICtrlSetState(-1, $GUI_HIDE)     ; Hides the "compinfo"-text during initialization



; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>  Adapted text Starts Heare <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#cs
The part of the adapted text is from the file i included.
And the art thing is, in that file it works.
It shows the total ini in the gui.

#ce

Dim $e, $i, $var, $file, $TreeView, $idTreeView1, $var2, $idTreeView2
Dim $idTreeView3, $test1, $varx
Dim $var, $file, $x
$file = @ScriptDir & "\imige_file_data2.ini"

Local $idImageitem = GUICtrlCreateTreeViewItem("Image", $idTreeview) ; The holder  fore the ini file in the tree $idTreeview is linkt with line 19
GUICtrlSetColor(-1, 0x0000C0)

;_IniReadInfo()
_IniGetSectionNames()
GUISetState()
Func _IniGetSectionNames()
    $varx = IniReadSectionNames($file)
    If @error Then
        MsgBox(4096, "", "Error occured, probably no INI file.")
    Else
        For $x = 1 To $varx[0]
            ;MsgBox(4096, "", $varx[$x])
            _IniReadInfo($varx[$x])
        Next
    EndIf
EndFunc   ;==>_IniGetSectionNames

Func _IniReadInfo($sSection)
    Dim $sValue
    $var = IniReadSection($file, $sSection)
    If @error Then
        MsgBox(4096, "", "Error occured, probably no INI file.")
    Else
        $idTreeView2 = GUICtrlCreateTreeViewItem($sSection, $idImageitem) ; This $idImageitem is linkt to line 51
        For $i = 1 To $var[0][0]
            $TreeView3 = GUICtrlCreateTreeViewItem($var[$i][0], $idTreeView2)
            $sValue = StringSplit($var[$i][1], '|')
            For $x = 1 To $sValue[0]
                If $sValue[$x] <> '' Then $idTreeView4 = GUICtrlCreateTreeViewItem($sValue[$x], $idTreeView3)               
            Next
        Next
    EndIf
EndFunc   ;==>_IniReadInfo

; >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>  Adapted text Stops Heare <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<



GUICtrlCreateLabel("", 0, 170, 350, 2, $SS_SUNKEN)
Local $idTogglebutton = GUICtrlCreateButton("&Toggle", 35, 185, 70, 20)
Local $idInfobutton = GUICtrlCreateButton("&Info", 105, 185, 70, 20)
Local $idStatebutton = GUICtrlCreateButton("Col./Exp.", 175, 185, 70, 20)
Local $idCancelbutton = GUICtrlCreateButton("&Cancel", 245, 185, 70, 20)

GUICtrlSetState($idGeneralitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))     ; Expand the "General"-item and paint in bold
GUICtrlSetState($idDisplayitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))     ; Expand the "Display"-item and paint in bold

GUISetState(@SW_SHOW)

Local $idMsg, $idItem, $hItem, $sText
; Loop until the user exits.
While 1
    $msg = GUIGetMsg()
    $idMsg = GUIGetMsg()
    Select
        Case $idMsg = $idCancelbutton Or $idMsg = $GUI_EVENT_CLOSE
            ExitLoop

        Case $idMsg = $idTogglebutton     ; Toggle the bold painting
            If BitAND(GUICtrlRead($idGeneralitem), $GUI_DEFBUTTON) Then
                GUICtrlSetState($idGeneralitem, 0)
                GUICtrlSetState($idDisplayitem, 0)
                
                GUICtrlSetState($idImageitem, 0)
            Else
                GUICtrlSetState($idGeneralitem, $GUI_DEFBUTTON)
                GUICtrlSetState($idDisplayitem, $GUI_DEFBUTTON)
                
                GUICtrlSetState($idImageitem, $GUI_DEFBUTTON)
            EndIf

        Case $idMsg = $idInfobutton
            $idItem = GUICtrlRead($idTreeview)     ; Get the controlID of the current selected treeview item
            If $idItem = 0 Then
                MsgBox($MB_SYSTEMMODAL, "TreeView Demo", "No item currently selected")
            Else
                $sText = GUICtrlRead($idItem, 1)     ; Get the text of the treeview item
                If $sText == "" Then
                    MsgBox($MB_SYSTEMMODAL, "Error", "Error while retrieving infos about item")
                Else
                    MsgBox($MB_SYSTEMMODAL, "TreeView Demo", "Current item selected is: " & $sText)
                EndIf
            EndIf

        Case $idMsg = $idStatebutton
            $idItem = GUICtrlRead($idTreeview)
            If $idItem > 0 Then
                $hItem = GUICtrlGetHandle($idItem)
                GUICtrlSendMsg($idTreeview, $TVM_EXPAND, $TVE_TOGGLE, $hItem)
            EndIf

            ; The following items will hide the other labels (1st and 2nd parameter) and then show the 'own' labels (3rd and 4th parameter)
        Case $idMsg = $idGeneralitem
            GUIChangeItems($idAboutlabel, $idCompinfo, $idStartlabel, $idStartlabel)

        Case $idMsg = $idAboutitem
            GUICtrlSetState($idCompinfo, $GUI_HIDE)
            GUIChangeItems($idStartlabel, $idStartlabel, $idAboutlabel, $idAboutlabel)

        Case $idMsg = $idCompitem
            GUIChangeItems($idStartlabel, $idAboutlabel, $idCompinfo, $idCompinfo)
    EndSelect
WEnd

GUIDelete()




Func GUIChangeItems($idHidestart, $idHideend, $idShowstart, $idShowend)
    Local $idX

    For $idX = $idHidestart To $idHideend
        GUICtrlSetState($idX, $GUI_HIDE)
    Next
    For $idX = $idShowstart To $idShowend
        GUICtrlSetState($idX, $GUI_SHOW)
    Next
EndFunc   ;==>GUIChangeItems

This is the Corect working code:

#include <GuiConstants.au3>
#include <file.au3>
#include <array.au3>
Dim $e, $i, $var, $file, $TreeView, $TreeView1, $var2, $TreeView2
Dim $TreeView3, $test1, $varx
Dim $var, $file, $x
$file = @ScriptDir & "\imige_file_data2.ini"

;If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000
GuiCreate("Form2", 420, 331, 430,346 ,BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
$TreeView1 = GUICtrlCreateTreeView(16, 16, 353, 217)

;_IniReadInfo()
_IniGetSectionNames()
GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
  ;;;
    EndSelect
WEnd
Exit

Func _IniGetSectionNames()
    $varx = IniReadSectionNames($file)
    If @error Then
        MsgBox(4096, "", "Error occured, probably no INI file.")
    Else
        For $x = 1 To $varx[0]
    ;MsgBox(4096, "", $varx[$x])
            _IniReadInfo($varx[$x])
        Next
    EndIf
EndFunc

Func _IniReadInfo($sSection)
    Dim $sValue
    $var = IniReadSection($file, $sSection)
    If @error Then
        MsgBox(4096, "", "Error occured, probably no INI file.")
    Else
        $TreeView2 = GUICtrlCreateTreeViewitem($sSection, $TreeView1)
        For $i = 1 To $var[0][0]
            $TreeView3 = GUICtrlCreateTreeViewItem($var[$i][0], $TreeView2)
            $sValue = StringSplit($var[$i][1], '|')
            For $x = 1 To $sValue[0]
                if $sValue[$x] <> '' Then $TreeView4 = GUICtrlCreateTreeViewitem($sValue[$x], $TreeView3)
            Next
        Next
    EndIf
EndFunc

I have placed a attachment wit both au3 files and the ini.
I stare me blind on it at the moment :(
Hope some one can point me in the right direction :)

Best Regards

 

Sorry, i am in the wrong forum To bad you cant move it your self :(

Test.au3 imige_file_data2.ini inireader fromdany.au3

Edited by ingosa
Typing Mistake in title
Link to post
Share on other sites
Func _IniReadInfo($sSection)
    Dim $sValue
    $var = IniReadSection($file, $sSection)
    If @error Then
        MsgBox(4096, "", "Error occured, probably no INI file.")
    Else
        $idTreeView2 = GUICtrlCreateTreeViewItem($sSection, $idImageitem) ; This $idImageitem is linkt to line 51
        For $i = 1 To $var[0][0]
            $TreeView3 = GUICtrlCreateTreeViewItem($var[$i][0], $idTreeView2)
            $sValue = StringSplit($var[$i][1], '|')
            For $x = 1 To $sValue[0]
                If $sValue[$x] <> '' Then $idTreeView4 = GUICtrlCreateTreeViewItem($sValue[$x], $idTreeView3)               
            Next
        Next
    EndIf
EndFunc   ;==>_IniReadInfo

Mine is also using '|', i had copy pased the whole code from the working one into the other.
Thats the art part.
I did alterd the vars to the one fore the test script, 

But thanks fore teh fast respond :)

Link to post
Share on other sites

Take care when manipulating ini file in windows.

Some applications are modifying the default format when you record any text file

You can set it here :

image.png.875e6610b2bb1a8c8a24e50ecc0d01d2.png

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

 

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

    No registered users viewing this page.

×
×
  • Create New...