Results 1 to 40 of 40

Thread: [RESOLVED] Exe file crashes

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Posts
    395

    Resolved [RESOLVED] Exe file crashes

    My application runs fine from the design window in VB 6.0, when I click the command button. But when I do the same in my exe file, it crashes.

    I have added a couple of components to the project. Could this be the reason?

  2. #2
    Fanatic Member kregg's Avatar
    Join Date
    Feb 2006
    Location
    UK
    Posts
    524

    Re: Exe file crashes

    What is the error?

    Does it do the same crash on another PC?

    How about providing some code that you've used at startup?

    I find it generally hard to tell you the problem directly because the problem could be related to so many things. It's hard to tell.

    Give the above a shot, and see what me and other members got to say

    kregg

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Posts
    395

    Re: Exe file crashes

    The code is as follows:

    VB Code:
    1. Private Sub Command2_Click()
    2.  
    3.     Dim Txt() As MyData 'stores our data
    4.     Dim i As Long 'counter
    5.     Dim dComb As String 'combination string
    6.     Dim dOutput As String 'output string
    7.     Dim UB As Long 'Ubound of the txt() array
    8.    
    9.     Dim Text1Count As Long, Text2Count As Long, Text3Count As Long, TotalTextCount As Long
    10.    
    11.     i = 0
    12.     dComb = ""
    13.     dOutput = ""
    14.     UB = 0
    15.        
    16.    
    17.    
    18.    
    19.     If Check1.Value = vbChecked And Len(Trim(Text1.Text)) <= 0 Then
    20.     MsgBox "Error: no data in column1"
    21.         Exit Sub
    22.     Else
    23.     If Check1.Value = vbChecked Then
    24.         Text1Count = GetLineCount(Text1)
    25.         Else
    26.         Text1Count = 1
    27.     End If
    28.     End If
    29.  
    30.     If Check2.Value = vbChecked And Len(Trim(Text2.Text)) <= 0 Then
    31.     MsgBox "Error: no data in column2"
    32.         Exit Sub
    33.     Else
    34.     If Check2.Value = vbChecked Then
    35.         Text2Count = GetLineCount(Text2)
    36.         Else
    37.         Text2Count = 1
    38.     End If
    39.     End If
    40.  
    41.     If Check2.Value = vbChecked And Len(Trim(Text3.Text)) <= 0 Then
    42.     MsgBox "Error: no data in column3"
    43.         Exit Sub
    44.     Else
    45.     If Check3.Value = vbChecked Then
    46.         Text3Count = GetLineCount(Text3)
    47.         Else
    48.         Text3Count = 1
    49.     End If
    50.     End If
    51.    
    52.     TotalTextCount = Text1Count * Text2Count * Text3Count
    53.    
    54.    
    55.     UB = -1 'set to invalid
    56.    
    57.     'assign each textbox data to the dynamic array if checked
    58.     If Check1.Value Then
    59.         UB = UB + 1
    60.         ReDim Txt(UB)
    61.         With Txt(UB)
    62.             .tStr = Split(Text1.Text, vbCrLf)
    63.             .Bounds = UBound(.tStr)
    64.         End With
    65.     End If
    66.     If Check2.Value Then
    67.         UB = UB + 1
    68.         ReDim Preserve Txt(UB)
    69.         With Txt(UB)
    70.             .tStr = Split(Text2.Text, vbCrLf)
    71.             .Bounds = UBound(.tStr)
    72.         End With
    73.     End If
    74.     If Check3.Value Then
    75.         UB = UB + 1
    76.         ReDim Preserve Txt(UB)
    77.         With Txt(UB)
    78.             .tStr = Split(Text3.Text, vbCrLf)
    79.             .Bounds = UBound(.tStr)
    80.         End With
    81.     End If
    82.    
    83.     If UB = -1 Then 'none selected so exit
    84.         Exit Sub
    85.     End If
    86.    
    87.     ProgressBar1.Value = 0
    88.     ProgressBar1.Max = TotalTextCount 'Your Value
    89.     ProgressBar1.Min = 0
    90.    
    91.    
    92.    
    93.     Do
    94.     ProgressBar1.Value = ProgressBar1.Value + 1
    95.         For i = 0 To UB
    96.             With Txt(i)
    97.                 If Len(.tStr(.index)) Then
    98.                     dComb = dComb & .tStr(.index) & " "
    99.                     Else
    100.                         dComb = vbNullString
    101.                         Exit For
    102.                 End If
    103.             End With
    104.         Next i
    105.        
    106.         For i = UB To 0 Step -1
    107.             With Txt(i)
    108.                 .index = .index + 1
    109.                 If .index > .Bounds Then
    110.                     .index = 0
    111.                 Else
    112.                     Exit For
    113.                 End If
    114.             End With
    115.         Next i
    116.         If i = -1 Then 'we are done
    117.             Exit Do
    118.         End If
    119.         If Len(dComb) > 0 Then
    120.             dOutput = dOutput & Trim$(dComb) & vbCrLf
    121.             dComb = vbNullString
    122.         End If
    123.        
    124.     Loop
    125.     'MsgBox Len(dOutput)
    126.     Text4.Text = dOutput
    127.     'txtCount = GetLineCount(Text4)
    128.     txtCount = Text4.GetLineFromChar(Len(Text4.Text)) + 1
    129. End Sub

    It is run on a command button. Text1,Text2 and Text3 have 3 lines of text in each.

    Text4 is the richtextbox.

    Extra components added are the progressbar and richtextbox.

    The progress bar reaches the end and some data appears in the richtextbox. No count appears. But the hour glass appears and its at 100% CPU.

    It all works fine before the exe is made.

  4. #4

  5. #5
    Fanatic Member kregg's Avatar
    Join Date
    Feb 2006
    Location
    UK
    Posts
    524

    Re: Exe file crashes

    I get a error at the first line:

    VB Code:
    1. Dim Txt() As MyData 'stores our data

    What is MyData? Does anyone else know what MyData is?

    Edit: Follow Marty's idea.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Posts
    395

    Re: Exe file crashes

    MyDate is below:

    VB Code:
    1. Private Type MyData
    2.     tStr() As String
    3.     Bounds As Long
    4.     index As Long
    5. End Type

    My boss doesn't want the whole project to go out because it contains some proprietary secrets for his business. :S
    Last edited by Jon12345; Nov 24th, 2006 at 02:58 PM.

  7. #7
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Exe file crashes

    GetLineCount is not defined and trying to help you this way is very tedious. At least set up your own project with the code you've posted and try to run it so you can see what else (if anything) is needed.

    Also since this is a professional project you should use meaningful control names instead of things like Command2 and Text1.

  8. #8
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Exe file crashes

    Quote Originally Posted by Jon12345
    But when I do the same in my exe file, it crashes.
    Does it throw an error of some kind?

    Try replacing your sub with this and see if it give you an idea where things are going wrong.
    VB Code:
    1. Private Sub Command2_Click()
    2.  
    3.           Dim Txt() As MyData 'stores our data
    4.           Dim i As Long 'counter
    5.           Dim dComb As String 'combination string
    6.           Dim dOutput As String 'output string
    7.           Dim UB As Long 'Ubound of the txt() array
    8.    
    9.           Dim Text1Count As Long, Text2Count As Long, Text3Count As Long, TotalTextCount As Long
    10.    
    11.    On Error GoTo Command2_Click_Error
    12.  
    13. 10        i = 0
    14. 20        dComb = ""
    15. 30        dOutput = ""
    16. 40        UB = 0
    17.        
    18.    
    19.    
    20.    
    21. 50        If Check1.Value = vbChecked And Len(Trim(Text1.Text)) <= 0 Then
    22. 60        MsgBox "Error: no data in column1"
    23. 70            Exit Sub
    24. 80        Else
    25. 90        If Check1.Value = vbChecked Then
    26. 100           Text1Count = GetLineCount(Text1)
    27. 110           Else
    28. 120           Text1Count = 1
    29. 130       End If
    30. 140       End If
    31.  
    32. 150       If Check2.Value = vbChecked And Len(Trim(Text2.Text)) <= 0 Then
    33. 160       MsgBox "Error: no data in column2"
    34. 170           Exit Sub
    35. 180       Else
    36. 190       If Check2.Value = vbChecked Then
    37. 200           Text2Count = GetLineCount(Text2)
    38. 210           Else
    39. 220           Text2Count = 1
    40. 230       End If
    41. 240       End If
    42.  
    43. 250       If Check2.Value = vbChecked And Len(Trim(Text3.Text)) <= 0 Then
    44. 260       MsgBox "Error: no data in column3"
    45. 270           Exit Sub
    46. 280       Else
    47. 290       If Check3.Value = vbChecked Then
    48. 300           Text3Count = GetLineCount(Text3)
    49. 310           Else
    50. 320           Text3Count = 1
    51. 330       End If
    52. 340       End If
    53.    
    54. 350       TotalTextCount = Text1Count * Text2Count * Text3Count
    55.    
    56.    
    57. 360       UB = -1 'set to invalid
    58.    
    59.           'assign each textbox data to the dynamic array if checked
    60. 370       If Check1.Value Then
    61. 380           UB = UB + 1
    62. 390           ReDim Txt(UB)
    63. 400           With Txt(UB)
    64. 410               .tStr = Split(Text1.Text, vbCrLf)
    65. 420               .Bounds = UBound(.tStr)
    66. 430           End With
    67. 440       End If
    68. 450       If Check2.Value Then
    69. 460           UB = UB + 1
    70. 470           ReDim Preserve Txt(UB)
    71. 480           With Txt(UB)
    72. 490               .tStr = Split(Text2.Text, vbCrLf)
    73. 500               .Bounds = UBound(.tStr)
    74. 510           End With
    75. 520       End If
    76. 530       If Check3.Value Then
    77. 540           UB = UB + 1
    78. 550           ReDim Preserve Txt(UB)
    79. 560           With Txt(UB)
    80. 570               .tStr = Split(Text3.Text, vbCrLf)
    81. 580               .Bounds = UBound(.tStr)
    82. 590           End With
    83. 600       End If
    84.    
    85. 610       If UB = -1 Then 'none selected so exit
    86. 620           Exit Sub
    87. 630       End If
    88.    
    89. 640       ProgressBar1.Value = 0
    90. 650       ProgressBar1.Max = TotalTextCount 'Your Value
    91. 660       ProgressBar1.Min = 0
    92.    
    93.    
    94.    
    95. 670       Do
    96. 680       ProgressBar1.Value = ProgressBar1.Value + 1
    97. 690           For i = 0 To UB
    98. 700               With Txt(i)
    99. 710                   If Len(.tStr(.Index)) Then
    100. 720                       dComb = dComb & .tStr(.Index) & " "
    101. 730                       Else
    102. 740                           dComb = vbNullString
    103. 750                           Exit For
    104. 760                   End If
    105. 770               End With
    106. 780           Next i
    107.        
    108. 790           For i = UB To 0 Step -1
    109. 800               With Txt(i)
    110. 810                   .Index = .Index + 1
    111. 820                   If .Index > .Bounds Then
    112. 830                       .Index = 0
    113. 840                   Else
    114. 850                       Exit For
    115. 860                   End If
    116. 870               End With
    117. 880           Next i
    118. 890           If i = -1 Then 'we are done
    119. 900               Exit Do
    120. 910           End If
    121. 920           If Len(dComb) > 0 Then
    122. 930               dOutput = dOutput & Trim$(dComb) & vbCrLf
    123. 940               dComb = vbNullString
    124. 950           End If
    125.        
    126. 960       Loop
    127.           'MsgBox Len(dOutput)
    128. 970       Text4.Text = dOutput
    129.           'txtCount = GetLineCount(Text4)
    130. 980       txtCount = Text4.GetLineFromChar(Len(Text4.Text)) + 1
    131.  
    132.    On Error GoTo 0
    133.    Exit Sub
    134.  
    135. Command2_Click_Error:
    136.  
    137.     MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Command2_Click of Form Form1" & vbCrLf & "Error on line number " & Erl
    138. End Sub

  9. #9
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Exe file crashes

    What's the secretcy in BROKEN? Are you guarding against someone wanting to fix it?

    You haven't answered half the questions asked...

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Posts
    395

    Re: Exe file crashes

    I have installed that error code and there is no error message. Just the 100% CPU. The same thing happens on another PC.

    By putting a msgbox after each line of code near the end of my subroutine, I can confirm that it completes all code within the End Sub. Then it crashes. i.e. I have a msgbox "End of routine" just before End Sub. That shows fine. Then I click Ok and it crashes.

    Very odd indeed.

    Intuition tells me that it might have something to do with the RichTextBox and ProgressBar controls, since I added those later. And I think it worked before these were added, as far as I can recall. The richtextbox used to be just a textbox control.
    Last edited by Jon12345; Nov 25th, 2006 at 07:19 AM.

  11. #11
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Exe file crashes

    Quote Originally Posted by Jon12345
    That shows fine. Then I click Ok and it crashes.
    Ok, well telling us it "crashes" doesn't give us much information.

    Do you get an error message when it crashes? Or does it pop up a message saying "... has encountered an error and needs to close", ie: the Send Error Report message on Windows XP.

    Also, it's kind of hard to help you fix something when you can't give us the code.

    It's like taking a car to a mechanic and saying "Hey can you help me fix my car? I can't let you look under the hood though, because it's a secret."


  12. #12
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Exe file crashes

    With 100% cpu usage, I would be looking at a looping problem. Since you got to the end of the button click event I would have to say the problem is elsewhere.

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Posts
    395

    Re: Exe file crashes

    What I mean by a crash is that the CPU goes to 100% and if I hold the mouse over the application, it goes to an hour glass. There is no pop up message of any kind.

  14. #14
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Exe file crashes

    Quote Originally Posted by Jon12345
    What I mean by a crash is that the CPU goes to 100% and if I hold the mouse over the application, it goes to an hour glass. There is no pop up message of any kind.
    Ok, well that's not really a "crash". Most likely a loop that is still going like Mark said.

    And with the little code you shared, plus the fact that the variable names/control names aren't really meaningful, makes it harder to figure out what the problem is.

    Did you say you didn't have any problems until you added other components to your project?

  15. #15
    Fanatic Member kregg's Avatar
    Join Date
    Feb 2006
    Location
    UK
    Posts
    524

    Re: Exe file crashes

    Check the loop to see if it is dependant on a value changing (should be!), and then see if that value changes when you go through the code. For example:

    VB Code:
    1. 'Problematic Loop code
    2. Private Sub loopcode()
    3.     x = 0
    4.     Do Until x = 5
    5.          y = y + 1
    6.     Loop
    7. End Sub
    8.  
    9. 'Can be corrected by
    10. Private Sub loopcode2()
    11.     x = 0
    12.     Do Until x = 5
    13.          y = y + 1
    14.          x = x + 1
    15.     Loop
    16. End Sub

    Hope it helps!

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Posts
    395

    Re: Exe file crashes

    DigiRev, yes you would think it was a loop, but like I said earlier I put a message box just before the End Sub and it got to that just fine. Then, I clicked Ok and the 100% CPU kicked in.

    Regarding the components, I cannot remember exactly. I think perhaps I should remove the progress bar and see what happens. If that doesn't work, remove the richtextbox control too.

  17. #17
    Fanatic Member kregg's Avatar
    Join Date
    Feb 2006
    Location
    UK
    Posts
    524

    Re: Exe file crashes

    With the sub that has the messagebox... has that been called anywhere by any chance?

  18. #18
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Exe file crashes

    When something like that happens it is usually because you failed to close and destroy objects that you used and when you attempt to close the app VB goes nuts!!!!

  19. #19
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Exe file crashes

    You will never reach Exit Do

    VB Code:
    1. For i = UB To 0 Step -1
    2.             With Txt(i)
    3.                 .index = .index + 1
    4.                 If .index > .Bounds Then
    5.                     .index = 0
    6.                 Else
    7.                     Exit For
    8.                 End If
    9.             End With
    10.         Next i
    11.         If i = -1 Then 'we are done
    12.             Exit Do
    13.         End If
    This is because your always resetting .index to zero... or you will always have at least one Txt(i) array element with .index <= .Bounds, which in turn calls Exit For, which in turn keeps i from getting to -1


    Tell us what you are trying to accomplish with that procedure... make the explanation descriptive... so we can rewrite the procedure (or relevant part) for you.
    Last edited by leinad31; Nov 26th, 2006 at 09:42 AM.

  20. #20
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Exe file crashes

    Its strange though that a msgbox statement at the end of the procedure is executed... that should only happen when UB = 0, and larger values for UB would produce the infinite loop.... is that the case? on what test value does the procedure work and on what test values does it loop infinitely.

    EDIT: My bad... it actually reaches the Exit Do eventually... but the increase in the number of loops when .Bound or UB is increased is very very large. Consider UB=2 and all .Bound = 2... loops (Fors + Do) would be around 3*3*3... if UB and all .Bound were increased to 5 then you would have around 5*5*5.

    Also consider disabling the button when its clicked and just reenable it before End Sub so the click event is not placed in the call stack... otherwise you could be running the long procedure several times if the user kept clicking the button during "hang".
    Last edited by leinad31; Nov 26th, 2006 at 11:28 AM.

  21. #21
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Exe file crashes

    If the source for the combinations are from textfiles then you can create a cartesian join of the textfiles through SQL+ADO...
    Attached Files Attached Files

  22. #22
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Exe file crashes

    By any chance are you running your exe on another machine or in another folder other than the development folder?

  23. #23

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Posts
    395

    Re: Exe file crashes

    I am going to take a risk and upload my project. What files do I need to include? The entire project folder?

  24. #24
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Exe file crashes

    Yes, That would be a start.

  25. #25

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Posts
    395

    Re: Exe file crashes

    Some kind soul helped me by email. They said this:

    Move the Dim of Txt() to the module level rather than in the Sub and the problem goes away.
    The first time I click Generate, it works. The second time I get the following error:

    Error 10(This array is fixed or temporarily locked) in prodecure Command2_Click of Form Form1. Error on line number 0.

    You can see where I placed the Dim Txt(). Hope its in the right place.

    VB Code:
    1. Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" ( _
    2.     ByVal hWnd As Long, _
    3.     ByVal wMsg As Long, _
    4.     ByVal wParam As Long, _
    5.     ByRef lParam As Any _
    6. ) As Long
    7.  
    8. Dim Txt() As MyData 'stores our data
    9.  
    10. Private Type MyData
    11.     tStr() As String
    12.     Bounds As Long
    13.     index As Long
    14. End Type

    Any ideas on this?

  26. #26
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Exe file crashes

    That's not going to solve your original problem and it just created a new one... The only way you are going to solve this is by total luck or by letting someone look at your project...

  27. #27
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Exe file crashes

    This is a VERY strange problem.

    I just found that if you make txt a fixed array with something like

    Private Txt(27) As MyData

    and you eliminate the Redim-ing then you can click Command2 as many times as you like. Is that acceptable?

    BTW, what is the code in Command2 supposed to do?

  28. #28
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Exe file crashes

    Aha!! If you remove the With blocks it works even if Txt is dynamic. In other words do the following. (I hope it's OK for me to post this code. If it's not then let me know and I'll delete it.)

    VB Code:
    1. Private Sub Command2_Click()
    2.  
    3.           Dim i As Long 'counter
    4.           Dim dComb As String 'combination string
    5.           Dim dOutput As String 'output string
    6.           Dim UB As Long 'Ubound of the txt() array
    7.    
    8.           Dim Text1Count As Long, Text2Count As Long, Text3Count As Long, TotalTextCount As Long
    9.    
    10. 10        On Error GoTo Command2_Click_Error
    11.    
    12. 20        i = 0
    13. 30        dComb = ""
    14. 40        dOutput = ""
    15. 50        UB = 0
    16.  
    17.    
    18. 60        If Check1.Value = vbChecked And Len(Trim(Text1.Text)) <= 0 Then
    19. 70        MsgBox "Error: no data in column1"
    20. 80            Exit Sub
    21. 90        Else
    22. 100       If Check1.Value = vbChecked Then
    23. 110           Text1Count = GetLineCount(Text1)
    24. 120           Else
    25. 130           Text1Count = 1
    26. 140       End If
    27. 150       End If
    28.  
    29. 160       If Check2.Value = vbChecked And Len(Trim(Text2.Text)) <= 0 Then
    30. 170       MsgBox "Error: no data in column2"
    31. 180           Exit Sub
    32. 190       Else
    33. 200       If Check2.Value = vbChecked Then
    34. 210           Text2Count = GetLineCount(Text2)
    35. 220           Else
    36. 230           Text2Count = 1
    37. 240       End If
    38. 250       End If
    39.  
    40. 260       If Check2.Value = vbChecked And Len(Trim(Text3.Text)) <= 0 Then
    41. 270       MsgBox "Error: no data in column3"
    42. 280           Exit Sub
    43. 290       Else
    44. 300       If Check3.Value = vbChecked Then
    45. 310           Text3Count = GetLineCount(Text3)
    46. 320           Else
    47. 330           Text3Count = 1
    48. 340       End If
    49. 350       End If
    50.    
    51. 360       TotalTextCount = Text1Count * Text2Count * Text3Count
    52.    
    53.    
    54. 370       UB = -1 'set to invalid
    55.    
    56.           'assign each textbox data to the dynamic array if checked
    57. 380       If Check1.Value Then
    58. 390           UB = UB + 1
    59. 400           ReDim Txt(UB)
    60.               'With Txt(UB)
    61. 410               Txt(UB).tStr = Split(Text1.Text, vbCrLf)
    62. 420               Txt(UB).Bounds = UBound(Txt(UB).tStr)
    63.               'End With
    64. 430       End If
    65. 440       If Check2.Value Then
    66. 450           UB = UB + 1
    67. 460           ReDim Preserve Txt(UB)
    68.               'With Txt(UB)
    69. 470               Txt(UB).tStr = Split(Text2.Text, vbCrLf)
    70. 480               Txt(UB).Bounds = UBound(Txt(UB).tStr)
    71.               'End With
    72. 490       End If
    73. 500       If Check3.Value Then
    74. 510           UB = UB + 1
    75. 520           ReDim Preserve Txt(UB)
    76.               'With Txt(UB)
    77. 530               Txt(UB).tStr = Split(Text3.Text, vbCrLf)
    78. 540               Txt(UB).Bounds = UBound(Txt(UB).tStr)
    79.               'End With
    80. 550       End If
    81.    
    82. 560       If UB = -1 Then 'none selected so exit
    83. 570           Exit Sub
    84. 580       End If
    85.    
    86. 590       ProgressBar1.Value = 0
    87. 600       ProgressBar1.Max = TotalTextCount 'Your Value
    88. 610       ProgressBar1.Min = 0
    89.    
    90.    
    91.    
    92. 620       Do
    93. 630       ProgressBar1.Value = ProgressBar1.Value + 1
    94. 640       Debug.Print ProgressBar1.Value
    95. 650           For i = 0 To UB
    96.                   'With Txt(i)
    97. 660                   If Len(Txt(i).tStr(Txt(i).index)) Then
    98. 670                       dComb = dComb & Txt(i).tStr(Txt(i).index) & " "
    99. 680                       Else
    100. 690                           dComb = vbNullString
    101. 700                           Exit For
    102. 710                   End If
    103.                   'End With
    104. 720           Next i
    105.  
    106. 730           For i = UB To 0 Step -1
    107.                   'With Txt(i)
    108. 740                   Txt(i).index = Txt(i).index + 1
    109. 750                   If Txt(i).index > Txt(i).Bounds Then
    110. 760                       Txt(i).index = 0
    111. 770                   Else
    112. 780                       Exit For
    113. 790                   End If
    114.                   'End With
    115. 800           Next i
    116. 810           If i = -1 Then 'we are done
    117.                   'new
    118.                   'ProgressBar1.Value = 0
    119. 820               Exit Do
    120. 830           End If
    121. 840           If Len(dComb) > 0 Then
    122. 850               dOutput = dOutput & Trim$(dComb) & vbCrLf
    123. 860               dComb = vbNullString
    124. 870           End If
    125.           'MsgBox dOutput
    126. 880       Loop
    127. 900      Exit Sub
    128.  
    129. Command2_Click_Error:
    130.  
    131. 910       MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Command2_Click of Form Form1" & vbCrLf & "Error on line number " & Erl
    132.       'Resume Next
    133. End Sub

  29. #29

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Posts
    395

    Re: Exe file crashes

    Someone else wrote the code that does the Redim, so I am not sure of the effect of eliminating it.

    The Command2 code is supposed to take values in each of 3 text boxes and append them to each other with all possible permutations (caveat: with textbox1 word coming before textbox2 etc).

    Does having Txt(27) give me 28 locations to store data? I might have a list of 10,000 words that are used. Maybe if I did Txt(50,000) to cover for lots of keywords?

  30. #30

  31. #31

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Posts
    395

    Re: Exe file crashes

    Hey Martin, that worked! Thank you. Now I can actually use the thing. Really appreciate the help on this one. I was completely stumped.

    One thing I notice about this bit of code is that if I load up one of the textboxes with 10,000 words, it starts to run the code but after about 10 seconds, the hourglass comes up and it hangs.

    Am I using the wrong types of variables so I run out of space? Or any ideas?

  32. #32

  33. #33

  34. #34
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Exe file crashes

    What's slowing you down are the string concatenations, and the line by line append to the rtb... since your gonna be storing all those values in memory anyway (in the rtb, texboxes, etc), might as well use arrays to store the values and transfer them as one batch to the rtb. Its a lot faster that way since you can skip access to object properties until you really need to do so.

    I included some Doevents to address the "hang" issue, but these doevents will slow down processing.

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim sA() As String
    3. Dim sB() As String
    4. Dim sC() As String
    5. Dim cntA As Long
    6. Dim cntB As Long
    7. Dim cntC As Long
    8. Dim mulA As Long
    9.  
    10. Dim idx As Long
    11. Dim idxUB As Long
    12.  
    13.    Frame1.Enabled = False
    14.    Command1.Enabled = False
    15.    ProgressBar1.Max = 400
    16.    
    17.    'load values....
    18.    If Check1.Value = vbChecked Then
    19.       Call GetArray("\data\text1.txt", sA)
    20.       cntA = UBound(sA) + 1
    21.    Else
    22.       ReDim sA(0)
    23.       cntA = 1
    24.    End If
    25.    
    26.    If Check2.Value = vbChecked Then
    27.       Call GetArray("\data\text2.txt", sB)
    28.       cntB = UBound(sB) + 1
    29.    Else
    30.       ReDim sB(0)
    31.       cntB = 1
    32.    End If
    33.    
    34.    If Check3.Value = vbChecked Then
    35.       Call GetArray("\data\text3.txt", sC)
    36.       cntC = UBound(sC) + 1
    37.    Else
    38.       ReDim sC(0)
    39.       cntC = 1
    40.    End If
    41.    
    42.    idxUB = (cntA * cntB * cntC) - 1
    43.    
    44.    'create series
    45.    If Check1.Value = vbChecked Then
    46.       ReDim Preserve sA(idxUB)
    47.       mulA = cntB * cntC
    48.       For idx = idxUB To 0 Step -1
    49.          ProgressBar1.Value = (idxUB - idx) * 100 \ idxUB
    50.          If idx Mod 1000 = 0 Then DoEvents
    51.          sA(idx) = sA(idx \ mulA)
    52.       Next
    53.    Else
    54.       ReDim sA(idxUB)
    55.       ProgressBar1.Value = 100
    56.    End If
    57.    
    58.    If Check2.Value = vbChecked Then
    59.       ReDim Preserve sB(idxUB)
    60.       For idx = idxUB To 0 Step -1
    61.          ProgressBar1.Value = ((idxUB - idx) * 100 \ idxUB) + 100
    62.          If idx Mod 1000 = 0 Then DoEvents
    63.          sB(idx) = sB((idx \ cntC) Mod cntB)
    64.       Next
    65.    Else
    66.       ReDim sB(idxUB)
    67.       ProgressBar1.Value = 200
    68.    End If
    69.  
    70.    If Check3.Value = vbChecked Then
    71.       ReDim Preserve sC(idxUB)
    72.       For idx = idxUB To 0 Step -1
    73.          ProgressBar1.Value = ((idxUB - idx) * 100 \ idxUB) + 200
    74.          If idx Mod 1000 = 0 Then DoEvents
    75.          sC(idx) = sC(idx Mod cntC)
    76.       Next
    77.    Else
    78.       ReDim sC(idxUB)
    79.       ProgressBar1.Value = 300
    80.    End If
    81.    
    82.    'update sA()
    83.    For idx = 0 To idxUB
    84.       ProgressBar1.Value = ((idx * 100) \ idxUB) + 300
    85.       If idx Mod 1000 = 0 Then DoEvents
    86.       sA(idx) = sA(idx) & vbTab & sB(idx) & vbTab & sC(idx)
    87.    Next
    88.    Erase sB
    89.    Erase sC
    90.    
    91.    RichTextBox1.Text = Join(sA, vbCrLf)
    92.    Erase sA
    93.    
    94.    Command1.Enabled = True
    95.    Frame1.Enabled = True
    96. End Sub
    97.  
    98. Private Sub GetArray(ByVal RelPath As String, ByRef DestArray() As String)
    99. Dim ff As Integer
    100.    
    101.    ff = FreeFile
    102.    Open App.Path & RelPath For Input As #ff
    103.       DestArray = Split(Input(LOF(ff), #ff), vbCrLf)
    104.    Close #ff
    105. End Sub
    106.  
    107. Private Sub Form_Unload(Cancel As Integer)
    108.    RichTextBox1.Text = ""
    109. End Sub

    Admittedly this could still be improved, such as using just one big array for the combinations rather than the three arrays above... I just also wanted to show you an alternative to creating the combinations by writing the serries rather than having recursive loops or having indices that jump around (indices that loop then wrap back to zero for each column as your currently doing).

    eg. For (A,B,C) (x,y,z) (0,1)
    You will have 6 A's, 6 B's and 6 C's for first column...
    You will have repeating pattern 2 x's, 2 y's, 2 z's for second column...
    and you will have 0 and 1 alternating for third column...

    A,x,0
    A,x,1
    A,y,0
    A,y,1
    A,z,0
    A,z,1
    etc...
    Last edited by leinad31; Nov 29th, 2006 at 02:34 AM.

  35. #35
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Exe file crashes

    If I understand how you are generating your list in the richtextbox you would create 27 entries if there were 3 entries in each column of the input data (3 x 3 x 3 = 27). So if you had 9500 in column1 and 10 in column 2 and 10 in column 3 then you'd be trying to generate 950,000 entries ( 9500 x 10 x 10) which will be very slow no matter what method you use. I performed an experiment with that much data in your program and also adding a display counter each time dOutput was incremented. The counter showed that in fact the program does not hang up with that much data (at least in the IDE)but after 1 hr 15 minutes it had "only" generated 275,000 rows. My display counter slows down the process slightly but you should look into other methods like leinad31's (which I didn't try) if in fact you need to process that much data.

  36. #36
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Exe file crashes

    Actually, you can generate just a subset or even one combination with the index calculations above, bit slower than index increment but it allows direct access... you just need the source elements count, all possible combinations count, the source arrays, and the index nth combination.

    eg. For (A,B,C), (x,y,z), (0,1)
    VB Code:
    1. sA() = Split("A,B,C", ",")
    2. sB() = Split("x,y,z", ",")
    3. sC() = Split("0,1", ",")
    4. cntA = UBound(sA) = 3   'this is count of A,B,C
    5. cntB = UBound(sB) = 3   'this is count of x,y,z
    6. cntC = UBound(sC) = 2   'this is count of 0,1
    7.  
    8. idxUB = (cntA * cntB * cntC) - 1  'all possible combinations adjusted by -1 for zero bound array
    9. idxUB = (3*3*2) - 1  = 17  '18 combinations in array indices 0-17
    10.  
    11. 'Combination at index 13 (14th combination) would then be:
    12. Debug.Print sA(13 \ (cntB * cntC)) & vbTab & sB((13 \ cntC) Mod cntB) & vbTab & sC(idx) = sC(13 Mod cntC)
    13. 'or Debug.Print sA(13 \ 6) & vbTab & sB((13 \ 2) Mod 3) & vbTab & sC(13 Mod 2)
    14. 'or Debug.Print sA(2) & vbTab & sB(6 Mod 3) & vbTab & sC(1)
    15. 'or Debug.Print sA(2) & vbTab & sB(0) & vbTab & sC(1)
    16.  
    17. 'WHERE sA(2) = 'C', sB(2) = 'x', sC(1) = '1'

    So for 950,000 entries, you could split that up into 100k subsets (index 0-99999, 99999-199999, etc)
    Last edited by leinad31; Nov 29th, 2006 at 10:59 PM.

  37. #37

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Posts
    395

    Re: Exe file crashes

    Sorry guys, I made a mistake. What I thought was the program hanging was in fact a huge slowdown that happens when the numbers get larger. It seems to be a disproportionate slowdown. Consequently, I will have to change the main routine.

    leinad31, thank you for the coding you did. I tried to get it working but couldn't. Are you storing the data in a text file or something as opposed to the Textboxes?

  38. #38
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Exe file crashes

    Please remember that in an intensive loop if you dont use DoEvents your cpu will go to 100% usage and slow down all operations on your computer.

  39. #39
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Exe file crashes

    Quote Originally Posted by Jon12345
    Sorry guys, I made a mistake. What I thought was the program hanging was in fact a huge slowdown that happens when the numbers get larger. It seems to be a disproportionate slowdown. Consequently, I will have to change the main routine.

    leinad31, thank you for the coding you did. I tried to get it working but couldn't. Are you storing the data in a text file or something as opposed to the Textboxes?
    Yes I'm using text files... it doesn't matter if its originally in a text file or a textbox... what's important is transfering the list to single dimension string arrays (eg. sA(), sB(), sC()... if there's no data then redim array to ubound zero such as ReDim sA(0)... sA(0) would contain "" by deault)...

    post #36 explains how you can generate a particular combination based on these source arrays. Note that the source arrays are not resized unlike in post #34, you just get relevant elements from the sources... you could then transfer to one huge ReDim destination_Array(idxUB), rather than three huge cause of resize source arrays.

    post #34 created the combinations per column... I reused the source arrays by resizing them to the number of combinations (ReDim Preserve sA(idxUB))... I then updated "" values in array by copying elements from portion of array with values (from array index 0 to cntA - 1), hence the decrement loops.

  40. #40

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Posts
    395

    Re: Exe file crashes

    leinad31, I got it working and it is so much faster. A big thank you and repped.

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