Visual Basic Tip: 11/13/95


Short Code Tips.
* Center a form on screen
    
  form1.Move (Screen.Width - Width) \ 2, (Screen.Height - Height) \ 2

* Assign app path to a string
 
  pth$ = app.Path & IIf(Len(app.Path) > 3, "\", "")

* Quick 'About' box

  Declare Sub ShellAbout Lib "shell.dll" (ByVal hWndOwner%, ByVal lpszAppName$, ByVal lpszMoreInfo$, ByVal hIcon%)
 
  ShellAbout hwnd, "About Window Caption", "Application Title", icon

* A Status gauge.  This is a very low resource usage method of creating a status bar.
  Simply place a standard VB label control on a form where you want the gauge to appear.
  Also clear the caption property.  Note, the graphical gauge appears immediately above
  the label control.

  Sub LabelStatus (cntl As Label, ByVal percent)
    clr = RGB(0, 0, 255)  'use a blue bar
    cntl.Parent.Line (cntl.Left, cntl.Top - cntl.Height)-Step(percent / 100 * cntl.Width, cntl.Height * .9), clr, BF
    cntl.Caption = Format$(percent, "#") + "% Complete"
    cntl.Refresh
  End Sub

  Sub Command1_Click () 
    label1.Alignment = 2  'center
    max = 50000
    onepercent = .01 * max

    For i = 1 To 50000
      If i Mod onepercent& = 0 Then LabelStatus label1, (i / max) * 100
    Next

    label1.Caption = ""
    Cls
  End Sub

* Generate random whole numbers (integer/long integer) between two values.
  The end values are included in the range of possible random numbers.
  Note, you should call Randomize on form load to ensure a random sequence.

  minr = 45
  maxr = 12000
  randno = minr + Fix(Rnd * (maxr - minr + 1))
Return to Phil's Web Page

Created by: Philip