Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

How to check syntax (Machine name, path, rooted path) using syntax class in VB and C#.

Author: Zunnair
Download Source Code : 916_syntaxcheck.zip

In this simple article you will learn that how we can syntax of machine name, path and rooted path using syntax check class in VB and C#.

 

Syntax class is used to check the syntax of machine name, path and rooted path. This class has static functions to perform these operations.
Check Machine Name:
To check that the machine name is in correct syntax or not, for this purpose syntax class provides us a function name check machine name ().This function takes a string as a name of machine and returns Boolean. It checks that ‘\’ is in machine name sting or not. If ‘\’ exists in string it returns false otherwise its returns true, means string is in correct syntax.
To demonstrate make a window application. Drag text box and one button on form. Write machine name in box and press button.
Now write the following code on Button click event:
C#
private void btn_Machine_Click(object sender, EventArgs e)
        {
           string str=string.Empty;
            str = txt_Machine.Text;
            bool b;
            if (str != string.Empty)
            {
                b = SyntaxCheck.CheckMachineName(str);
                str = b.ToString();
                MessageBox.Show(str);
            }
            else
                MessageBox.Show("please enter machine name");
        }
VB
Private Sub btn_Machine_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim str As String = String.Empty
        str = txt_Machine.Text
        Dim b As Boolean
        If str <> String.Empty Then
            b = SyntaxCheck.CheckMachineName(str)
            str = b.ToString()
            MessageBox.Show(str)
        Else
            MessageBox.Show("please enter machine name")
        End If
    End Sub
This simple code checks the machine name syntax.
Path:
To check that the path is in correct syntax or not, for this purpose syntax class provides us a function name check path ().This function takes a string as a path and returns Boolean. It checks that path starts with ‘\\’ or not. If path starts with ‘\\’ it returns true, means string is in correct syntax else returns false.
To demonstrate make a window application. Drag text box and one button on form. Write path in box and press button.
Now write the following code on Button click event:
C#
private void btn_Path_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = txt_Path.Text;
            bool b;
            if (str != string.Empty)
            {
                b = SyntaxCheck.CheckPath(str);
                str = b.ToString();
                MessageBox.Show(str);
            }
            else
                MessageBox.Show("please enter path");
        }
VB
Private Sub btn_Path_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim str As String = String.Empty
        str = txt_Path.Text
        Dim b As Boolean
        If str <> String.Empty Then
            b = SyntaxCheck.CheckPath(str)
            str = b.ToString()
            MessageBox.Show(str)
        Else
            MessageBox.Show("please enter path")
        End If
    End Sub
This simple code checks the path syntax.
Root Path:
To check that the root path is in correct syntax or not, for this purpose syntax class provides us a function name check root path ().This function takes a string as a path and returns Boolean. It checks that root path starts with ‘\’ or drive name or not. If path starts with ‘\\’ or drive name it returns true, means string is in correct syntax else returns false.
To demonstrate make a window application. Drag text box and one button on form. Write root path in box and press button.
Now write the following code on Button click event:
C#
private void btn_RootPath_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            str = txt_root.Text;
            bool b;
            if (str != string.Empty)
            {
                b = SyntaxCheck.CheckRootedPath(str);
                str = b.ToString();
                MessageBox.Show(str);
            }
            else
                MessageBox.Show("please enter root path");
        }
VB
Private Sub btn_RootPath_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim str As String = String.Empty
        str = txt_root.Text
        Dim b As Boolean
        If str <> String.Empty Then
            b = SyntaxCheck.CheckRootedPath(str)
            str = b.ToString()
            MessageBox.Show(str)
        Else
            MessageBox.Show("please enter root path")
        End If
    End Sub
This simple code checks the root path syntax.
Now write the following code on FORM LOAD event:
C#
private void Form1_Load(object sender, EventArgs e)
        {
            this.Text = "Devasp Syntax Check Application";
        }
VB
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
        Me.Text = "Devasp Syntax Check Application"
    End Sub
This simple article tells that how we can syntax of machine name, path and rooted path using syntax check class in VB and C#.
   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Buffer Class Operations in VB and C# (.net 2.0).

Disclaimer - Privacy
© 2002-2017 DevASP.net