Results 1 to 8 of 8

Thread: something is weird about this code...

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Location
    I'm right here!
    Posts
    849

    Question something is weird about this code...

    hello,

    I have a text file with two items in each line (seperated with a ",")

    I use this code to put all the lines in a listview:

    VB Code:
    1. frmMain.ListView1.Sorted = False
    2.     Dim strbig As String
    3.     Open App.Path & "\text.txt" For Input As #1
    4.     strbig = Input(LOF(1), 1)
    5.     a() = Split(strbig, vbCrLf)
    6.     Close #1
    7.     For i = 0 To UBound(a) - 1
    8.         Set lvEdit1 = frmMain.ListView1.ListItems.Add(, , a(i))
    9.     Next i

    everything works, the only thing is, in the 5th line the second item
    comes before the first...
    that's wierd... I don't know what is the problem....

    can anyone help?

    thanks

    Dekel C.

  2. #2
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    From your code, it seems that it's a problem with the file. Post up the file you are using.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    VB Code:
    1. Dim strOne As String
    2.     Dim strTwo As String
    3.  
    4.     Open App.Path & "\text.txt" For Input As #1
    5.     Do While Not EOF(1)
    6.         Input #1, strOne, strTwo
    7.         Set lvEdit1 = frmMain.ListView1.ListItems.Add(, , strOne)
    8.         Set lvEdit1 = frmMain.ListView1.ListItems.Add(, , strTwo)
    9.     Loop
    10.     Close #1

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    is the SET necessary? or just like a LET statement?

  5. #5
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    For objects, SET is necessary. You can't use SET on non-objects (unlike in .net, a string is not an object,etc)
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    i didn't see what made that an object, from the code... in fact, i still don't

  7. #7
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Originally posted by dglienna
    i didn't see what made that an object, from the code... in fact, i still don't
    The problem is that dekelc is either not declaring his variables or they are global. For example in his code there is no Dim for either a() or i. Also missing is something like the following which would make it clearer that lvEdit1 is an object.

    VB Code:
    1. Dim lvEdit1  As ListItem

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    I guess that you used it because he did. That makes sense, I guess. Using it erroneously would prolly cause an error, anyways.

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