Results 1 to 2 of 2

Thread: Freezing up

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2009
    Posts
    25

    Freezing up

    The script searches for strings inside of another string.

    My problem is that List3 loads +400 items and then when it searches it will freeze up the program.

    I put a limit on it to only load 20 items so it dose not freeze up.

    But it dose not get close to finishing what it needs to do.

    Code:
    Private Sub Command1_Click()
    Const StringLen = 20
    Dim MyArr(StringLen), TxtString As String
    
    List3.Clear
    List4.Clear
    Randomize
    ' Generate random string and list of numbers
    For i = 1 To StringLen
        TxtString = Text1.Text
        Call loadlist
    Next
    ' Search List
    For i = 1 To StringLen
        If InStr(TxtString, List3.List(i - 1)) Then
            List5.AddItem List3.List(i - 1) & " found!"
        Else: List4.AddItem List3.List(i - 1) & " not found."
        End If
    Next
        
    End Sub
    
    'Populates the listbox
    Private Sub loadlist()
    
    Dim strTemp As String
    Open App.Path & "\Item2.txt" For Input As #1
    Do Until EOF(1) = True
    Line Input #1, strTemp
    List3.AddItem strTemp
    Loop
    Close #1
    
    End Sub

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

    Re: Freezing up

    Private Sub Command1_Click()
    Const StringLen = 20
    Dim MyArr(StringLen), TxtString As String

    List3.Clear
    List4.Clear
    Randomize
    ' Generate random string and list of numbers
    For i = 1 To StringLen
    TxtString = Text1.Text
    Call loadlist
    Next
    ' Search List
    For i = 1 To StringLen
    If InStr(TxtString, List3.List(i - 1)) Then
    List5.AddItem List3.List(i - 1) & " found!"
    Else: List4.AddItem List3.List(i - 1) & " not found."
    End If
    Next

    End Sub

    'Populates the listbox
    Private Sub loadlist()

    Dim strTemp As String
    Open App.Path & "\Item2.txt" For Input As #1
    Do Until EOF(1) = True
    Line Input #1, strTemp
    List3.AddItem strTemp
    Loop
    Close #1

    End Sub
    I didn't understand what your code is doing here...

    > Why are you using
    Randomize
    ?
    >
    For i = 1 To StringLen
    TxtString = Text1.Text
    Call loadlist
    Next
    Why are you assigning TxtString inside the loop??
    > Why are you loading data from the file using loadlist inside a 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,...

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