KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

Fill listview from txt-file

 
Post new topic   Reply to topic    KiXforms Forum Index -> Starters Code Clinic
View previous topic :: View next topic  
Author Message
Patrick
KiXforms Novice
KiXforms Novice


Joined: 07 Jan 2006
Posts: 3
Location: Germany

PostPosted: Sun Jul 25, 2010 12:05 pm    Post subject: Fill listview from txt-file Reply with quote

Hy,

how to fill a listview from txt-file?

The content of the file shown below:

    item1;item2;item3;item4
    item1;;item3;item4


thx
Back to top
View user's profile Send private message
eriqjaffe
KiXforms Follower
KiXforms Follower


Joined: 16 Aug 2004
Posts: 19
Location: Arlington Heights, IL, USA

PostPosted: Fri Jul 30, 2010 2:57 pm    Post subject: Reply with quote

Something like this?

Code:
$ = SetOption("NoMacrosInStrings","ON")
$ = SetOption("NoVarsInStrings","ON")
$ = SetOption("WrapAtEOL","ON")
BREAK ON

$System = CreateObject("Kixtart.System")

$infile = ReadFile(@SCRIPTDIR+"\foo.txt")

$cols = 0

; read in text file and use that array to determine
; the number of columns that will be needed
for each $line in $infile
    $tmp = split($line,";")
    if ubound($tmp) > $cols
       $cols = ubound($tmp)
    endif
next

; exit script if there aren't any columns to create
if $cols = 0
   ? "No columns, aborting!"
   quit 1
endif

$Form = $System.Form()
$Form.BackColor = 240,240,240
$Form.Height = 175
$Form.Left = 43
$Form.Text = "Form"
$Form.Top = 10
$Form.Width = 325
$ListView = $Form.Controls.ListView()
$ListView.Height = 95
$ListView.Left = 15
$ListView.Top = 15
$ListView.Width = 275
$ListView.Gridlines = 1
; create the columns per the earlier count
for $x = 0 to $cols
    $Column = $ListView.Columns.Add
    $Column.Text = "Column " + val($x+1)
    $Column.Width = $ListView.Width / val($cols+1)
next
; fill the columns with data from the text file that we read earlier
for each $line in $infile
    $foo = split($line,";")
    $Item = $ListView.Items.Add
    for $y = 0 to ubound($foo)
        $Item.SubItems($y).Text = $foo[$y]
    next
next

;KD END

$Form.Show
While $Form.Visible
   $=Execute($Form.DoEvents())
Loop
Exit 1

Function ReadFile($file)
   Dim $lf, $f, $_, $t
   $lf=chr(10)
   $f=freefilehandle
   $_=open($f,$file)
      if @error   exit @error   endif
      do $t=$t+$lf+readline($f) until @error
      $_=close($f)
   $ReadFile=split(substr($t,2),$lf)
EndFunction
Back to top
View user's profile Send private message
Patrick
KiXforms Novice
KiXforms Novice


Joined: 07 Jan 2006
Posts: 3
Location: Germany

PostPosted: Fri Jul 30, 2010 5:03 pm    Post subject: Reply with quote

Yes,

thanks, that works greate.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Starters Code Clinic All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group