home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / messag / main.ba_ / main.ba
Encoding:
Text File  |  1995-01-14  |  2.8 KB  |  97 lines

  1. 'API assorted functions
  2. Declare Function OutMessage% Lib "User" Alias "SendMessage" (ByVal hWnd%, ByVal wMsg%, ByVal wParam%, lParam As Any)
  3. Declare Function SendMessage& Lib "User" (ByVal hWnd%, ByVal wMsg%, ByVal wParam%, lParam As Any)
  4. Declare Function GetWindowsDirectory% Lib "Kernel" (ByVal lpBuffer$, ByVal nSize%)
  5. Declare Function WinHelp% Lib "User" (ByVal hWnd%, ByVal lpHelpFile$, ByVal wCommand%, ByVal dwData As Any)
  6.     Global Const HELP_CONTENTS = &H3
  7.     Global Const HELP_PARTIALKEY = &H105
  8.  
  9.  
  10.  
  11. 'program variables
  12. Global FormPassString As String 'used to pass strings
  13. Global FormPassString2 As String
  14.  
  15. Global nl As String
  16.  
  17. Global DisplayedMoveCtl As Integer
  18.  
  19. Function BackSlashAdd (ThePath)
  20. 'adds a backslash (\) to a string, only if the rightmost
  21. 'character is not already a backslash
  22.  
  23.     ThisPath$ = ThePath
  24.     If Right$(ThisPath$, 1) <> "\" Then
  25.         ThisPath$ = ThisPath$ + "\"
  26.         End If
  27.     BackSlashAdd = ThisPath$
  28. End Function
  29.  
  30. Function GetWinDir ()
  31.      Buffer$ = Space$(255)
  32.      count% = GetWindowsDirectory(Buffer$, 255)
  33.      GetWinDir = Left$(Buffer$, count%)
  34. End Function
  35.  
  36. Sub initialize ()
  37.     nl = Chr$(13) + Chr$(10)
  38. End Sub
  39.  
  40. Sub ListHscroll (TheListBox As Control, CharsWide%)
  41.     If CharsWide% > 15000 Then CharsWide% = 15000
  42.     LongString$ = String$(CharsWide%, "W")
  43.     tppx% = Screen.TwipsPerPixelX
  44.     MaxiWide% = TheListBox.Parent.TextWidth(LongString$) / tppx%
  45.     HscrollLen& = SendMessage(TheListBox.hWnd, 1045, MaxiWide%, 0)
  46. End Sub
  47.  
  48. Function replace (x, y, ReplaceString)
  49. 'replaces ALL occurences of y$ within x$ with ReplaceString
  50. 'for example, strip("abcdefabcedf","cde") = "abfabf"
  51.     
  52.     Dim z As String
  53.     
  54.     If Len(x) < 1 Or Len(y) < 1 Then
  55.         replace = ""
  56.         Exit Function
  57.         End If
  58.  
  59.     If Len(ReplaceString) = 0 Then
  60.         replace = x
  61.         Exit Function
  62.         End If
  63.     
  64.     z = x
  65.     pos% = InStr(z, y)
  66.     Do Until pos% = 0
  67.         z = Left$(z, (pos% - 1)) + ReplaceString + Right$(z, Len(z) - Len(y) - pos% + 1)
  68.         pos% = InStr(z, y)
  69.         Loop
  70.     replace = z
  71. End Function
  72.  
  73. Function TrimAtNull (TheWord)
  74. 'Trims the string at the NULL character
  75. 'useful with most DLL's that change a string's value
  76.  
  77.     pos% = InStr(TheWord, Chr$(0))
  78.     If pos% = 0 Then
  79.         TrimAtNull = TheWord
  80.         Else
  81.         TrimAtNull = Left$(TheWord, pos% - 1)
  82.         End If
  83. End Function
  84.  
  85. Sub WaitFor (SecondsToWait%)
  86.     If SecondsToWait > 59 Then SecondsToWait = 59
  87.     ThisSecond% = Val(Format$(Now, "ss"))
  88.     WaitUntil% = ThisSecond% + SecondsToWait
  89.     If WaitUntil% > 59 Then
  90.         WaitUntil% = WaitUntil% - 59
  91.         End If
  92. LoopWait:
  93.     NowSeconds% = Val(Format$(Now, "ss"))
  94.     If NowSeconds% <> WaitUntil% GoTo LoopWait
  95. End Sub
  96.  
  97.