Results 1 to 7 of 7

Thread: Why This code Crashed VB6 Ent. Ed

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    12

    Thumbs down

    Hello... does anyone know why this made my vb6 not work? and i have to restart the computer in order for vb to work again?

    Dim TimeNow As Long
    Dim CurrentTime As Long

    MSComm1.RTSEnable = True
    TimeNow = GetTickCount
    CurrentTime = TimeNow

    ' Busy wait here for 5 milliseconds
    Do Until (CurrentTime - TimeNow > 5)
    CurrentTime = GetTickCount
    Loop

    'Some code here

    TimeNow = GetTickCount
    CurrentTime = TimeNow

    ' Busy wait here for 15 milliseconds
    Do Until (CurrentTime - TimeNow > 15)
    CurrentTime = GetTickCount
    Loop

    MSComm1.RTSEnable = False

    ----- If i don't put in the 15ms busy wait and just go on.. then it will not crash... so I don't think it's the GetTickCount... any ideas would be greatly appreciated..
    Thanx in advance! =)



  2. #2

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    12
    Maybe I should use and declare different variables?

  3. #3
    New Member
    Join Date
    Feb 2000
    Location
    Salem, Oregon, USA
    Posts
    14
    Give me your code for GetTickCount. I think it's very possible that's where the error is coming from...


    Litehouse

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    12
    Humm.. GetTickCount is only a lib or something that i call.. and the declare is below :


    Private Declare Function GetTickCount Lib "kernel32" _
    () As Long

  5. #5
    Hyperactive Member
    Join Date
    Jun 1999
    Posts
    308
    Are you working with COM ports? If so then dont foget that COM ports operate asynchronicaly. You are using loop with out DoEvents and you perfom some codes before Waiting 15 msec. You have to be sure there are no activity on COM Port before entering waiting loop, or place Doevents inside the loop.

  6. #6

    Thread Starter
    New Member
    Join Date
    Jul 2000
    Posts
    12
    LG:

    Thanx for responding.. =)

    Yes.. i'm working with COM ports.
    Yes.. There are events going on in the COM port while i'm waiting, actually, that's why i'm waiting.. for the event to finish before i turn off RTS

    So i looked up DoEvent.. and it's functionallity is it Yields execution so that the operating system can process other events.

    So i now try to change the code to this :

    ' Busy wait here for 15 milliseconds
    Do Until (CurrentTime - TimeNow > 15)
    DoEvent()
    CurrentTime = GetTickCount
    Loop

    -- and see what happens.
    -- So with events firing in the COM ports, I can't call any system calls?


  7. #7
    Hyperactive Member
    Join Date
    Jun 1999
    Posts
    308
    It is not about system events, realy.
    I uderstand this like:

    VB doesn't have a control over COM port because COM is a sistem device, end servised by system. But VB is notified by OS about any changes in COM port status and its in and out buffers. If in any moment VB loosing tracking of changes in COM status it is a system failure for VB and it stops responding without raising runtime errors. When you make such loops you are preventing VB from recieving OS notifications about COM status and VB goes crasy.
    but.... that is my point of view. I do a lot of serial communications programming and getiing problems like that time to time. And every time it happens to be something new and unique.

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