Friday, September 23, 2016

DAO in Visual 2010 Express Edition

Reference to be added before :

----DAO 3.51 library
---- Access object library
This is for Advance MSoffice (Access) environment
---- Browse -> C - > programfiles - > MS office -> ACEDAO.dll




Below are the coding for DAO database process
-------------------------------------------------------------------------------------------------------------


Imports DAO
Imports System.Data
Public Class Form1
    Dim dp As String = "D:\StudentDB.accdb"
    Dim ae As New Microsoft.Office.Interop.Access.Dao.DBEngine
    Dim db As Microsoft.Office.Interop.Access.Dao.Database = ae.Workspaces(0).OpenDatabase(dp)
    Dim dbrecordset As Microsoft.Office.Interop.Access.Dao.Recordset = db.OpenRecordset("StuTable")

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        dbrecordset.MoveFirst()
        TextBox1.Text = dbrecordset.Fields("ID").Value
        TextBox2.Text = dbrecordset.Fields("Sname").Value
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        dbrecordset.MoveFirst()
        TextBox1.Text = dbrecordset.Fields("ID").Value
        TextBox2.Text = dbrecordset.Fields("Sname").Value

    End Sub

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        Try
            If dbrecordset.EOF Then
                MsgBox("No records")
            Else

                dbrecordset.MoveNext()
                TextBox1.Text = dbrecordset.Fields("ID").Value
                TextBox2.Text = dbrecordset.Fields("Sname").Value

            End If
        Catch ex As Exception
            MsgBox("No records")
        End Try
      

    End Sub

    Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
        dbrecordset.MoveLast()
        TextBox1.Text = dbrecordset.Fields("ID").Value
        TextBox2.Text = dbrecordset.Fields("Sname").Value
    End Sub


    Private Sub Button4_Click(sender As Object, e As System.EventArgs) Handles Button4.Click
        Try
            If dbrecordset.BOF Then
                MsgBox("No records")
            Else

                dbrecordset.MovePrevious()
                TextBox1.Text = dbrecordset.Fields("ID").Value
                TextBox2.Text = dbrecordset.Fields("Sname").Value

            End If
        Catch ex As Exception
            MsgBox("No records")
        End Try
       
    End Sub

    Private Sub Button5_Click(sender As System.Object, e As System.EventArgs) Handles Button5.Click
        dbrecordset.AddNew()
        dbrecordset.Fields("ID").Value = Val(TextBox1.Text)
        dbrecordset.Fields("Sname").Value = TextBox2.Text
        dbrecordset.Update()
        dbrecordset.MoveLast()

    End Sub

    Private Sub Button6_Click(sender As System.Object, e As System.EventArgs) Handles Button6.Click
        dbrecordset.Edit()
        Do Until dbrecordset.EOF
            ' s = dbrecordset.Fields("ID").Value
            If dbrecordset.Fields("ID").Value = Val(TextBox1.Text) Then

                dbrecordset.Fields("Sname").Value = TextBox2.Text
                dbrecordset.Update()
            End If
            dbrecordset.MoveNext()
        Loop
    End Sub


    Private Sub Button7_Click(sender As System.Object, e As System.EventArgs) Handles Button7.Click
        TextBox1.Text = ""
        TextBox2.Text = ""


    End Sub

    Private Sub Button8_Click(sender As System.Object, e As System.EventArgs) Handles Button8.Click
        dbrecordset.Delete()

        TextBox1.Text = ""
        TextBox2.Text = ""
    End Sub
End Class
---------------------------------------------------------------------------------------------------------






Wednesday, August 10, 2016

Control Array (single event for multiple handlers) , Picture box control

