home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Unleashed / Visual_Basic_4_Unleashed_SAMS_Publishing_1995.iso / crystal / extras / crpedemo / winapis.bas < prev    next >
Encoding:
BASIC Source File  |  1994-12-15  |  5.9 KB  |  217 lines

  1. Option Explicit
  2.  
  3.  
  4. Declare Function GetSystemDirectory Lib "KERNEL" (ByVal lpBuffer As String, ByVal nSize As Integer) As Integer
  5. Declare Function GetWindowsDirectory Lib "KERNEL" (ByVal lpBuffer As String, ByVal nSize As Integer) As Integer
  6.  
  7. 'The following Declare Function should be entered on a single line
  8. Declare Function GetFreeSystemResources Lib "USER" (ByVal fuSysResource As Integer) As Integer
  9.  
  10.  
  11. 'Declaration of Constants
  12. Const GFSR_SYSTEMRESOURCES = 0
  13. Const GFSR_GDIRESOURCES = 1
  14. Const GFSR_USERRESOURCES = 2
  15.  
  16. Function AsciiZ$ (a$)
  17. ' Converts zero-delimited ASCII strings to Basic strings
  18. '
  19. Dim p%
  20. 'find the location of the zero character
  21. p = InStr(a, Chr(0))
  22. ' character is at the very end ?
  23. If p = 0 Then p = Len(a) + 1
  24. ' get the string minus the character
  25. AsciiZ$ = Trim(Left(a, p - 1))
  26. '
  27.  
  28.  
  29. End Function
  30.  
  31. Function FreeResourcesAreAbove (LowLimit)
  32.   On Error GoTo FreeResourcesAreAbove_err
  33.   Dim em As String
  34.   Dim myGDI As Integer, MyUser As Integer, MySystem As Integer
  35.   em$ = "FreeResourcesAreAbove_Start"
  36.   FreeResourcesAreAbove = False
  37.   Dim res As Integer
  38.   res% = Get_Resource(myGDI, MyUser, MySystem) '   code here
  39.   If myGDI < LowLimit Or MyUser < LowLimit Or MySystem < LowLimit Then
  40.     FreeResourcesAreAbove = False
  41.   Else
  42.     FreeResourcesAreAbove = True
  43.   End If
  44.   Exit Function
  45.  
  46. FreeResourcesAreAbove_err:
  47.   FreeResourcesAreAbove = False
  48.   MsgBox Error$(Err) + "Crystal .bas - FreeResourcesAreAbove" & em$
  49.   Exit Function
  50.  
  51.  
  52. End Function
  53.  
  54. Function Get_Resource (myGDI, MyUser, MySystem)
  55.    Static LN As String * 1
  56.    Dim Msg As String
  57.    On Error GoTo Get_Resource_err
  58.    'LN forces the Message Box to wrap to a new line
  59.     LN = Chr(13)
  60.    'Percentage of Free GDI RESOURCES
  61.    'Msg = "GDI Resources = " & GetFreeSystemResources(GFSR_GDIRESOURCES) & " %" & LN
  62.    myGDI = GetFreeSystemResources(GFSR_GDIRESOURCES)
  63.    'percentage of Free USER RESOURCES
  64.    'Msg = Msg & "User Resources = " & GetFreeSystemResources(GFSR_USERRESOURCES) & " %" & LN
  65.    MyUser = GetFreeSystemResources(GFSR_USERRESOURCES)
  66.    'percentage of Free SYSTEM RESOURCES
  67.    'Msg = Msg & "System Resources = " & GetFreeSystemResources(GFSR_SYSTEMRESOURCES) & " %"
  68.    MySystem = GetFreeSystemResources(GFSR_SYSTEMRESOURCES)
  69.    'Display results in a message box
  70.    'MsgBox Msg
  71. Exit Function
  72. Get_Resource_err:
  73. Msg$ = " WinAPIs.bas - Get_resource "
  74. MsgBox Error$(Err) & Msg$
  75.  
  76. End Function
  77.  
  78. Function GetWinDirs (WhichOne As String)
  79. 'sets the buffer length for both variables to 144
  80. On Error GoTo GetWinDirs_err
  81. WhichOne$ = UCase$(WhichOne$)
  82. Dim Win_Dir As String * 144
  83. Dim Sys_Dir As String * 144
  84. Dim x As Integer
  85. If WhichOne$ = "WINDOWS" Then
  86.    'returns the windows directory
  87.    x = GetWindowsDirectory(Win_Dir$, Len(Win_Dir$))
  88.    GetWinDirs = Win_Dir$
  89.    'Displays the windows directory in a Message box
  90.    'MsgBox Win_Dir
  91. End If
  92. If WhichOne$ = "SYSTEM" Then
  93.    'Returns the Windows\System directory
  94.    x = GetSystemDirectory(Sys_Dir$, Len(Win_Dir$))
  95.    GetWinDirs = Sys_Dir$
  96.    'Displays the windows\system directory in a Message box
  97.    'MsgBox Sys_Dir
  98. End If
  99. Exit Function
  100.  
  101. GetWinDirs_err:
  102. Dim Msg As String
  103. Msg$ = " WinAPIs.bas - GetWinDirs "
  104. MsgBox Error$(Err) & Msg
  105.  
  106.  
  107. End Function
  108.  
  109. Function Keep32to126Letters (mystring As String)
  110.   On Error GoTo Keep32To126Letters_err
  111.   Dim em As String
  112.   em$ = "Keep32To126Letters_Start"
  113.   Keep32to126Letters = False
  114.   Dim placeinstring As Integer
  115.   Dim ThisChar As String
  116.   Dim lenofstring As Integer
  117.   Dim NewString As String
  118.  
  119.   lenofstring% = Len(mystring$)
  120.   placeinstring% = 1
  121.   ThisChar$ = ""
  122.   NewString$ = ""
  123.   Do While placeinstring% <= lenofstring%
  124.     ThisChar$ = Mid$(mystring$, placeinstring%, 1)
  125.     'MsgBox Str(Lenofstring%) & ": " & ThisChar$ & " : " & Str(Asc(ThisChar$))
  126.     If Asc(ThisChar$) < 32 Or Asc(ThisChar$) > 126 Then
  127.       NewString$ = NewString$ & " "
  128.     Else
  129.       NewString$ = NewString$ & ThisChar$
  130.     End If
  131.     placeinstring% = placeinstring% + 1
  132.   Loop
  133.  
  134.   Keep32to126Letters = NewString$
  135.   Exit Function
  136.  
  137. Keep32To126Letters_err:
  138.   Keep32to126Letters = False
  139.   MsgBox Error$(Err) + "WinAPIs .bas - Keep32To126Letters" & em$
  140.   Exit Function
  141.  
  142.  
  143.  
  144. End Function
  145.  
  146. Function KillEndingCR (mystring As String)
  147.   On Error GoTo KillEndingCR_err
  148.   Dim em As String
  149.   em$ = "KillEndingCR_Start"
  150.   KillEndingCR = False
  151.   Dim placeinstring As Integer
  152.   Dim cr As String
  153.   Dim lenofstring As Integer
  154.   Dim NewString As String
  155.  
  156.   lenofstring% = Len(mystring$)
  157.   placeinstring% = 1
  158.   cr$ = Chr(13) & Chr(10)
  159.   NewString$ = ""
  160.     placeinstring% = InStr(1, mystring$, cr$)
  161.     MsgBox Str(placeinstring%)
  162.     MsgBox mystring$
  163.  Do While Right$(mystring$, 2) = cr$
  164.     mystring$ = Left(mystring$, lenofstring% - 2)
  165.     placeinstring% = InStr(1, mystring$, cr$)
  166.     lenofstring% = Len(mystring$)
  167.     MsgBox Str(placeinstring%)
  168.     MsgBox mystring$
  169.   Loop
  170.  
  171.   KillEndingCR = mystring$
  172.   Exit Function
  173.  
  174. KillEndingCR_err:
  175.   KillEndingCR = False
  176.   MsgBox Error$(Err) + "WinAPIs .bas - KillEndingCR" & em$
  177.   Exit Function
  178. End Function
  179.  
  180. Function KillLeadingCR (mystring As String)
  181.   On Error GoTo KillLeadingCR_err
  182.   Dim em As String
  183.   em$ = "KillLeadingCR_Start"
  184.   KillLeadingCR = False
  185.   Dim placeinstring As Integer
  186.   Dim ThisChar As String
  187.   Dim lenofstring As Integer
  188.   Dim NewString As String
  189.  
  190.   lenofstring% = Len(mystring$)
  191.   placeinstring% = 1
  192.   ThisChar$ = ""
  193.   NewString$ = ""
  194.   Do While placeinstring% <= lenofstring%
  195.     ThisChar$ = Mid$(mystring$, placeinstring%, 1)
  196.     'MsgBox Str(Lenofstring%) & ": " & ThisChar$ & " : " & Str(Asc(ThisChar$))
  197.     If Asc(ThisChar$) > 32 And Asc(ThisChar$) < 127 Then
  198.       NewString$ = Mid$(mystring$, placeinstring%)
  199.       Exit Do
  200.     End If
  201.     placeinstring% = placeinstring% + 1
  202.   Loop
  203.  
  204.   KillLeadingCR = NewString$
  205.   Exit Function
  206.  
  207. KillLeadingCR_err:
  208.   KillLeadingCR = False
  209.   MsgBox Error$(Err) + "WinAPIs .bas - KillLeadingCR" & em$
  210.   Exit Function
  211.  
  212.  
  213.  
  214.  
  215. End Function
  216.  
  217.