Cheap Web Hosting Providers
Visual Basic 6‎ > ‎

VB 6 Tips

Debugging Visual Basic 6 Exe

posted Aug 27, 2010 2:16 AM by Rajesh NK   [ updated Aug 28, 2010 12:16 AM ]

If you want to see the debug text from compilled Exe, use API function OutputDebugString. It has following advantages over debug.print function
1. Debug output is shown in IDE as well as when code is run outside IDE, ie when exe is run.
2. Text from two processes is shown at one place and it helps to understand the sequence of text

This function shows debug text in debugger. Debug View is a debugger with few extra features than the normal debugger which can be downloaded from here http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx

code sample:

Private Declare Sub OutputDebugString Lib "kernel32" Alias "OutputDebugStringA" (ByVal lpOutputString As String)

Private Sub Command1_Click()
    Call proc(0)
End Sub


Private Function proc(no As Double) As Double
  If no < 1 Then
      OutputDebugString "Divide by zero in proc function"
      Exit Function
  End If
  proc = 30 / no
End Function

Output: Shows debug text "Divide by zero in proc function" in Debug View window


1-1 of 1