AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Load datafile into Listview

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Carnifex



Joined: 10 Nov 2009
Posts: 9

PostPosted: Thu Nov 12, 2009 11:02 pm    Post subject: Load datafile into Listview Reply with quote

I'm trying to write a program to keep track of my finances.

I made a simple GUI with the function to save added data in two different ListViews (one for income, one for outgoing(?))

The following code does not correctly load the data back into the listview.

Code:

ButtonLoadData: ;On button click
Gui, ListView, Inc ;Set focus on ListView with name Inc

getIndex() ;Call getIndex function

Loop, read, %SaveFile% ;loop-read file
{
   If A_Index <= (resultInc // 3) ;if the index is equal or smaller than the total divided by 3
   {
      LV_Add("", A_LoopReadLine, "", "") ;Add line to first column
   }
   Else if A_Index > (resultInc // 3) && A_Index <= (resultInc - (resultInc // 3)) ;if the index is larger than the total divided by 3 and equal to or smaller
                                                                                   ;than the total minus the total divided by 3
   {
      LV_Add("", "", A_LoopReadLine, "") ;Add line to second column
   }
   Else ;if index bigger than all that until eof reached
   {
      LV_Add("", "", "", A_LoopReadLine) ;Add line to third column
   }
}
Return

;------------------------------------------------------------------------

getIndex()
{
Loop, read, %SaveFile% ;loop-read file
   resultInc := A_Index ;save last index number to variable
Return
}


What it does, is it places all data from the file into the second column in my ListView.

Is there an easier way to retrieve data from a file and get them into the right columns ? (maybe saving the data differently in the first place?)
It currently just saves all columns in one row into a textfile. That's why I divide by 3, to split the colums.

Also notice this is just the part for the Income.
Back to top
View user's profile Send private message
Carnifex



Joined: 10 Nov 2009
Posts: 9

PostPosted: Fri Nov 13, 2009 1:34 am    Post subject: Reply with quote

I made an easier version, but it still gives the same result: (I also changed the way the script saves the data to the file.

Maybe there's a way to save the column data to a text file using tab delimiters? So that it can read from the file using those delimiters?

Code:

ButtonLoadData: ;On button click
Gui, ListView, Inc ;Set focus on ListView with name Inc

Loop, Read, %SaveFile% ;loop-read file
{
   StringSplit, incArray, A_LoopReadLine, `, ;StringSplit into an array
}

countInc = %incArray0% ;Saving the objectcount in the array to a variable

Loop, %countInc% ;looping through the array
{
   resultInc := incArray%A_Index% ;Point current object to a variable
   
   If A_Index <= (countInc // 3) ;Same code as my other solution
   {
      LV_Add("", resultInc, "", "")
   }
   Else if A_Index > (countInc // 3) && A_Index <= (countInc - (countInc // 3))
   {
      LV_Add("", "", resultInc, "")
   }
   Else
   {
      LV_Add("", "", "", resultInc)
   }
}
Return
Back to top
View user's profile Send private message
Carnifex



Joined: 10 Nov 2009
Posts: 9

PostPosted: Fri Nov 13, 2009 3:13 am    Post subject: Reply with quote

Fixed it !

Code:

Gui, ListView, Inc
Loop, Read, %SaveFileInc%
{
   Loop, parse, A_LoopReadLine, `,
   {
      if A_Index = 1
      {
         LV_Add("", "", "", "")
         LV_Modify(x, "Col1", A_LoopField)
      }
      else if A_Index = 2
      {
         LV_Modify(x, "Col2", A_LoopField)
      }
      else if A_Index = 3
      {
         LV_Modify(x, "Col3", A_LoopField)
         x += 1
      }
   }
}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group