Difference between revisions of "The Basics of VB6"

From Free Knowledge Base- The DUCK Project: information for everyone
Jump to: navigation, search
(New page: These notes can be organized later. === Open a Form From Another Form === Open the form called frmCompanies frmCompanies.Show Open it so that the parent form cannot be clicked. To s...)
 
 
(20 intermediate revisions by one user not shown)
Line 1: Line 1:
 
These notes can be organized later.   
 
These notes can be organized later.   
  
=== Open a Form From Another Form ===
+
=== Select Case (Switch) ===
  
Open the form called frmCompanies
+
CASE in Visual BASIC does not "fall through" like in C.
  frmCompanies.Show
+
Open it so that the parent form cannot be clicked.  To suspend execution of the first form until after the second form is done with, add the keyword constant vbModal as an argument to the Show method.
+
  frmCompanies.Show vbModal
+
The Hide method of a form removes the form from the screen (makes it invisible), but the form still remains in memory.
+
  frmCompanies.Hide
+
  Me.Hide
+
  Hide
+
You can load a form in memory and not display it.
+
  Load frmCompanies
+
Unload form from memory (which also closes it)
+
  Unload Me
+
Example
+
  Private Sub Form_Unload(Cancel As Integer)
+
    If MsgBox("Are you sure you want to quit?", vbYesNo + vbQuestion, "Unload Test") = vbNo Then
+
      Cancel = 1
+
    End If
+
  End Sub
+
  
=== From Dimensions and Twip Units ===
+
  Select Case Button.Key
 +
    Case "ListCache"
 +
      mnuListCache_Click
 +
    Case "Refresh"
 +
      mnuRefresh_Click
 +
    Case "simmode"
 +
      cmdSimMode_Click
 +
  End Select
  
The default unit is the twip, which is 1/1440 of an inch for height, width, top, and left.
+
  Select Case tcpClient.State
 +
    Case 0
 +
      tcpClient.RemoteHost = cboRemoteHost
 +
      SessionConnect
 +
    Case 7
 +
      lblStatus.Caption = "Connected"
 +
    Case 9
 +
      lblStatus.Caption = "Connection Error"
 +
  End Select
  
Pixels to Twip:
+
Case based on more than one condition
   W = W * Screen.TwipsPerPixelX
+
 
  H = H * Screen.TwipsPerPixelY
+
   Select Case True
Twips to Pixel:
+
    Case strMessage Like "*OK*" And lblStatus.Caption = "Connected"
   W = W / Screen.TwipsPerPixelX
+
    blnReceivedAll = True
   H = H / Screen.TwipsPerPixelY
+
  Case strMessage Like "*OK*" And lblStatus.Caption = "retrieving."
 +
    lblStatus.Caption = "retrieving.."
 +
    blnReceivedAll = True
 +
   Case Else
 +
    Set LoopTime = New TimerClass: tmrDisconnect.Enabled = True
 +
   End Select
 +
 
 +
=== Public Declarations ===
 +
 
 +
Public strCurrentTool As String
 +
 
 +
Public fMainForm As frmQAB
 +
 
 +
Public cn As ADODB.Connection
 +
 
 +
Public rsCompanies As ADODB.Recordset
 +
 
 +
Public Const dbtContact = "contact"
 +
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
[[Category:Computer Technology]]
 +
[[Category:Programming]]
 +
[[Category:VB6]]

Latest revision as of 10:55, 2 February 2008

These notes can be organized later.

Select Case (Switch)

CASE in Visual BASIC does not "fall through" like in C.

 Select Case Button.Key
   Case "ListCache"
     mnuListCache_Click
   Case "Refresh"
     mnuRefresh_Click
   Case "simmode"
     cmdSimMode_Click
 End Select
 Select Case tcpClient.State
   Case 0
     tcpClient.RemoteHost = cboRemoteHost
     SessionConnect
   Case 7
     lblStatus.Caption = "Connected"
   Case 9
     lblStatus.Caption = "Connection Error"
 End Select

Case based on more than one condition

 Select Case True
   Case strMessage Like "*OK*" And lblStatus.Caption = "Connected"
   blnReceivedAll = True
 Case strMessage Like "*OK*" And lblStatus.Caption = "retrieving."
   lblStatus.Caption = "retrieving.."
   blnReceivedAll = True
 Case Else
   Set LoopTime = New TimerClass: tmrDisconnect.Enabled = True
 End Select

Public Declarations

Public strCurrentTool As String
Public fMainForm As frmQAB
Public cn As ADODB.Connection
Public rsCompanies As ADODB.Recordset
Public Const dbtContact = "contact"