Public Class Form2

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click

        Dim btn As Button = CType(sender, Button)
        MessageBox.Show(btn.Text)

    End Sub

    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click, PictureBox2.Click, PictureBox3.Click, PictureBox4.Click

        Dim pb As PictureBox = CType(sender, PictureBox)

        Select Case CInt(pb.Tag)
            Case 0
                pb.Image = Image.FromFile("D:\SD_SampleVBpgm\img1.jpg")
                pb.SizeMode = PictureBoxSizeMode.StretchImage


            Case 1
                pb.Image = Image.FromFile("D:\SD_SampleVBpgm\img2.jpg")
                pb.SizeM(ode = PictureBoxSizeMode.AutoSize)

            Case 2
                pb.Image = Image.FromFile("D:\SD_SampleVBpgm\img3.jpg")
                pb.SizeMode = PictureBoxSizeMode.Zoom


        End Select
    End Sub
End Class

Tuesday, August 9, 2016

Working with Arrays

Public Class Form1
    Dim str(10) As String
    Dim incr As Integer
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'inserting values to array
        For incr = 0 To 10

            str(incr) = InputBox("enter name")

        Next

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        'display all the array values
        For incr = 0 To str.Length - 1
            MessageBox.Show(str(incr))
        Next

    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        incr = 0
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        'search for a particular string
        Dim searchStr As String
        searchStr = InputBox("enter a string")
        For incr = 0 To str.Length - 1

            'a string contains a string
            If str(incr).Contains(searchStr) Then
                MessageBox.Show(str(incr))
            End If

        Next

    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        'remove a particular string
        Dim searchStr As String
        searchStr = InputBox("enter a string")

        'using of list object to remove a string
        Dim strList As List(Of String) = str.ToList()
        strList.Remove(searchStr)
        str = strList.ToArray()

    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        'search for a particular string
        Dim searchStr As String
        searchStr = InputBox("enter a string")
        For incr = 0 To str.Length - 1

            'a string contains a string
            If str(incr).EndsWith(searchStr) Then
                MessageBox.Show(str(incr))
            End If

        Next
    End Sub

  
End Class

Thursday, July 21, 2016

VB 2010 Mouse Events

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

   

    Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown

        If e.Button = MouseButtons.Left Then

            Me.BackColor = Color.AliceBlue
        ElseIf e.Button = MouseButtons.Right Then
            Me.BackColor = Color.Chocolate


        End If

    End Sub

    Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
        Label1.Text = "X= " & e.X & "  " & "Y = " & e.Y

    End Sub



    Private Sub Form1_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseWheel


        Dim r, g, b As Integer

        r = e.X
        g = e.Y




        If r > 255 Then
            r = r / 255

        End If
        If g > 255 Then
            g = g / 255

        End If
        Me.BackColor = Color.FromArgb(r, g, 150)
    End Sub
End Class

Tuesday, September 1, 2015

Query String , ViewState , Session

Query String : to send information through URL

 Response.Redirect("Default3.aspx?val1=ass&val2=" & TextBox1.Text)

The query string cannot be viewed as well as the current page URL will be shown even after the redirection of web page.

        Server.Transfer("Default3.aspx?val1=ass&val2=" & TextBox1.Text)


To retrieve information from URL
 Response.Write(Request.QueryString("val1") + "  " + Request.QueryString("val2"))



Viewstate : syntax

 increment of  viewstate  value which can be saved even after the page postback.
           ViewState("cnt") = ViewState("cnt") + 1 


Session : syntax


' Check in Page load of  a webpage

if  textbox1.text= "vamsi" then
Session("username")=textbox1.text 
response.redirect("homepage.aspx")
endif

'below code with in homepage.aspx  at pageload even


Response.write("Welcome " + Session("username"))


'Checking of user name on each webpage at pageload event

'the below code should check whether the username is hari or not. if its hari its move on to the else part or it will redirect the page which created by the user "errpage.aspx" 

' the thing is it may not allow the current page to the unauthorised user

If Session("username") <> "hari" Then

            Response.Redirect("errpage.aspx")


        Else

            Response.Write(Request.QueryString("val1") + "  " + Request.QueryString("val2"))

        End If