Jump to content
Sign in to follow this  
PcExpert

Add info to listview

Recommended Posts

PcExpert

Hi all,

I want to make a program that reads info out an ini file and then add it to the listview. see my cofe below:

#Include <GuiListView.au3>
#include <GUIConstants.au3>
#include <file.au3>

$gui_incident_overview = GUICreate("Incidenten Overzicht", 600, 450)  ; will create a dialog box that when displayed is centered
$incident_overview_listview = GUICtrlCreateListView ("Klantnummer  |Probleem ID |Omschrijving ",10,10,550,300)
GUICtrlCreateLabel("Klantnummer", 12, 315)
$incident_overview_klant = GUICtrlCreateInput("", 10, 335, 100, 20)
$incident_overview_search = GUICtrlCreateButton("Zoeken", 12, 410, 100, 40)
$incident_overview_exit = GUICtrlCreateButton("Venster sluiten", 486, 410, 100, 40)     ; will display an empty dialog box
GUISetState(@SW_SHOW, $gui_incident_overview)

 

While 1
    $msg = GUIGetMsg()
    Select
  Case $msg = $incident_overview_search
   incident_overview_listpop()
  Case $msg = $GUI_EVENT_CLOSE
   Exitloop
 EndSelect
WEnd 

Func incident_overview_listpop()

$incident_overview_read = GUICtrlRead($incident_overview_klant)

If $incident_overview_read = "" Then
 
