vb6.0
keydown and key change
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim k As String
Private Sub Command1_Click()
MsgBox List1.Text
End Sub
Private Sub Form_Load()
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\My Documents\student.mdb;Persist Security Info=False"
cn.Open
End Sub
Private Sub List1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
ListView1.SetFocus
k = List1.Text
End If
End Sub
Public Sub getd()
ListView1.ListItems.Clear
'k = List1.Text
Dim sql As String
sql = "select * from assign where name='" & k & "' "
Dim x As Integer
x = 1
rs.Open sql, cn
Do While Not rs.EOF
ListView1.ListItems.Add = rs.Fields(5).Value
ListView1.ListItems(x).SubItems(1) = rs.Fields(2).Value
ListView1.ListItems(x).SubItems(2) = rs.Fields(3).Value
ListView1.ListItems(x).SubItems(3) = rs.Fields(9).Value
ListView1.ListItems(x).SubItems(4) = rs.Fields(7).Value
x = x + 1
rs.MoveNext
Loop
rs.Close
End Sub
Private Sub ListView1_GotFocus()
Call getd
End Sub
Private Sub ListView1_LostFocus()
'ListView1.ListItems.Clear
End Sub
Private Sub Text1_Change()
List1.Clear
Dim k As String
k = Text1.Text & "%"
Dim sql As String
sql = "select * from assign where NAME like('" & k & "');"
rs.Open sql, cn
Do While Not rs.EOF
List1.AddItem (rs.Fields(2).Value)
rs.MoveNext
Loop
rs.Close
End Sub
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyDown Or KeyCode = vbKeyUp Then
List1.SetFocus
End If
End Sub
VB 6.0(Click and keypress event on Listview)
To get element of listview1 into textbox and second lisview2
Public cn As New ADODB.Connection
Public rs As New ADODB.Recordset
Dim y As Integer
Private Sub Command1_Click()
Dim sql As String
sql = "select * from assign"
Dim x As Integer
x = 1
rs.Open sql, cn
Do While Not rs.EOF
ListView1.ListItems.Add = rs.Fields(0).Value
ListView1.ListItems(x).SubItems(1) = rs.Fields(1).Value
ListView1.ListItems(x).SubItems(2) = rs.Fields(2).Value
ListView1.ListItems(x).SubItems(3) = rs.Fields(3).Value
ListView1.ListItems(x).SubItems(4) = rs.Fields(4).Value
x = x + 1
rs.MoveNext
Loop
rs.Close
End Sub
Private Sub Form_Load()
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\My Documents\school.mdb;Persist Security Info=False"
cn.Open
y = 1
End Sub
Private Sub ListView1_Click()
Text1.Text = ListView1.SelectedItem.Text
Text2.Text = ListView1.SelectedItem.SubItems(1)
Text3.Text = ListView1.SelectedItem.SubItems(2)
Text4.Text = ListView1.SelectedItem.SubItems(3)
Text5.Text = ListView1.SelectedItem.SubItems(4)
End Sub
Private Sub ListView1_KeyPress(KeyAscii As Integer)
ListView2.ListItems.Add = ListView1.SelectedItem.Text
ListView2.ListItems(y).SubItems(1) = ListView1.SelectedItem.SubItems(1)
ListView2.ListItems(y).SubItems(2) = ListView1.SelectedItem.SubItems(2)
ListView2.ListItems(y).SubItems(3) = ListView1.SelectedItem.SubItems(3)
ListView2.ListItems(y).SubItems(4) = ListView1.SelectedItem.SubItems(4)
y = y + 1
End Sub
VB.NET selected item getting in Textbox
Coding of form(above)
Public Class Form1
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim z As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\My Documents\school.mdb"
cn.Open()
z = 1
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim sql As String
Dim x As Integer = 0
sql = "select * from assign"
rs.Open(sql, cn)
Do While Not rs.EOF
ListView1.Items.Add(rs.Fields(0).Value)
ListView1.Items(x).SubItems.Add(rs.Fields(1).Value)
ListView1.Items(x).SubItems.Add(rs.Fields(2).Value)
ListView1.Items(x).SubItems.Add(rs.Fields(3).Value)
ListView1.Items(x).SubItems.Add(rs.Fields(4).Value)
rs.MoveNext()
x = x + 1
Loop
rs.Close()
End Sub
Private Sub ListView1_ItemSelectionChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.ListViewItemSelectionChangedEventArgs) Handles ListView1.ItemSelectionChanged
TextBox1.Text = e.Item.Text
TextBox2.Text = e.Item.SubItems(1).Text
TextBox3.Text = e.Item.SubItems(2).Text
TextBox4.Text = e.Item.SubItems(3).Text
TextBox5.Text = e.Item.SubItems(4).Text
z = z + 1
End Sub
End Class
Another Example
Public rs As New ADODB.Recordset
Public sqlstr As String
Public litem As ListItem
Public Sub filllist()
sqlstr = "select * from productmst"
rs.Open sqlstr, gcon, adOpenDynamic, adLockBatchOptimistic
ListView1.ListItems.Clear
Do While Not rs.EOF
Set litem = ListView1.ListItems.Add(, , rs.Fields(0))
litem.ListSubItems.Add , , rs.Fields(1)
litem.ListSubItems.Add , , rs.Fields(2)
litem.ListSubItems.Add , , rs.Fields(3)
litem.ListSubItems.Add , , rs.Fields(4)
litem.ListSubItems.Add , , rs.Fields(5)
rs.MoveNext
Loop
rs.Close
ListView1.Sorted = True
End Sub
Private Sub Command1_Click()
End Sub
Private Sub Form_Load()
Call filllist
End Sub
Private Sub ListView1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
Text1.Text = ListView1.SelectedItem.Text
Text2.Text = ListView1.SelectedItem.SubItems(1)
Text3.Text = ListView1.SelectedItem.SubItems(2)
Text4.Text = ListView1.SelectedItem.SubItems(3)
Text5.Text = ListView1.SelectedItem.SubItems(4)
End If
End Sub
Private Sub Text2_Change()
Dim k As String
Dim i As Integer
k = Text2.Text & "%"
sqlstr = "select * from productmst where company like('" & k & "');"
rs.Open sqlstr, gcon, adOpenDynamic, adLockBatchOptimistic
ListView1.ListItems.Clear
Do While Not rs.EOF
Set litem = ListView1.ListItems.Add(, , rs.Fields(0))
litem.ListSubItems.Add , , rs.Fields(1)
litem.ListSubItems.Add , , rs.Fields(2)
litem.ListSubItems.Add , , rs.Fields(3)
litem.ListSubItems.Add , , rs.Fields(4)
litem.ListSubItems.Add , , rs.Fields(5)
rs.MoveNextLoop
rs.Close
ListView1.Sorted = True
'ListView1.HoverSelection = True
'ListView1.ListItems.Item(1).Selected = True
End Sub
Private Sub Text2_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyUp Or KeyCode = vbKeyDown Then
ListView1.SetFocus
End If
End Sub
module
Public gcon As New ADODB.Connection
Sub main()
gcon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\demo\demo.mdb;Persist Security Info=False"
gcon.Open
Form1.Show
End Sub
LOWER CASE TO UPPER CASE WITH SINGLE CHARACTER
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim str As String
Dim i, j, f As Integer
Dim ch As Char
i = TextBox1.Text
For j = 1 To i
ch = GetChar(TextBox1.Text, j)
If ch = " " Then
f = 1
Continue For
End If
If f = 1 Or j = 1 Then
If Asc(ch) = 65 And Asc(ch) = 97 Then
ch = Chr(Asc(ch) + 32)
End If
End If
Next
End Sub
End Class
To Link to OTHER site(vb.NET)
Button1_Click
System.Diagnostics.Process.Start("www.rkgenwa.yolasite.com")
End Sub
VB6.0
Private Sub Command1_Click()
If Option1.Value = True Then
MsgBox "Male"
Else
MsgBox "Female"
End If
End Sub
Private Sub Form_Load()
Option1.Value = True
End Sub
Public Class Form1
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim alrmtime = New DateTime(Today.Year, Today.Month, Today.Day, CInt(TextBox1.Text), CInt(TextBox2.Text), CInt(TextBox3.Text))
If Now > alrmtime Then
Beep()
End If
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
Timer1.Enabled = True
End Sub
Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged
Timer1.Enabled = False
End Sub
End Class
Change runtime short cut key of menu Item(VB.NET)
newToolStripMenuItem.ShortcutKeys = System.Windows.Forms.Shortcut.CtrlD
Text change
fileToolStripMenuItem.Text = "You clicked"
Check change when Clicked
fileToolStripMenuItem.Checked = Not FgfdgToolStripMenuItem.Checked
TreeView
To get the text of node
Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
MsgBox(e.Node.Text)
End Sub
To show the checkboxes with each node
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TreeView1.CheckBoxes = True
End Sub
Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
If e.Node.Checked = True Then
MsgBox("U checked" & e.Node.Text)
Else
MsgBox("U Unchecked" & e.Node.Text)
End If
End Sub
Structure in vb.net
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim r As rk
r.name = "rajesh"
MsgBox(r.name)
End Sub
Public Structure rk
Public name As String
Public fname As String ‘ u can add more emelent
End Structure
End Class
Object testing
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If sender Is Button2 Then ‘ that raised action of button or not
MsgBox("Hello u clicked oin button1")
Else
MsgBox("Hello u clicked oin button2")
End If
End Sub
Interface
Public Interface kr
Sub sert(ByVal str As String)
Function rk1() As Integer
End Interface
Implements kr
Multiple Inheritance
Or implements kr,rrr,pp ‘’many more
To get or set color of back color
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If Me.BackColor.ToKnownColor = KnownColor.Blue Then
Me.BackColor = Color.Aqua
End If
End Sub
ToolTip(vb.net)
Coding and properties for tooptip
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ToolTip1.SetToolTip(Button1, "Click Here to go ahead")
End Sub
properties of tooltip
isballoon -> true
backcolor->255, 192, 192
forecolor-> Blue
tooltip title->Ramesh Genwa Says
Listview Element Adding (VB6.0)
Code of above form:
Public litem As ListItem
Public Sub filllistview()
Set litem = ListView1.ListItems.Add(, , "1")
litem.ListSubItems.Add , , "rajesh"
litem.ListSubItems.Add , , "kumar"
litem.ListSubItems.Add , , "sharma"
litem.ListSubItems.Add , , "Jodhpur"
ListView1.Sorted = True
End Sub
you can clear listview as
ListView1.ListItems.Clear
Random function with shapes
Coding of above
form1 coding
Private Sub Form_Load()
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
'Text1.Text = Rnd * 100000 * Rnd * 2
'Text1.ForeColor = RGB(Rnd * 250, Rnd * 160, Rnd * 1050)
Shape2.Left = Shape2.Left + 4
Shape2.BackColor = RGB(Rnd * 250, Rnd * 160, Rnd * 1050)
Shape2.FillColor = RGB(Rnd * 2050, Rnd * 10, Rnd * 100)
Shape2.BorderColor = RGB(Rnd * 2050, Rnd * 10, Rnd * 100)
Shape3.Left = Shape3.Left + 5
Shape3.BackColor = RGB(Rnd * 250, Rnd * 160, Rnd * 1050)
Shape3.FillColor = RGB(Rnd * 2050, Rnd * 10, Rnd * 100)
Shape3.BorderColor = RGB(Rnd * 2050, Rnd * 10, Rnd * 100)
End Sub
mdi form coding :
Private Sub case_Click()
Me.Arrange vbCascade
End Sub
Private Sub new_Click()
Dim frm As New Form1
frm.Show
End Sub
Private Sub tile_Click()
Me.Arrange vbTileHorizontal
End Sub
Private Sub tilehori_Click()
Me.Arrange vbTileHorizontal
End Sub
Private Sub tiletextbar_Click()
'Me.Arrange vbTitleBarText
End Sub
Private Sub tilevertu_Click()
Me.Arrange vbTransparent
End Sub
Private Sub verticalq_Click()
Me.Arrange vbVertical
End Sub
After clicking at new menu and tileverti
VB.NET
TO show Print Dialog
use this
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dlg As New PrintDialog
dlg.ShowDialog()
End Sub
End Class
Open Dialog
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dlg As New OpenFileDialog
dlg.ShowDialog()
If dlg.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim fileName As String
fileName = dlg.FileName
MsgBox(fileName)
End If
End Sub
End Class
Color Dialog
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dlg As New ColorDialog
dlg.ShowDialog()
If dlg.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim str As String
str = dlg.Color.Name
MsgBox(str)
End If
End Sub
End Class
Font Dialog
Public Class Form1Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dlg As New FontDialog
dlg.ShowDialog()
If dlg.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim fontName As String
Dim fontSize As Integer
fontName = dlg.Font.Name
fontSize = dlg.Font.Size
MsgBox(fontName & " " & fontSize)
End If
End Sub
End Class
vb6.0
Picture box
Private Sub Command2_Click()
Picture1.Picture = LoadPicture("C:\rk.bmp")
End Sub
Private Sub Command2_Click()
Picture1 = LoadPicture("C:\rk.bmp")
End Sub
Open dialog
Private Sub Command1_Click()
CommonDialog1.ShowOpen
RichTextBox1.LoadFile (CommonDialog1.FileName)
End Sub
Normal load
Private Sub Command2_Click()
Picture1.Picture = LoadPicture("C:\rk.bmp")
End Sub
Open file using Common dialog box
Private Sub Command3_Click()
CommonDialog1.Filter = "Ritch text format|*.RTF|Word document|*.doc|ALL FILES|*.*|"
CommonDialog1.ShowSave
RichTextBox1.SaveFile (CommonDialog1.FileName)
End Sub
Picture Load using Common dialog box
Private Sub Command5_Click()
CommonDialog1.Filter = "jpg|*.jpeg|gif|*.gif|bmp|*.bmp|all|*.*|jpg|*.jpg| "
CommonDialog1.ShowOpen
Picture1 = LoadPicture(CommonDialog1.FileName)
End Sub
To change the title of In-built dialog
CommonDialog1.DialogTitle = "hell user"
Open dialog with title chage
Private Sub Command8_Click()
CommonDialog1.DialogTitle = "hello user u clicked on open"
CommonDialog1.ShowOpen
RichTextBox1.LoadFile (CommonDialog1.FileName)
End Sub
Private Sub Command1_Click()
CommonDialog1.Filter = "Ritch text format|*.RTF|Word document|*.doc|ALL FILES|*.*|"
CommonDialog1.ShowOpen
RichTextBox1.LoadFile (CommonDialog1.FileName)
End Sub
Private Sub Command2_Click()
'CommonDialog1.ShowOpen
Picture1.Picture = LoadPicture("C:\rk.bmp")
End Sub
Private Sub Command3_Click()
CommonDialog1.Filter = "Ritch text format|*.RTF|Word document|*.doc|ALL FILES|*.*|"
CommonDialog1.ShowSave
RichTextBox1.SaveFile (CommonDialog1.FileName)
End Sub
Private Sub Command4_Click()
CommonDialog1.ShowColor
'RichTextBox1.BackColor = CommonDialog1.Color
RichTextBox1.SelColor = CommonDialog1.Color
End Sub
Private Sub Command5_Click()
CommonDialog1.Filter = "jpg|*.jpeg|gif|*.gif|bmp|*.bmp|all|*.*|jpg|*.jpg| "
CommonDialog1.ShowOpen
If CommonDialog1.Max > CommonDialog1.Max Then
MsgBox "Error loading"
Else
Picture1 = LoadPicture(CommonDialog1.FileName)
End If
End Sub
Private Sub Command6_Click()
CommonDialog1.ShowPrinter
Printer.Copies = CommonDialog1.Copies
End Sub
Private Sub Command7_Click()
CommonDialog1.ShowColor
RichTextBox1.BackColor = CommonDialog1.Color
'RichTextBox1.SelColor = CommonDialog1.Color
End Sub
Private Sub Command8_Click()
CommonDialog1.DialogTitle = "hello user u clicked on open"
CommonDialog1.ShowOpen
RichTextBox1.LoadFile (CommonDialog1.FileName)
End Sub
oledb.doc Size : 72 Kb Type : doc |
|
COLOR CHANGING AT TIMER TICK.zip Size : 2.199 Kb Type : zip |
|
sqlwith listview.docx Size : 14.965 Kb Type : docx |
|