Monday 19 December 2011

Check System Path Valid or Not


Imports System.IO
For this, I am using Textbox, two buttons named btnCheck and btnReset and a label for showing result.
Result will shown when check button is clicked after entering any system path in the textbox. 
If system path exist, result will be System Path Valid, otherwise System Path Not Valid.
Click event of btnCheck is Shown below
Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click
        If txtPath.Text = "" Then
            MsgBox("Enter Any System Path to Check")
            txtPath.Focus()
            Exit Sub
        End If
        Dim di As New DirectoryInfo(txtPath.Text)
        If di.Exists = True Then
            lblResult.Text = lblResult.Text + " Valid"
        Else
            lblResult.Text = lblResult.Text + " Not Valid"
        End If
    End Sub

Click Event of btnReset is given below
Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
        txtPath.Text = ""
        lblResult.Text = "System Path"
    End Sub

I am using one more event, for textbox. Ie., textchange Event
When textbox content is changed, the result label set to System Path.
Private Sub txtPath_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPath.TextChanged
        lblResult.Text = "System Path"
    End Sub

 When btnReset click, the content in the textbox set to Null and the result label set to  “System Path”.

No comments:

Post a Comment