Common Visual Basic 6 Codes


Adding items in the combo box from a database
--Form Load--

Adodc1.Refresh
With Adodc1.Recordset
If .RecordCount > 0 Then .MoveFirst
While .EOF = False
Combo1.AddItem !UserName
.MoveNext
Wend
End With

Verifying Username and Password in the Login Form --Command Button(Login)-- x = "username = '" & Combo1.Text & "'" With Adodc1.Recordset If .RecordCount > 0 Then .MoveFirst .Find x If .EOF = False Then pass = !Password If pass = txtPassword.Text Then Form1.Show Unload Me Else MsgBox "Invalid Password!" txtPassword.Text = "" txtPassword.SetFocus End If End If End With
Finding Record (Searching Database for a single record) --Command Button(Search)-- a = Text1.Text temp = "lastname= '" & a & "'" With Adodc1.Recordset .MoveFirst .Find (temp) If .EOF = True Then MsgBox "Record not found!" Else MsgBox "Record Found!" End If End With
Filtering Records with option buttons(grouping same records) --Command Button(Filter)-- Gen. Declaration Dim x As Integer Private Sub Option1_Click(Index As Integer) x = Index End Sub Private Sub Filter_Click() If x = 0 Then Adodc1.Recordset.Filter = "lastname= '" & Text1.Text & "'" ElseIf x = 1 Then Adodc1.Recordset.Filter = "firstname= '" & Text1.Text & "'" End If If Adodc1.Recordset.EOF = True Then Adodc1.Refresh MsgBox "record not found" End If End Sub
Determining if Even or Odd number(If Statement) Private Sub Command1_Click() num = txt1.Text If num Mod 2 = 0 Then MsgBox "Even" Else MsgBox "Odd" End If End Sub
Determining if Even or Odd number(Select Case) Private Sub Command1_Click() num = Val(txt1.Text) Mod 2 Select Case num Case 0 MsgBox "Even" Case Else MsgBox "Odd" End Select End Sub
Getting the total amount from the DataGrid With Adodc1.Recordset If .RecordCount > 0 Then .MoveFirst Sum = 0 While .EOF = False Sum = Sum + !amount .MoveNext Wend text1.Text = Sum End With
Inserting Image from File Private Sub Image1_DblClick() cdialog.Filter = "JPEG Files(*.jpg)|*.jpg|BITMAP Files(*.bmp)|*.bmp|GIF Files(*.gif)|*.gif" cdialog.DefaultExt = "*.jpg" cdialog.ShowOpen If cdialog.FileName <> "" Then Image1.Picture = LoadPicture(cdialog.FileName) txtphoto.Text = cdialog.FileName End If End Sub
Copyright © 2007-2010 All Rights Reserved Kakeru's World
Hosted by www.Geocities.ws

1