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

How to Get the Length of the String Using Class Library

Author: DevASP
Download Source Code :

This sample program will brief you how you can get the length of the string by calling a VB6 Len function through Class Library object in your Project.

To begin with this application, create a new project in Visual Studio 2005 (VS2005) and add new class by selecting the Add à New Item à Class option by right clicking on your project from solution explorer. Now named this class as CCalStrLen and add the following code:


Public Class CCalStrLen


 'Global Varaible of String Type

Private ShowStrLength As String


  'Get the String From the User

Public Property GetStr() As String



     Return ShowStrLength

  End Get

  Set(ByVal value As String)

     ShowStrLength = value

  End Set


End Property


 'Calculate the length of the String

Public ReadOnly Property StrLen() As Long



    StrLen = Len(Me.ShowStrLength)

  End Get


End Property


End Class


Now all you have to do is add TextBox control, Button Control and Label control in your Form1.vb file and add the following code on  event:


Public Class Form1


Private Sub cmdSLength_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSLength.Click


Dim StringLength As New CCalStrLen


'Checks the length of the String

'if Zero error message is displayed


If (txtSLength.Text.Length > 0) Then


    StringLength.GetStr = txtSLength.Text




MsgBox("Enter String First", MsgBoxStyle.OkOnly, "Error Message")


End If


'Show the Length of the String

'which is entered by user


txtSLength.Text = StringLength.GetStr

lblShow.Visible = True

lblShow.Text = StringLength.StrLen.ToString


End Sub


End Class


Add Article Comment:
Name :
Email Address :
Comments :
<< How to make image of the form as it is on your drive on one button click using System.Drawing.Graphics

Disclaimer - Privacy
© 2002-2017