home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code1 / dispatch / dispatch.bas next >
BASIC Source File  |  1993-08-31  |  2KB  |  99 lines

  1. '********************************************************
  2. '*
  3. '* First attempt of a dispatcher to invoke 'general'
  4. '* procedures of a form from other modules/forms.
  5. '*
  6. '* Oliver Mangold   CIS 100277,511
  7. '* Aug. 1993
  8. '*
  9. '********************************************************
  10.  
  11.  
  12. Option Explicit
  13.  
  14.     ' return value of dispatched function / sub
  15. Global dispatchReturnValue
  16.  
  17.     ' true if a dispatched sub is running
  18.     ' false otherwise
  19. Global dispatchIsRunning As Integer
  20.  
  21. ' dispatch a sub with no arguments
  22. '
  23. '
  24. Sub dispatch (frm As Form, fn$)
  25.  
  26.     dispatchIsRunning = True
  27.  
  28.     frm.dispatcher(0) = fn$     ' set the function / sub name
  29.  
  30. End Sub
  31.  
  32. ' dispatch a sub with one argument
  33. '
  34. Sub dispatch1 (frm As Form, fn$, arg1)
  35.  
  36.     dispatchIsRunning = True
  37.  
  38.     ' setting the dispatcher must have this order
  39.     ' 1. set dispatcher(1) - dispatcher(n) with the
  40.     '    arguments
  41.     ' 2. set dispatcher(0) with the name of the sub you
  42.     '    want to call
  43.  
  44.     frm.dispatcher(1) = arg1
  45.     frm.dispatcher(0) = fn$
  46.     
  47. End Sub
  48.  
  49. ' dispatch a sub with two arguments
  50. '
  51. '
  52. Sub dispatch2 (frm As Form, fn$, arg1, arg2)
  53.  
  54.     dispatchIsRunning = True
  55.  
  56.     ' setting the dispatcher must have this order
  57.     ' 1. set dispatcher(1) - dispatcher(n) with the
  58.     '    arguments
  59.     ' 2. set dispatcher(0) with the name of the sub you
  60.     '    want to call
  61.  
  62.     frm.dispatcher(2) = arg2
  63.     frm.dispatcher(1) = arg1
  64.     frm.dispatcher(0) = fn$
  65.     
  66. End Sub
  67.  
  68. ' Get the value the dispatched sub returned
  69. '
  70. '
  71. Function dispatchGetVal ()
  72.  
  73.     dispatchGetVal = dispatchReturnValue
  74.     
  75. End Function
  76.  
  77. ' Set the return value of the dispatched sub.
  78. ' Inform the calling procedure that the sub has finished
  79. '
  80. '
  81. Sub dispatchReturn (ByVal val1)
  82.  
  83.     dispatchReturnValue = val1
  84.     dispatchIsRunning = False
  85.  
  86. End Sub
  87.  
  88. ' Wait for the dispatched sub to finish
  89. '
  90. '
  91. Sub dispatchWait ()
  92.  
  93.     While dispatchIsRunning
  94.         DoEvents
  95.     Wend
  96.  
  97. End Sub
  98.  
  99.