$incident_overview_filesArray=_FileListToArray("klanten\","*.ini")

For $b=1 To $incident_overview_filesArray[0]
 $incident_overview_klantnummer = StringTrimRight($incident_overview_filesArray[$b], 4)

   $incident_overview_Sections = IniReadSectionNames("klanten\" & $incident_overview_filesArray[$b])
 
   If @error Then 
    MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
    For $i = 1 To $incident_overview_Sections[0]
        If $incident_overview_Sections[$i] = "gegevens"Then
  Else
  
 $incident_overview_probdesc = IniRead("klanten\" & $incident_overview_filesArray[$i], $incident_overview_Sections[$i], "omschrijving", "")
 GUICtrlCreateListViewItem($incident_overview_klantnummer & "|" & $incident_overview_Sections[$i] & "|" & $incident_overview_probdesc, $incident_overview_listview) 
  EndIf
    Next
 EndIf

Next
EndIf
EndFunc

What I want this code to do is the following: read every file, if the inputbox is empty, then read every section name except if the name of the section is 'gegevens', then, from every section, read the problem description. And finally add the information to the listview.

But the code doesnt seem to do its work correctly:(. Could someone please explain me why?

Thanks!

Edited by PcExpert

Share this post


Link to post
Share on other sites
Aceguy

how does your inifile look.??? post example please.

but this is how you do what you want.... ***change path to your inifile***

$inifile = "klanten\test.ini"

$sec = IniReadSectionNames($inifile)

For $c1 = 1 To $sec[0]
    $ini = IniReadSection($inifile, $sec[$c1])
    For $c2 = 1 To $ini[0][0]
        ConsoleWrite($ini[$c2][1] & @LF)
    Next
Next
Edited by Aceguy

Share this post


Link to post
Share on other sites
PcExpert

oops, sorry, I forgot to post it. This is a inifile:

[Gegevens]

naam=MY NAME

adres=MY ADDRESS

postcode=MY POSTALCODE

woonplaats=MY CITY

email=MYEMAIL@ISP.TLD

telefoon=0000-00000

[663461]

omschrijving=test

probleem=test volledig

The filename of the ini is a random generated numer with 6 numbers in total.

Edited by PcExpert

Share this post


Link to post
Share on other sites
Danny35d

Looking at your code inside incident_overview_listpop() function change the following line

$incident_overview_read = GUICtrlRead($incident_overview_search)

To

$incident_overview_read = GUICtrlRead($incident_overview_klant)


AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites
PcExpert

It still doesnt return any results in the listview, I modified the code from my first post, so it is right now. Although it seems that the script is doing something as I cannot close the GUI once I pressed the button, but no results are coming :).

Share this post


Link to post
Share on other sites
Danny35d

It still doesnt return any results in the listview, I modified the code from my first post, so it is right now.

I copied and pasted the code from the first post and work fine in my computer. Do you have klanten folder at the same directory where you are running your script?

Although it seems that the script is doing something as I cannot close the GUI once I pressed the button, but no results are coming :).

To be able to close your GUI by pressing the button you have to change

Case $msg = $GUI_EVENT_CLOSE

To

Case $msg = $GUI_EVENT_CLOSE Or $msg = $incident_overview_exit

Note:

I just noticed your script failed if you only have one .ini file. You need to change this line

$incident_overview_probdesc = IniRead("klanten\" & $incident_overview_filesArray[$i], $incident_overview_Sections[$i], "omschrijving", "")

To

$incident_overview_probdesc = IniRead("klanten\" & $incident_overview_filesArray[$b], $incident_overview_Sections[$i], "omschrijving", "")

Edited by Danny35d

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites
PcExpert

Yesterday I did a stresstest for another applicatyion I wrote, it succeeded, but in my ' klanten' directory there were more than 18000 files to index. But that application passed the test. I thought it might have something to do with the amount of files, so I deleted them all, and I kept one, but even then, I dont see anything in the listview. :) The script is in the same directory as the folder 'klanten' and I did all modification as suggested.

Edited by PcExpert

Share this post


Link to post
Share on other sites
Danny35d

Did you change the code lines below? When I ran you script with one .ini file I get the message Array variable has incorrect number.

$incident_overview_probdesc = IniRead("klanten\" & $incident_overview_filesArray[$i], $incident_overview_Sections[$i], "omschrijving", "")

To

$incident_overview_probdesc = IniRead("klanten\" & $incident_overview_filesArray[$b], $incident_overview_Sections[$i], "omschrijving", "")


AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites
PcExpert

Yes I did. But still didnt work To be sure f I have the right code now:

#Include <GuiListView.au3>
#include <GUIConstants.au3>
#include <file.au3>

$gui_incident_overview = GUICreate("Incidenten Overzicht", 600, 450)  ; will create a dialog box that when displayed is centered
$incident_overview_listview = GUICtrlCreateListView ("Klantnummer  |Probleem ID |Omschrijving ",10,10,550,300)
GUICtrlCreateLabel("Klantnummer", 12, 315)
$incident_overview_klant = GUICtrlCreateInput("", 10, 335, 100, 20)
$incident_overview_search = GUICtrlCreateButton("Zoeken", 12, 410, 100, 40)
$incident_overview_exit = GUICtrlCreateButton("Venster sluiten", 486, 410, 100, 40)     ; will display an empty dialog box
GUISetState(@SW_SHOW, $gui_incident_overview)

 

While 1
    $msg = GUIGetMsg()
    Select
  Case $msg = $incident_overview_search
   incident_overview_listpop()
  Case $msg = $GUI_EVENT_CLOSE
   Exitloop
 EndSelect
WEnd 

Func incident_overview_listpop()

$incident_overview_read = GUICtrlRead($incident_overview_klant)

If $incident_overview_read = "" Then
 
$incident_overview_filesArray=_FileListToArray("klanten\","*.ini")

For $b=1 To $incident_overview_filesArray[0]
 $incident_overview_klantnummer = StringTrimRight($incident_overview_filesArray[$b], 4)

   $incident_overview_Sections = IniReadSectionNames("klanten\" & $incident_overview_filesArray[$b])
 
   If @error Then 
    MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
    For $i = 1 To $incident_overview_Sections[0]
        If $incident_overview_Sections[$i] = "gegevens" Then
  Else
  
 $incident_overview_probdesc = IniRead("klanten\" & $incident_overview_filesArray[$b], $incident_overview_Sections[$i], "omschrijving", "") 
 GUICtrlCreateListViewItem($incident_overview_klantnummer & "|" & $incident_overview_Sections[$i] & "|" & $incident_overview_probdesc, $incident_overview_listview) 
  EndIf
    Next
 EndIf

Next
EndIf
EndFunc
Edited by PcExpert

Share this post


Link to post
Share on other sites
PcExpert

I think it stops because of the if-else loop. I commentred it now, this is the code:

#Include <GuiListView.au3>
#include <GUIConstants.au3>
#include <file.au3>

$gui_incident_overview = GUICreate("Incidenten Overzicht", 600, 450)  ; will create a dialog box that when displayed is centered
$incident_overview_listview = GUICtrlCreateListView ("Klantnummer  |Probleem ID |Omschrijving ",10,10,550,300)
GUICtrlCreateLabel("Klantnummer", 12, 315)
$incident_overview_klant = GUICtrlCreateInput("", 10, 335, 100, 20)
$incident_overview_search = GUICtrlCreateButton("Zoeken", 12, 410, 100, 40)
$incident_overview_exit = GUICtrlCreateButton("Venster sluiten", 486, 410, 100, 40)     ; will display an empty dialog box
GUISetState(@SW_SHOW, $gui_incident_overview)

 

While 1
    $msg = GUIGetMsg()
    Select
  Case $msg = $incident_overview_search
   incident_overview_listpop()
  Case $msg = $GUI_EVENT_CLOSE
   Exitloop
 EndSelect
WEnd 

Func incident_overview_listpop()

$incident_overview_read = GUICtrlRead($incident_overview_klant)

If $incident_overview_read = "" Then
 
$incident_overview_filesArray = _FileListToArray(@ScriptDir & "\klanten\", "*.ini", 1)

For $b=1 To $incident_overview_filesArray[0]
 $incident_overview_klantnummer = StringTrimRight($incident_overview_filesArray[$b], 4)

   $incident_overview_Sections = IniReadSectionNames("klanten\" & $incident_overview_filesArray[$b])
 
   If @error Then 
    MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
    For $i = 1 To $incident_overview_Sections[0]
     ;   If $incident_overview_Sections[$i] = "gegevens" Then
  ;Else
  
 $incident_overview_probdesc = IniRead("klanten\" & $incident_overview_filesArray[$b], $incident_overview_Sections[$i], "omschrijving", "") 
 GUICtrlCreateListViewItem($incident_overview_klantnummer & "|" & $incident_overview_Sections[$i] & "|" & $incident_overview_probdesc, $incident_overview_listview) 
 ; EndIf
    Next
 EndIf

Next
EndIf
EndFunc

As you can see, I commented the part where it checks if the section name is ' gegevens'. I think that it hangs in the if-else loop, because when its commented like now, it works fine, any way to solve this? I just dont want the section 'gegevens' to show up in the listview.

Edited by PcExpert

Share this post


Link to post
Share on other sites
PcExpert

Thanks all for the help provided. It works like a charm now!:)

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  

×