Results 1 to 9 of 9

Thread: load list1 from file but has to be same format regardless

  1. #1

    Thread Starter
    Banned
    Join Date
    Jun 2017
    Posts
    116

    load list1 from file but has to be same format regardless

    i have my code to load from text file list of keywords and i want the list1 to load it up same as it is shown in text file this means, special char, upper or lower case etc.

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: load list1 from file but has to be same format regardless

    So, what's the problem? How are you trying it? Do you have some code where it doesn't work (either throws an error or gives undesired results)?

  3. #3

    Thread Starter
    Banned
    Join Date
    Jun 2017
    Posts
    116

    Re: load list1 from file but has to be same format regardless

    when i copy the keywords from webpage the keywords can be upper or lower case with special char on some of the keywords etc what ever or space..
    this is why i wanted to import it just as it is rather then just import it standardly.

    Private Sub Command2_Click()
    On Error Resume Next
    List1.Clear
    Label1.Caption = "0"
    Call LoadList(c, List1)
    Dim i As Long
    Dim j As Long
    With List1
    For i = 0 To .ListCount - 1
    For j = .ListCount To (i + 1) Step -1
    If .List(j) = .List(i) Then
    .RemoveItem j
    End If
    Next
    Next
    End With
    Label1.Caption = List1.ListCount
    End Sub

  4. #4
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: load list1 from file but has to be same format regardless

    You have not showed the code that reads the file so we can not tell what you may be doing wrong.

    The basic file methods in VB will give you the data as it occurs in the file so if that is not what you are seeing then you must be either using a different method or doing some processing on the data that is changing it somehow but again you have not shown the code that would be in question.

  5. #5

    Thread Starter
    Banned
    Join Date
    Jun 2017
    Posts
    116

    Re: load list1 from file but has to be same format regardless

    this opened the text file populates it into text what else is it

  6. #6
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: load list1 from file but has to be same format regardless

    No that does not open any file
    You have a line there that calls another sub
    Code:
    Call LoadList(c, List1)
    I would assume that is where the file is opened and read but without seeing it can't say for sure as it may call some other sub or even more than one other sub.

  7. #7

    Thread Starter
    Banned
    Join Date
    Jun 2017
    Posts
    116

    Re: load list1 from file but has to be same format regardless

    Public Function LoadList(dialogCommon As CommonDialog, list45 As ListBox)
    On Error GoTo Error_Killer
    With dialogCommon
    .DialogTitle = "Load List"
    .Filter = "All Supported Types|*.txt"
    .ShowOpen
    LoadListFromFile list45, .FileName
    End With
    Error_Killer:
    Exit Function
    End Function

    Sub LoadListFromFile(cListBox As ListBox, sCurrentFile As String)
    Dim sLineIn As String
    On Error GoTo ErrLoadListFromFile
    Open sCurrentFile For Input As #1
    While Not EOF(1)
    Line Input #1, sLineIn
    If Trim$(sLineIn) <> "" Then cListBox.AddItem LCase(Replace(sLineIn, "", ""))
    Wend
    Close #1
    sCurrentFile = ""
    AfterLoadListFromFile:
    Form1.Label1.Caption = Form1.List1.ListCount
    Exit Sub
    ErrLoadListFromFile:
    Resume AfterLoadListFromFile
    End Sub

    or sorry

  8. #8
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: load list1 from file but has to be same format regardless

    This line converts the contents to lower case
    Code:
    If Trim$(sLineIn) <> "" Then cListBox.AddItem LCase(Replace(sLineIn, "", ""))
    You can replace with
    Code:
    If Trim$(sLineIn) <> "" Then cListBox.AddItem sLineIn
    VB6 controls are not support Unicode, so if the file contains Unicode, they will replaced with question mark ?

    Please use CODE tag to enclose your code not QUOTE tag



  9. #9
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    Re: load list1 from file but has to be same format regardless

    gen

    FWIW, 4x2y's last comment "translates" into this:

    Code:
    Public Function LoadList(dialogCommon As CommonDialog, list45 As ListBox)
        On Error GoTo Error_Killer
        With dialogCommon
            .DialogTitle = "Load List"
            .Filter = "All Supported Types|*.txt"
            .ShowOpen
            LoadListFromFile list45, .FileName
        End With
    Error_Killer:
        Exit Function
    End Function
    
    Sub LoadListFromFile(cListBox As ListBox, sCurrentFile As String)
        Dim sLineIn As String
        On Error GoTo ErrLoadListFromFile
        Open sCurrentFile For Input As #1
        While Not EOF(1)
            Line Input #1, sLineIn
            If Trim$(sLineIn) <> "" Then cListBox.AddItem LCase(Replace(sLineIn, "", ""))
        Wend
        Close #1
        sCurrentFile = ""
    AfterLoadListFromFile:
        Form1.Label1.Caption = Form1.List1.ListCount
        Exit Sub
    ErrLoadListFromFile:
        Resume AfterLoadListFromFile
    End Sub
    Spoo

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