Jump to content

Recommended Posts

Posted

Hi,

Since a long time I read lots of topics on this forum as a visitor and found most of the searched answers; thank you!

Now I'm out of topic to read about what I'm looking for (or just not found), I come to ask for some help about my script.

I'm new and not completely sure if the topic is at the correct place.

  • Description of the script: this script create 3 control lists
    • The first list displays years, those years are folders, in each, a ".ini" file named with months contains data (id of bills)
    • The second list displays months, those months are ".ini" files (indicated here up) containing data (id of bills)
    • The third list displays bills, those bills are ".ini" files containing data
  • Folders & files structure
    • root folder:
      • main.au3 (Autoit script)
      • Data (folder):
        • Bills (folder):
          • ".ini" files containing data
        • Budgets (folder):
          • 2021 (folder)
            • ".ini" files named with months and containing data (id of bills)
          • 2022 (folder)
            • empty
          • 2023 (folder)
            • empty
  • How running program works
    • A year is selected and months linked to this year are listed in the second list
    • Then a month is selected and bills linked to this month are listed in the last list
  • My problem
    • When I've selected a month, bills display, then I select another year, the last bills stay visible in the list, it should disapear

The question is, what do I miss to hide/delete the bills list when another selection starts, or, where is the mistake?

Here is the code:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <GuiListView.au3>

Opt('MustDeclareVars', 1)
Opt('GUIOnEventMode', 1)

Global $ArrayDataBudgetList[12], $ArrayDataBillList[200], $ArrayDataYearList[100]
Global $FormHome
Global $GroupBanner, $GroupFunctionsArea
Global $LabelProgramTitle, $LabelTest
Global $ButtonNewBudget, $ButtonNewBill, $ButtonEditBill
Global $ListBudget, $ListBill, $ListYear, $idItem[200], $selectedYear, $selectedBudget
Global $nMsg, $MsgBoxQuit
Global $iniBudget, $iniBill

Main()

Func Main()
   CreateMainWindow()
   LaunchDisplayFromYear()
   While 1
      Sleep(10)
   WEnd
EndFunc

Func On_Close_Main()
   $MsgBoxQuit = MsgBox (4, '/!\QUIT/!\'' ,'Are you sure you want to quit?')
   If $MsgBoxQuit = 6 Then
      Exit ;answer is YES
   EndIf
EndFunc

Func LaunchDisplayFromYear()
   _GUICtrlListView_DeleteAllItems($ListYear)
   $ArrayDataYearList = GetDataYearList()
   FillYearsList()
EndFunc

Func DisplayBudgets()
   _GUICtrlListView_DeleteAllItems($ListBudget) ;Free space to display next bill list
   $selectedYear = StringTrimRight(GUICtrlRead(GUICtrlRead($ListYear)), 1)
   $ArrayDataBudgetList = GetDataBudgetList()
   FillBudgetsList()
EndFunc

Func DisplayBills()
   _GUICtrlListView_DeleteAllItems($ListBill) ;Free space to display next bills
   $selectedBudget = StringTrimRight(GUICtrlRead(GUICtrlRead($ListBudget)), 1)
   GetDataBillList()
   FillBillsList()
EndFunc

Func FillYearsList()
   For $i = 1 TO UBound($ArrayDataYearList, $UBOUND_ROWS)-1 Step 1
      If $ArrayDataYearList[$i] <> '' Then
         $idItem[$i] = GUICtrlCreateListViewItem($ArrayDataYearList[$i], $ListYear)
         GUICtrlSetOnEvent(-1, 'DisplayBudgets')
      EndIf
   Next
EndFunc

Func FillBudgetsList()
   For $i = 1 TO UBound($ArrayDataBudgetList, $UBOUND_ROWS)-1 Step 1 ;Fill list of budgets
      If $ArrayDataBudgetList[$i] <> '' Then
         $idItem[$i] = GUICtrlCreateListViewItem($ArrayDataBudgetList[$i], $ListBudget)
         GUICtrlSetOnEvent(-1, 'DisplayBills')
      EndIf
   Next
EndFunc

Func FillBillsList()
   For $i = 1 TO UBound($ArrayDataBillList, $UBOUND_ROWS)-1 Step 1
      If $ArrayDataBillList[$i] <> '' Then
         $idItem[$i] = GUICtrlCreateListViewItem($ArrayDataBillList[$i], $ListBill)
      EndIf
   Next
EndFunc

Func GetDataYearList()
   If FileExists('./Data/Budgets') Then
      Return _FileListToArray('./Data/Budgets/')
   EndIf
EndFunc

Func GetDataBudgetList()
   If FileExists('./Data/Budgets/' & $selectedYear) Then
      Return _FileListToArray('./Data/Budgets/' & $selectedYear & '/')
   EndIf
