Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

Load items to list view is nto working ;(



Public Function FLoadlistV(file$, listx As ListView) As String
Dim x As String
    Dim sLineIn As String
    On Error GoTo ErrLoadListFromFile
 
    listx.ListItems.Clear
    Open file$ For Input As #1
    While Not EOF(1)
        Line Input #1, sLineIn
        x = Replace(Trim$(sLineIn), " ", "")
        If x <> "" Then listx.ListItems.Add sLineIn
    Wend
   
ErrLoadListFromFile:
    Close #1
End Function

if this right i call it like this:   Call FLoadlistV(App.Path & "\phrase.txt", phrase)
there is no errors, it just is not loading into the list.
0
andyakira
Asked:
andyakira
  • 2
1 Solution
 
cachedVBCommented:
Public Function LoadListFromFile(ByRef SourceFile As String, _
     ByRef List As ListBox)
On Error GoTo ErrEvt
Dim TextLine As String, FN As Integer

List.Clear

FN = FreeFile
 Open SourceFile For Input As #FN ' Open file.
   Do While Not EOF(FN) ' Loop until end of file.
   Line Input #FN, TextLine ' Read line into variable.
   If TextLine <> LineToRem Then
    List.AddItem (TextLine)
    Else
    If X > 9999999 Then
    MsgBox "Error!"
    Exit Function
    End If
   
   End If
Loop
Close #FN ' Close file.



ErrEvt:
Select Case Err.number
   Case 51
      Err.Clear
   Case Else
   X = X + 1
End Select

Resume Next
End Function



try that instead
0
 
andyakiraAuthor Commented:
does this work for list view?
0
 
andyakiraAuthor Commented:
i cant get it to work, i need one for listview.
0
 
Ryan ChongCommented:
Try:

Public Function FLoadlistV(file$, listx As ListView) As String
    Dim x As String
    Dim sLineIn As String
    'On Error GoTo ErrLoadListFromFile
 
    listx.ListItems.Clear
    Open file$ For Input As #1
    While Not EOF(1)
        Line Input #1, sLineIn
        x = Replace(Trim$(sLineIn), " ", "")
        If x <> "" Then listx.ListItems.Add , , sLineIn
    Wend
   
ErrLoadListFromFile:
    Close #1
End Function

>>listx.ListItems.Add sLineIn
Should changed to listx.ListItems.Add , , sLineIn

cheers
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now