Visual Basic String Function : Mid
Purpose : The Mid functions the specified portion of a string expression.
Syntax :
Mid ( strExpression , ingStart [ , ingLength ] )
MidB ( strExpression , ingStart [ , ingLength ] )
strExpression : Specifies the string from which you want to return a substring.
ingStart : Specifies the starting position for the returned substring.
ingLength : Specifies the number of characters of the returned substring.
Mid ( strExpression , ingStart [ , ingLength ] )
MidB ( strExpression , ingStart [ , ingLength ] )
strExpression : Specifies the string from which you want to return a substring.
ingStart : Specifies the starting position for the returned substring.
ingLength : Specifies the number of characters of the returned substring.
Dim strGood as String
Dim strBye as String , strDolly as String
strGood = "Good bye, Arvind"
strBye = Mid ( strGood, 6 , 3 )
strDolly = Mid ( strGood , 11 )
The first example uses the Mid function to assign the value " bye " to the variable strBye. In the second example, the length parameter is omitted so the string returned starts where indicated and continues for the balance of then length of strGood . Therefore , the variable strDolly is assigned the value " Arvind "
Dim strBye as String , strDolly as String
strGood = "Good bye, Arvind"
strBye = Mid ( strGood, 6 , 3 )
strDolly = Mid ( strGood , 11 )
The first example uses the Mid function to assign the value " bye " to the variable strBye. In the second example, the length parameter is omitted so the string returned starts where indicated and continues for the balance of then length of strGood . Therefore , the variable strDolly is assigned the value " Arvind "
Using this in Form
Private Sub Command1_Click()
Dim i As Integer
Dim strS As String
Dim strD As String
strS = Text1.Text
i = Len(Text1.Text)
strD = Mid(strS, 1, i - 1)
Text2.Text = strD
End Sub
Dim i As Integer
Dim strS As String
Dim strD As String
strS = Text1.Text
i = Len(Text1.Text)
strD = Mid(strS, 1, i - 1)
Text2.Text = strD
End Sub
No comments:
Post a Comment