EndFunc

Func GetDataBillList()
   If $selectedBudget <> Null Then
      For $i = 1 TO UBound($ArrayDataBillList, $UBOUND_ROWS)-1 Step 1
         If FileExists('./Data/Budgets/' & $selectedYear & '/' & $selectedBudget) Then
            Local $id = IniRead('./Data/Budgets/' & $selectedYear & '/' & $selectedBudget, '1-' & $i, 'BillsId', '')
         EndIf
         If $id <> '' Then
            If FileExists('./Data/Bills/' & $id & '.ini') Then
               _ArrayInsert($ArrayDataBillList, $i, IniRead('./Data/Bills/' & $id & '.ini', '1', 'CompanyName', ''))
            EndIf
         EndIf
      Next
   EndIf
EndFunc

Func CreateMainWindow()
   #Region ### START Koda GUI section ### Form=C:\Users\Cédric\Desktop\GoogleDrive\ME\Projects\1_ON_FinanceApp\home.kxf
   $FormHome = GUICreate('Home', 1520, 1000, 200, 10)
   GUISetOnEvent($GUI_EVENT_CLOSE, 'On_Close_Main')
   $GroupBanner = GUICtrlCreateGroup('', 10, 10, 1500, 100)
   $LabelProgramTitle = GUICtrlCreateLabel('programTitle', 32, 24, 62, 17)
   $ListYear = GUICtrlCreateListView('Year', 10, 120, 250, 800)
   _GUICtrlListView_SetColumnWidth($ListYear, 0, 246)
   $ListBudget = GUICtrlCreateListView('Budgets', 270, 120, 250, 800)
   _GUICtrlListView_SetColumnWidth($ListBudget, 0, 246)
   $ListBill = GUICtrlCreateListView('Bills|Tests', 530, 120, 720, 800)
   $GroupFunctionsArea = GUICtrlCreateGroup('', 1260, 114, 250, 806)
   $ButtonNewBudget = GUICtrlCreateButton('New Budget', 1270, 130, 230, 30)
   $ButtonNewBill = GUICtrlCreateButton('New Bill', 1270, 170, 230, 30)
   $ButtonEditBill = GUICtrlCreateButton('Edit Bill', 1270, 210, 230, 30)
   GUISetState(@SW_SHOW)
   #EndRegion ### END Koda GUI section ###
EndFunc

 

Within the folowing folders I've created some test files with the indicated content:

  • in ./Data/Bills/2968108.ini
    [1]
    CompanyName=SwissCaution
    DueDate=31.12.2020
    Amount=126.5
    Splited=0
    Status=Active
  • in ./Data/Bills/F-206-2543-18.ini
    [1]
    CompanyName=Company Test
    DueDate=31.12.2020
    Amount=37.65
    Splited=0
    Status=Active
  • in ./Data/Budgets/2021/january.ini
    [1]
    Month=january
    Year=2021
    Status=Active
    [1-1]
    BillsId=2968108
    [1-2]
    BillsId=F-206-2543-18

 

Do you have any idea?

 

  • Moderators
Posted

Moved to the appropriate forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

This should do it:

Func DisplayBills()
   _GUICtrlListView_DeleteAllItems($ListBill) ;Free space to display next bills
   $selectedBudget = StringTrimRight(GUICtrlRead(GUICtrlRead($ListBudget)), 1)
   $ArrayDataBillList=""
   Global $ArrayDataBillList[200]
   GetDataBillList()
   FillBillsList()
EndFunc

You have an array which is not cleared, and therefore all items in it are added to the Listview.

Some of my script sourcecode

Posted

Hi, Dan_555,

Thanks for your answer.

I tried this, it doesn't work.

I've linked print screen with a selected year and month that contains bills, (picture test-ok.png), and another with a selected year that contains nothing the bill list stay visible even no month is selected (picture test-nok.png).

test-nok.png

test-ok.png

Posted

Replace those 2 func with this :

Func DisplayBudgets()
   _GUICtrlListView_DeleteAllItems($ListBudget) ;Free space to display next bill list
   _GUICtrlListView_DeleteAllItems($ListBill) ;Free space to display next bills
   $selectedYear = StringTrimRight(GUICtrlRead(GUICtrlRead($ListYear)), 1)
   $ArrayDataBudgetList = GetDataBudgetList()
   FillBudgetsList()
EndFunc

Func DisplayBills()
   _GUICtrlListView_DeleteAllItems($ListBill) ;Free space to display next bills
   Global $ArrayDataBillList[200]
   $selectedBudget = StringTrimRight(GUICtrlRead(GUICtrlRead($ListBudget)), 1)
   GetDataBillList()
   FillBillsList()
EndFunc

 

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
×
×
  • Create New...