home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 31 / CDASC_31_1996_juillet_aout.iso / vrac / mcvbehtp.zip / VBEHTP30.BAS < prev    next >
BASIC Source File  |  1996-05-16  |  15KB  |  442 lines

  1. Option Explicit
  2.  
  3. Global Const VB_LNG_FRENCH = 1
  4. Global Const VB_LNG_DUTCH = 2
  5. Global Const VB_LNG_GERMAN = 3
  6. Global Const VB_LNG_ENGLISH = 4
  7. Global Const VB_LNG_ITALIAN = 5
  8. Global Const VB_LNG_SPANISH = 6
  9. Global Const VB_LNG_CATALAN = 7
  10. Global Const VB_LNG_POLISH = 8
  11.  
  12. Const MB_MESSAGE_LEFT = 0
  13.  
  14. Declare Sub cPushID Lib "mcvb3016.dll" (IDArray As Integer, ByVal nID As Integer)
  15. Declare Sub cPopID Lib "mcvb3016.dll" (IDArray As Integer, ByVal nID As Integer)
  16. Declare Sub cPopLastID Lib "mcvb3016.dll" (IDArray As Integer)
  17. Declare Function cGetID Lib "mcvb3016.dll" (IDArray As Integer, ByVal nPosition As Integer) As Integer
  18. Declare Sub cClearID Lib "mcvb3016.dll" (IDArray As Integer)
  19. Declare Sub cChangeChars Lib "mcvb3016.dll" (Txt As String, charSet As String, newCharSet As String)
  20. Declare Function cGetIni Lib "mcvb3016.dll" (ByVal AppName As String, ByVal szItem As String, ByVal szDefault As String, ByVal InitFile As String) As String
  21. Declare Function cInsertBlocks Lib "mcvb3016.dll" (Txt As String, Insert As String) As String
  22. Declare Function cLngMsgBox Lib "mcvb3016.dll" (ByVal nLanguage As Integer, ByVal Message As String, ByVal Button As Long, ByVal Title As String) As Integer
  23. Declare Function cKillFileAll Lib "mcvb3016.dll" (ByVal lpFilename As String) As Integer
  24. Declare Function cTimerClose Lib "mcvb3016.dll" (ByVal TimerHandle As Integer) As Integer
  25. Declare Function cTimerOpen Lib "mcvb3016.dll" () As Integer
  26. Declare Function cTimerRead Lib "mcvb3016.dll" (ByVal TimerHandle As Integer) As Long
  27. Declare Function cTimerStart Lib "mcvb3016.dll" (ByVal TimerHandle As Integer) As Integer
  28.  
  29. 'Don't change any variables and their value below
  30.  
  31. Const ID_ITEMS = 16
  32.  
  33. Type tagERRORHANDLERtype
  34.    ModuleName                       As String * 256
  35.    RoutineHandle                    As String * 4
  36.    RoutineName                      As String * 76
  37.    CrLf                             As String * 2
  38. End Type
  39.  
  40. Type tagTRACERtype
  41.    StartStop                        As String * 1
  42.    RoutineHandle                    As Integer
  43. End Type
  44.  
  45. Type tagPROFILERtype
  46.    ModuleName                       As String * 256
  47.    RoutineHandle                    As String * 4
  48.    RoutineName                      As String * 76
  49.    TimeCounter                      As Long
  50.    TotalCall                        As Long
  51.    TotalTime                        As Long
  52.    MinimumTime                      As Long
  53.    MaximumTime                      As Long
  54.    Dummy                            As String * 10
  55.    CrLf                             As String * 2
  56. End Type
  57.  
  58. Dim TotalRoutines                   As Integer
  59. Dim ActualTrace                     As Long
  60. Dim OldStartRoutine                 As Integer
  61. Dim OldStopRoutine                  As Integer
  62.  
  63. Dim FileTR                          As String
  64. Dim FilePF                          As String
  65.  
  66. Dim chanFileTR                      As Integer
  67. Dim chanFilePF                      As Integer
  68.  
  69. Dim FileLNG                         As String
  70.  
  71. Dim FileHND                         As String
  72.  
  73. Dim FileLOG                         As String
  74.  
  75. Dim IDArray(0 To ID_ITEMS)          As Integer
  76.  
  77. Dim Language                        As Integer
  78. Dim AutoLog                         As Integer
  79. Dim WaitingTimeForReaction          As Integer
  80. Dim DefaultButton                   As Integer
  81. Dim DisplayOnline                   As Integer
  82. Dim TraceProfile                    As Integer
  83.  
  84. Dim TotalSameHandle                 As Long
  85. Dim LastHandle                      As Integer
  86. Dim ChanHandle                      As Integer
  87. Dim OldChanHandle                   As Integer
  88.  
  89. Dim tagERRORHANDLER                 As tagERRORHANDLERtype
  90. Dim tagTRACER                       As tagTRACERtype
  91. Dim tagPROFILER                     As tagPROFILERtype
  92.  
  93. Sub mcClearID ()
  94.    Call cClearID(IDArray(0))
  95. End Sub
  96.  
  97. Function mcGetID (nPos As Integer)
  98.    mcGetID = cGetID(IDArray(0), nPos)
  99. End Function
  100.  
  101. Function mcGetLanguageID (LanguageID As Integer) As String
  102.  
  103.    Dim RetLanguage      As String
  104.  
  105.    Select Case LanguageID
  106.       Case VB_LNG_FRENCH
  107.          RetLanguage = "VFR"
  108.       Case VB_LNG_DUTCH
  109.          RetLanguage = "VNL"
  110.       Case VB_LNG_GERMAN
  111.          RetLanguage = "VDE"
  112.       Case VB_LNG_ENGLISH
  113.          RetLanguage = "VUK"
  114.       Case VB_LNG_ITALIAN
  115.          RetLanguage = "VIT"
  116.       Case VB_LNG_SPANISH
  117.          RetLanguage = "VSP"
  118.       Case VB_LNG_CATALAN
  119.          RetLanguage = "VCA"
  120.       Case VB_LNG_POLISH
  121.          RetLanguage = "VPO"
  122.       Case Else
  123.          RetLanguage = "VUK"
  124.    End Select
  125.    
  126.    If (LanguageID > 0) Then
  127.       Language = LanguageID
  128.    Else
  129.       Language = VB_LNG_ENGLISH
  130.    End If
  131.  
  132.    mcGetLanguageID = RetLanguage
  133.  
  134. End Function
  135.  
  136. Function mcIDErrorHandler (nErr As Integer) As Integer
  137.  
  138.    ' check if this a correct Error passed
  139.    If (nErr = 0) Then
  140.       'if no, resume next
  141.       mcIDErrorHandler = True
  142.       Exit Function
  143.    End If
  144.  
  145.    Dim RoutineCount     As Integer
  146.    Dim RoutineNumber    As Integer
  147.    Dim RoutineStack     As String
  148.    Dim TotalRoutines    As Integer
  149.    Dim BlankLines       As Integer
  150.    Dim Chan             As Integer
  151.    Dim StopExit         As Integer
  152.    Dim TimeOut          As Long
  153.    Dim ButtonsConfig    As Integer
  154.    Dim ErrorTitle       As String
  155.  
  156.    '  some initializations
  157.    RoutineStack = ""
  158.    TotalRoutines = 0
  159.    BlankLines = 0
  160.    StopExit = False
  161.    ButtonsConfig = 0
  162.    ErrorTitle = ""
  163.    RoutineStack = RoutineStack + mcReadText("0", "")
  164.    
  165.    ' find the next valid unused file number.
  166.    Chan = FreeFile
  167.  
  168.    ' open the file with the definition of each routines (file must be in the WINDOWS directory)
  169.    Close #Chan
  170.    Open FileHND For Random Shared As #Chan Len = Len(tagERRORHANDLER)
  171.  
  172.    ' get the stack of the routines
  173.    For RoutineCount = 0 To ID_ITEMS
  174.       ' get the number of the routine
  175.       RoutineNumber = mcGetID(RoutineCount)
  176.       ' if there a valid routine number
  177.       If (RoutineNumber > 0) Then
  178.          ' yes, read the definition of the routine
  179.          Get #Chan, RoutineNumber, tagERRORHANDLER
  180.          ' form the stack of the routines founden to display
  181.          RoutineStack = RoutineStack + Left$(tagERRORHANDLER.ModuleName + Space$(12), 14) + Chr$(9) + tagERRORHANDLER.RoutineHandle + Chr$(9) + Trim$(tagERRORHANDLER.RoutineName) + Chr$(13)
  182.          ' count the routines to display
  183.          TotalRoutines = TotalRoutines + 1
  184.       Else
  185.          ' no, exit from reading the stack
  186.          Exit For
  187.       End If
  188.    Next RoutineCount
  189.  
  190.    ' close the open file
  191.    Close #Chan
  192.  
  193.    ' check if the default button must be activated
  194.    If (DefaultButton = True) Then
  195.       ' yes, RETRY and CANCEL with RETRY is the default
  196.       ButtonsConfig = 5 Or 0
  197.    Else
  198.       ' no, RETRY and CANCEL with CANCEL is the default
  199.       ButtonsConfig = 5 Or 256
  200.       ' yes, add text for RETRY after timeout or action
  201.       RoutineStack = RoutineStack & Chr$(13) & Chr$(13) & "program will be stopped"
  202.    End If
  203.  
  204.    ' set the error title
  205.    ErrorTitle = mcReadText("1", nErr & "~" & Error$(nErr))
  206.  
  207.    ' check if one routine has been founded
  208.    If (Len(RoutineStack) > 0) Then
  209.       ' check the time out
  210.       TimeOut = WaitingTimeForReaction * (163840 Or 524288)
  211.       ' display remaining blank lines
  212.       BlankLines = (8 - TotalRoutines) - (TimeOut = 0)
  213.       For RoutineCount = 0 To BlankLines
  214.          RoutineStack = RoutineStack + Chr$(13)
  215.       Next RoutineCount
  216.       ' add some text for management
  217.       RoutineStack = RoutineStack & mcReadText("2", "")
  218.       ' check if a timeout must be used
  219.       If (TimeOut <> 0) Then
  220.          ' yes, add text depending of the default button
  221.          RoutineStack = RoutineStack & mcReadText("3", "") & " "
  222.          ' if default is RETRY then display 'continue' else 'stop'
  223.          If (DefaultButton = True) Then
  224.             RoutineStack = RoutineStack & mcReadText("4", "")
  225.          Else
  226.             RoutineStack = RoutineStack & mcReadText("5", "")
  227.          End If
  228.       End If
  229.       ' display the error message box
  230.       StopExit = (cLngMsgBox(Language, RoutineStack, MB_MESSAGE_LEFT Or TimeOut Or ButtonsConfig Or 16, ErrorTitle) = 2)
  231.       ' yield process
  232.       DoEvents
  233.    End If
  234.  
  235.    ' check if an auto logging must be performed
  236.    If (AutoLog = True) Then
  237.  
  238.       ' open the logging file in append mode
  239.       Close #Chan
  240.       Open FileLOG For Append Shared As #Chan
  241.  
  242.       ' save the error and his description
  243.       Print #Chan, ErrorTitle; " "; mcReadText("6", Date$ & "~" & Time$)
  244.       Print #Chan, ""
  245.       ' save the full stack name of each routines founden
  246.       Print #Chan, RoutineStack
  247.       Print #Chan, ""
  248.       ' check if the CANCEL button pushed or TimeOut
  249.       If (StopExit = True) Then
  250.          ' yes stop by operator, save text for CANCEL
  251.          Print #Chan, mcReadText("7", "")
  252.       Else
  253.          ' no, retry by operator, save text for RETRY
  254.          Print #Chan, mcReadText("8", "")
  255.       End If
  256.       ' save separator
  257.       Print #Chan, String$(78, "-")
  258.  
  259.       ' close the file
  260.       Close #Chan
  261.  
  262.    End If
  263.  
  264.    ' if stop the program the END the application
  265.    If (StopExit = True) Then End
  266.  
  267.    ' no stop, resumes to next line in the main application
  268.    mcIDErrorHandler = True
  269.  
  270. End Function
  271.  
  272. Sub mcOnlineDisplay (ID As Integer)
  273.  
  274.    Dim ActualLine    As String
  275.  
  276.    If (ChanHandle = -1) Then
  277.  
  278.       ' close the old chan if more than 1 mcInitID is called
  279.       If (OldChanHandle <> -1) Then Close #OldChanHandle
  280.  
  281.       ' find the next valid unused file number.
  282.       ChanHandle = FreeFile
  283.  
  284.       ' open the file with the definition of each routines (file must be in the WINDOWS directory)
  285.       Close #ChanHandle
  286.       Open FileHND For Random Shared As #ChanHandle Len = Len(tagERRORHANDLER)
  287.  
  288.       ' save the handle
  289.       OldChanHandle = ChanHandle
  290.  
  291.    End If
  292.  
  293.    ' read the handle
  294.    Get #ChanHandle, ID, tagERRORHANDLER
  295.  
  296.    If (LastHandle = ID) Then
  297.       TotalSameHandle = TotalSameHandle + 1
  298.    Else
  299.       If (frmDisplayOnline.lstOnline.ListIndex > -1) Then
  300.          ActualLine = frmDisplayOnline.lstOnline.List(frmDisplayOnline.lstOnline.ListIndex)
  301.          frmDisplayOnline.lstOnline.List(frmDisplayOnline.lstOnline.ListIndex) = TotalSameHandle & Mid$(ActualLine, InStr(ActualLine, Chr$(9)))
  302.       End If
  303.       TotalSameHandle = 1
  304.    End If
  305.  
  306.    frmDisplayOnline.lblCounter = TotalSameHandle
  307.    frmDisplayOnline.lblHandle = ID
  308.  
  309.    If (LastHandle <> ID) Then
  310.       frmDisplayOnline.lstOnline.AddItem TotalSameHandle & Chr$(9) & Trim$(tagERRORHANDLER.RoutineHandle) & Chr$(9) & Trim$(tagERRORHANDLER.ModuleName) & Chr$(9) & Trim$(tagERRORHANDLER.RoutineName)
  311.       If (frmDisplayOnline.lstOnline.ListCount > 25) Then frmDisplayOnline.lstOnline.RemoveItem 0
  312.       frmDisplayOnline.lstOnline.ListIndex = frmDisplayOnline.lstOnline.NewIndex
  313.    End If
  314.  
  315.    LastHandle = ID
  316.  
  317.    DoEvents
  318.  
  319. End Sub
  320.  
  321. Sub mcPopID (ID As Integer)
  322.    Call cPopID(IDArray(0), ID)
  323. End Sub
  324.  
  325. Sub mcPopLastID (WhichManagement As Integer, RoutineNumber As Integer)
  326.    If ((WhichManagement = 2) Or (WhichManagement = 3)) Then Call mcStopTracer(RoutineNumber)
  327.    Call cPopLastID(IDArray(0))
  328. End Sub
  329.  
  330. Sub mcPushID (ID As Integer)
  331.  
  332.    Call cPushID(IDArray(0), ID)
  333.  
  334.    If (DisplayOnline = True) Then Call mcOnlineDisplay(ID)
  335.  
  336. End Sub
  337.  
  338. Function mcReadText (TextOrder As String, InsertText As String) As String
  339.  
  340.    Dim Tmp              As String
  341.    Dim BasisText        As String
  342.  
  343.    ' read the text in the language file
  344.    BasisText = cGetIni("mcvbehtp", TextOrder, "?", FileLNG)
  345.    
  346.    ' insert some text if any
  347.    Tmp = cInsertBlocks(BasisText, InsertText)
  348.  
  349.    ' change all º by a CR and all ú by TAB
  350.    Call cChangeChars(Tmp, "ºú", Chr$(13) + Chr$(9))
  351.  
  352.    mcReadText = Tmp
  353.  
  354. End Function
  355.  
  356. Sub mcStartTracer (RoutineNumber As Integer)
  357.  
  358.    Dim TimerCounter  As Integer
  359.    Dim Status        As Integer
  360.  
  361.    ' check if the routine number is not outside the limits
  362.    If ((RoutineNumber < 1) Or (RoutineNumber > TotalRoutines)) Then Exit Sub
  363.  
  364.    ' check if this is the same routine
  365.    If (OldStartRoutine <> RoutineNumber) Then
  366.       ' increment the trace number
  367.       ActualTrace = ActualTrace + 1
  368.       ' prepare the trace information
  369.       tagTRACER.StartStop = ">"
  370.       tagTRACER.RoutineHandle = RoutineNumber
  371.       ' save the trace information
  372.       Put #chanFileTR, ActualTrace, tagTRACER
  373.    End If
  374.  
  375.    ' save the old routine
  376.    OldStartRoutine = RoutineNumber
  377.  
  378.    ' read the record associated with the routine number
  379.    Get #chanFilePF, RoutineNumber, tagPROFILER
  380.  
  381.    ' open a timer
  382.    TimerCounter = cTimerOpen()
  383.    ' save the handle of the new timer
  384.    tagPROFILER.TimeCounter = TimerCounter
  385.    ' increment the number of calls
  386.    tagPROFILER.TotalCall = tagPROFILER.TotalCall + 1
  387.  
  388.    ' save the record associated with the routine number
  389.    Put #chanFilePF, RoutineNumber, tagPROFILER
  390.  
  391.    ' start the timer
  392.    Status = cTimerStart(TimerCounter)
  393.  
  394. End Sub
  395.  
  396. Sub mcStopTracer (RoutineNumber As Integer)
  397.  
  398.    Dim TimerCounter  As Integer
  399.    Dim TimeElapsed   As Long
  400.    Dim Status        As Integer
  401.  
  402.    ' check if the routine number is not outside the limits
  403.    If ((RoutineNumber < 1) Or (RoutineNumber > TotalRoutines)) Then Exit Sub
  404.  
  405.    ' check if this is the same routine
  406.    If (OldStopRoutine <> RoutineNumber) Then
  407.       ' increment the trace number
  408.       ActualTrace = ActualTrace + 1
  409.       ' prepare the trace information
  410.       tagTRACER.StartStop = "<"
  411.       tagTRACER.RoutineHandle = RoutineNumber
  412.       ' save the trace information
  413.       Put #chanFileTR, ActualTrace, tagTRACER
  414.    End If
  415.  
  416.    ' save the old routine
  417.    OldStopRoutine = RoutineNumber
  418.  
  419.    ' read the record associated with the routine number
  420.    Get #chanFilePF, RoutineNumber, tagPROFILER
  421.  
  422.    ' check if the timer is valid
  423.    If (tagPROFILER.TimeCounter > 0) Then
  424.       ' computes the elapsed time
  425.       TimeElapsed = cTimerRead(tagPROFILER.TimeCounter)
  426.       ' add the elapsed time
  427.       tagPROFILER.TotalTime = tagPROFILER.TotalTime + TimeElapsed
  428.       ' check for the minimum time
  429.       If (TimeElapsed < tagPROFILER.MinimumTime) Then tagPROFILER.MinimumTime = TimeElapsed
  430.       ' check for the minimum time
  431.       If (TimeElapsed > tagPROFILER.MaximumTime) Then tagPROFILER.MaximumTime = TimeElapsed
  432.    End If
  433.  
  434.    ' save the record associated with the routine number
  435.    Put #chanFilePF, RoutineNumber, tagPROFILER
  436.  
  437.    ' close the associated timer
  438.    Status = cTimerClose(tagPROFILER.TimeCounter)
  439.  
  440. End Sub
  441.  
  442.