Results 1 to 11 of 11

Thread: [RESOLVED] txt file to listview

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2004
    Location
    Newcastle
    Posts
    114

    Resolved [RESOLVED] txt file to listview

    hi guys, having abit of trouble loading up 3 collums in my listview, reading from a txt file. here is my code

    Public Sub LoadServer()
    Dim strServer As String
    Open App.Path & "\ServerList.txt" For Input As #1
    While Not EOF(1)
    Input #1, strServer
    sCon.sErver.ListItems.Add(, , Left$(strServer, InStr(strServer, ":") - 1), , 2).ListSubItems.Add = Split(strServer, ":")(1)
    Wend
    Close #1
    End Sub

    now this reads my txt file wich looks like this

    irc.mindspring.com:6667
    irc.koach.com:6667
    irc.bork.uk.quakenet.org:6667
    irc.chatcore.org:6667

    it places this line in seprate collums, but what my question is, how could i add stuff to a 3rd collum, lets just say my txtfile line looked like this

    irc.mindspring.com:6667-username

    i can manage to split the irc server and the port into seprate collums, how would i add the "username" to another collum... thanks very much guys

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: txt file to listview

    Code:
    Dim lvwItem As ListItem
    '~~~> Inside loop
    '// Input the line from file and split the 3 data and store it to variables
    Set lvwItem = ListView1.ListItems.Add(, , "a") '~~~> for first column
    lvwItem.SubItems(1) = "ab"  '~~~> for second column
    lvwItem.SubItems(2) = "abc" '~~~> for third column
    '~~~> End loop

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  3. #3
    Lively Member agent_007's Avatar
    Join Date
    Jan 2010
    Posts
    93

    Re: txt file to listview

    Quote Originally Posted by Lazer View Post
    hi guys, having abit of trouble loading up 3 collums in my listview, reading from a txt file. here is my code

    Public Sub LoadServer()
    Dim strServer As String
    Open App.Path & "\ServerList.txt" For Input As #1
    While Not EOF(1)
    Input #1, strServer
    sCon.sErver.ListItems.Add(, , Left$(strServer, InStr(strServer, ":") - 1), , 2).ListSubItems.Add = Split(strServer, ":")(1)
    Wend
    Close #1
    End Sub

    now this reads my txt file wich looks like this

    irc.mindspring.com:6667
    irc.koach.com:6667
    irc.bork.uk.quakenet.org:6667
    irc.chatcore.org:6667

    it places this line in seprate collums, but what my question is, how could i add stuff to a 3rd collum, lets just say my txtfile line looked like this

    irc.mindspring.com:6667-username

    i can manage to split the irc server and the port into seprate collums, how would i add the "username" to another collum... thanks very much guys
    Try This


    Code:
    Private Sub Command1_Click()
    Dim strServer As String
    Open "c:\name.txt" For Input As #1
    While Not EOF(1)
    Input #1, strServer
    ListView1.ListItems.Add(1).Text = Split(strServer, ":")(0)
    ListView1.ListItems.Item(1).ListSubItems.Add.Text = Right(Split(strServer, "-")(0), 4)
    ListView1.ListItems.Item(1).ListSubItems.Add.Text = Split(strServer, "-")(1)
    Wend
    Close #1
    End Sub
    and heres my textfile

    irc.mindspring.com:6667-username
    irc.koach.com:6667-XXX
    irc.bork.uk.quakenet.org:6667-agent_007
    irc.chatcore.org:6667-hellboy
    Attached Images Attached Images  
    Last edited by agent_007; Jan 24th, 2010 at 06:14 AM.

    Im Pro in C#,VB.NET,Batch,Socket Programming, SPY Software Programming, VB6, Win32Api, VBscript, Windows Registry, ASP.NET, PHP, Jquery, AJAX.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Mar 2004
    Location
    Newcastle
    Posts
    114

    Re: txt file to listview

    thanks very much kind sir, works perfect.. but one last thing, i use an image list with icons for my list view, my icons wont show using this code.. how can i add my icon back to the list view.. the icon index is "1"... thanks

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2004
    Location
    Newcastle
    Posts
    114

    Re: txt file to listview

    ohh. and this line

    Right(Split(strServer, "-")(0), 4)

    there isnt always 4 digits, so how could i make it read it diffrent? thanks

  6. #6
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: txt file to listview

    Quote Originally Posted by Lazer View Post
    ohh. and this line

    Right(Split(strServer, "-")(0), 4)

    there isnt always 4 digits, so how could i make it read it diffrent? thanks
    Code:
    Dim strTemp As String
    Dim strSite As String, strPort As String, strUser As String
    strTemp = "irc.mindspring.com:6667-username" '~~~> for testing
    strSite = Mid(strTemp, 1, InStr(strTemp, ":") - 1)
    strPort = Mid(strTemp, InStr(strTemp, ":") + 1, InStr(strTemp, "-") - Len(strSite) - 2)
    strUser = Mid(strTemp, InStr(strTemp, "-") + 1)
    MsgBox strSite
    MsgBox strPort
    MsgBox strUser

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  7. #7
    Lively Member agent_007's Avatar
    Join Date
    Jan 2010
    Posts
    93

    Re: txt file to listview

    Quote Originally Posted by Lazer View Post
    ohh. and this line

    Right(Split(strServer, "-")(0), 4)

    there isnt always 4 digits, so how could i make it read it diffrent? thanks


    use this instead

    Code:
    ListView1.ListItems.Item(1).ListSubItems.Add.Text = Split((Split(strServer, "-")(0)), ":")(1)

    Im Pro in C#,VB.NET,Batch,Socket Programming, SPY Software Programming, VB6, Win32Api, VBscript, Windows Registry, ASP.NET, PHP, Jquery, AJAX.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Mar 2004
    Location
    Newcastle
    Posts
    114

    Re: txt file to listview

    thank you. but the icon still isnt showing.. thanks

  9. #9
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: txt file to listview

    Modified version of agent's code:
    Code:
    Private Sub Command1_Click()
    Dim lvwItem As ListItem
    Dim strServer As String
    Open "c:\name.txt" For Input As #1
    While Not EOF(1)
    Input #1, strServer
    Set lvwItem = ListView1.ListItems.Add(, , Split(strServer, ":")(0),,2) '~~> with icon index 2
    lvwItem.SubItems(1) =Split((Split(strServer, "-")(0)), ":")(1)
    lvwItem.SubItems(2) =Split(strServer, "-")(1)
    Wend
    Close #1
    End Sub
    (not tested)

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Mar 2004
    Location
    Newcastle
    Posts
    114

    Re: txt file to listview

    thank you

  11. #11
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: [RESOLVED] txt file to listview

    Does that solved your issue...???? If so, please Mark the Thread as RESOLVED (you can find the link in Thread Tools, situated at the top of this page)

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width