Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB6 Timer(), Space() Form_Initialize() causes Immediate Crash

Create a new VB6 project. Paste the code below as your project code. Hit Run. See if it crashes... Remove or simplify anything you like in this code, and then it will work fine. Can anyone please shed some light on why this is crashing?

This has been tested on eight PC's so far, all running various combinations of Windows XP, Windows Vista, Windows 7, Office 2010, and Office 2007. The ones where it was tested in the Visual Basic IDE have Visual Basic 6 SP 6 installed.

Private Sub Sleep(ByVal nSeconds As Long)
    Dim nStart As Long: nStart = Timer
    Do
        DoEvents
    Loop Until (Timer - nStart) >= nSeconds
End Sub

Private Sub Crash()
    Dim sTempPath As String: sTempPath = Space(255)
End Sub

Private Sub Form_Initialize()
    Sleep 1
    Crash
End Sub


Addendum #1:

I put this as a macro in Excel 2010, replacing Form_Initialize() with Workbook_Open(), and sure enough, when you open the document. It crashes!

Addendum #2:

I added break points to every line before hitting "Run" and it crashed before it got to the first break point. But again, if I simplify or remove anything in this, it works fine and does not crash.

Addendum #3:

Tried MicSim's suggestion of removing the colon, and it did not crash. Added it back, ran it again and it did not crash. Closed Visual Basic, and put in the original code and it crashed.

Addendum #4:

Problem Details from Visual Basic 6 IDE:

Problem signature:
Problem Event Name: APPCRASH
Application Name: VB6.EXE
Application Version: 6.0.81.76
Application Timestamp: 3592011f
Fault Module Name: VBA6.dll
Fault Module Version: 6.0.0.8169
Fault Module Timestamp: 358b0c74
Exception Code: c0000005
Exception Offset: 00026329
OS Version: 6.1.7601.2.1.0.256.4
Locale ID: 1033
Additional Information 1: 7e3b
Additional Information 2: 7e3beb1e9ccf6d519c5b994ca59a280f
Additional Information 3: 7b83
Additional Information 4: 7b833c57ebcf54809fd3aaccd8ea4f46

Read our privacy statement online:
http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409

If the online privacy statement is not available, please read our privacy statement offline:
C:\Windows\system32\en-US\erofflps.txt

Addendum #5:

Problem Details from Microsoft Excel 2010:

Problem signature:
Problem Event Name: APPCRASH
Application Name: EXCEL.EXE
Application Version: 14.0.4756.1000
Application Timestamp: 4b9c08e8
Fault Module Name: VBE7.DLL
Fault Module Version: 7.0.15.90
Fault Module Timestamp: 4b7b1248
Exception Code: c0000005
Exception Offset: 00045b6a
OS Version: 6.1.7601.2.1.0.256.4
Locale ID: 1033

Additional information about the problem:
LCID: 1033
skulcid: 1033

Read our privacy statement online:
http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409

If the online privacy statement is not available, please read our privacy statement offline:
C:\Windows\system32\en-US\erofflps.txt

Screenshot after hitting Run, or Build

like image 253
Drew Chapin Avatar asked Dec 13 '11 16:12

Drew Chapin


1 Answers

After reviewing your question and all the addendums, I realized that your computer is running the release version of VB6, and not SP6.

Your crash details indicate the following versions:

  • VB6.exe: 6.0.81.76
  • VBA6.dll: 6.0.0.8179

The exact build numbers of Visual Basic 6.0 SP6 files are as follows:

  • VB6.exe: 6.0.97.82
  • VBA6.dll: 6.0.0.9782

Exception code c0000005 corresponds to an access violation in module vba6.dll. A similar problem is documented on Microsoft KB

I have not found an accurate source listing build numbers for each VB6 service packs, but it looks like this is the RTM version. Even though you might have installed SP6 yourself, a rogue installer may have overwritten shared system files by an older version after the service pack was installed. This would explain why a lot of users commented that the code is working fine for them with a seemingly similar setup.

like image 93
Gabriel Avatar answered Nov 15 '22 11:11

Gabriel