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