Results 1 to 12 of 12

Thread: Help with application.. Please [resolved]

  1. #1

    Thread Starter
    Addicted Member Chrispybee's Avatar
    Join Date
    Sep 2003
    Location
    North Wales, UK
    Posts
    217

    Resolved Help with application.. Please [resolved]

    Could someone please have a look at my code.
    It may look a mess, tried to remark everything for ease of use.

    What this does is opens a config file, reads data and acts upon what is in the config file.

    If you have a look at the code then you will see what happens.

    The problem:
    The main problem that I'm having is where the application will hang when been waiting or running for more then 5 - 10 hours.

    Many thanx in advance...
    Attached Files Attached Files
    Last edited by Chrispybee; Nov 2nd, 2004 at 04:58 AM.

  2. #2
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918
    I didn't have a really close look at your code but one thing stood out:

    In your sub LoadConfigFiles() try changing this line:
    VB Code:
    1. Do Until (strFinishTime = Time)
    2. to
    3.     Do Until (strFinishTime [color=red]>=[/color] Time)
    The reason I suggest that, is because the finish time may pass while that loop statement is being executed so when the test is made again, ie (strFinishTime = Time) it will never be true.

    Just a thought.
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  3. #3

    Thread Starter
    Addicted Member Chrispybee's Avatar
    Join Date
    Sep 2003
    Location
    North Wales, UK
    Posts
    217
    Thanks for that.

    The problem is when it runs for more that 7-10 hours.

    It maybe my wait routine but all looks ok.

    If anyone has any ideas on how I can make this more efficient, ideas and help are much appreciated.

    Thanx

  4. #4
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    hmmm ok...
    VB Code:
    1. Do Until (strFinishTime >= Time)
    That should actually be:
    VB Code:
    1. Do Until (strFinishTime <= Time)
    However, this is a bad way to do it.
    What I would do is place all that code in a timer.
    Then when you start the process, just enable the timer. Place the timer on say a 100ms interval.
    This means that it won't scoff CPU time by looping constantly.
    When ytou want the process to stop, just disable the time.

    Does that help?

    Ouch...just had another look at your code. You have a
    VB Code:
    1. Do
    2.    'shed loads of code
    3. Loop
    This puts you in an infinite loop, unless an error is raised
    In fact, when an error is raised, you come out of the loop, then it sends you back into the loop with a Goto

    I'd put this in a timer.

    Woof

  5. #5

    Thread Starter
    Addicted Member Chrispybee's Avatar
    Join Date
    Sep 2003
    Location
    North Wales, UK
    Posts
    217
    Thanx for that Wonka..


    For the wait routine, would something like
    VB Code:
    1. If strFinishTime = Time then
    2.    Timer1.Enabled = False
    3. Else
    4.    Timer1.Enabled = True
    5. End If

    Can you also point out the other problem out for me?

    Thanx

  6. #6

    Thread Starter
    Addicted Member Chrispybee's Avatar
    Join Date
    Sep 2003
    Location
    North Wales, UK
    Posts
    217

    Angry

    I'm still not having any joy!! My application is still hanging after 5 - 10 hours of waiting?


    As anyone else got a wait routine that I could have a look at?

    Please help...

  7. #7
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    Your coding is 110% wrong.

    VB is not Basic or Pascal...you don't need infinate loops.

    I'd have 2 timers.
    One fires every 10 seconds to see what the time is and to see if it should start doing stuff.
    If it does then it enables the other timer
    if the time has run out then it should disable the other timer

    You are using Goto's...BAD BAD BAD...do you realise how hard it is for us to debug an app like that Almost impossible.

    I am almost sure that it's hanging coz of your infinate loops.

    Post your current code that you have now.

    Woka

  8. #8

    Thread Starter
    Addicted Member Chrispybee's Avatar
    Join Date
    Sep 2003
    Location
    North Wales, UK
    Posts
    217
    Thanks for that Woka!!

    I'm glad that I can take constructive critisim!!

    Here is my latest app.

    As you will see, it will be 10000000% wrong! But with the aid of coders like yourself, I may become better! Well you can hope eh?

    Many thanks for your help with this.
    Attached Files Attached Files

  9. #9
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    ok...hmmm...just downloaded your project.

    Just a few pointers:
    VB Code:
    1. Dim Woof As String, Moose As Long, Growl As Integer _
    2.    , Sausage As Boolean blah blah blah
    Can be VERY confusing for a number of reasons. 1st you are spanning multiple lines. It makes it hard to find where varibles are declared. Also you need to use naming conventions. Woof is a bad name for a varible A developer, like me, who is looking at your project has trouble debugging as they don't know what varibles types are...
    What you should do is:
    VB Code:
    1. Dim strWoof     As String
    2. Dim lngMoose    As Long
    3. Dim intGrowl    As Integer
    4. Dim blnSausage  As Boolean
    As you can see this is MUCH easier to read, and also you cans ee what var type it is just by it's name.

    Another point. Don't use the END command.
    I'd remove this from your app. Do a search on VBF for why not to use it.

    Also...I think I may have found what's causing it to hang.
    All over your app you are doing stuff like:
    VB Code:
    1. Open strLogDir & "\" & strAppFile For Append As #3
    2. 'blah blah
    3. Close #3
    It works...but it is prone to problems.
    What you should do is:
    VB Code:
    1. Dim intFile As Integer
    2.    intFile = FreeFile
    3.    Open strLogDir & "\" & strAppFile For Append As #intFile
    4.    'blah blah
    5.    Close #intFile
    This could be the cause of your problems.

    Hope this helps.

    Woka

  10. #10

    Thread Starter
    Addicted Member Chrispybee's Avatar
    Join Date
    Sep 2003
    Location
    North Wales, UK
    Posts
    217
    Thanks for the tips Woka, I've done what you've said and tidy'd up my coding. Renamed things like CSOURCE to strCSOURCE and so on.

    Your coding is 110% wrong.

    VB is not Basic or Pascal...you don't need infinate loops.

    I'd have 2 timers.
    One fires every 10 seconds to see what the time is and to see if it should start doing stuff.
    If it does then it enables the other timer
    if the time has run out then it should disable the other timer

    You are using Goto's...BAD BAD BAD...do you realise how hard it is for us to debug an app like that Almost impossible.

    I am almost sure that it's hanging coz of your infinate loops.

    Post your current code that you have now.

    Woka
    Could you show me what you mean. I may sound thick but until someone points out I feel it will stay the same.

    Thanks

  11. #11
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    Place 2 timers on your form. tmrCheck and tmrDoStuff, then add the following:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     With tmrDoStuff
    5.         .Interval = 200
    6.         .Enabled = False
    7.     End With
    8.     With tmrCheck
    9.         .Interval = 1000
    10.         .Enabled = True
    11.     End With
    12. End Sub
    13.  
    14. Private Sub tmrCheck_Timer()
    15. Dim lngSec As Long
    16.     lngSec = Format(Time, "s")
    17.     If lngSec > 10 And lngSec < 50 Then
    18.         If Not tmrDoStuff.Enabled Then
    19.             tmrDoStuff.Enabled = True
    20.         End If
    21.     Else
    22.         If tmrDoStuff.Enabled Then
    23.             tmrDoStuff.Enabled = False
    24.         End If
    25.     End If
    26. End Sub
    27.  
    28. Private Sub tmrDoStuff_Timer()
    29.     Me.Caption = Time
    30. End Sub
    The tmrCheck checks to see if the seconds of the current time are between 10 and 50. If so then it enables the other timer, otherwise it disables the other timer.

    Does that make sense?

    Woka

  12. #12

    Thread Starter
    Addicted Member Chrispybee's Avatar
    Join Date
    Sep 2003
    Location
    North Wales, UK
    Posts
    217
    This has now been resolved.

    In the end, by frienfd who is a Delphi programmer told me what a timer is and does. I now fully understand timers. Phew!

    I've put the entire loop and stuck it into a timer.
    I got rid of the main
    VB Code:
    1. Do
    2.     ....Lots and lots of other loops and stuff
    3. Loop

    When the user starts the application. The timer is enabled.
    After all files are processed then timer is disabled.

    The timer is on a interval of around 30seconds.

    Many thanks for everyone that's helped me on this.

    Chris

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