Make your own free website on Tripod.com

String Reversal Program

 

 

This is string reversal program that made use of the Len and the Mid functions in VB. Lets recall what is the Mid function. The Mid function extracts a substring from the original phrase or string. It takes the following format:

Mid(phrase, position, n)

Where position is the starting position of the phrase from which the extraction process will start and n is the number of characters to be extracted. In this program, I am using a combination of the Len and the Mid functions to extract  one character at a time from a phrase entered by the user, starting from the back and gradually move infornt using the For...Next Loop. I have also created another procedure to restore the phrase, based on the same principle. Here is the Program:

 

Private Sub Text1_Change()

End Sub

Public Sub Command1_Click()
Dim phrase, final_Phrase As String
Dim pos As Integer
Lbl_Rev.Caption = ""
phrase = Or_Text.Text
For pos = Len(phrase) To 1 Step -1
Lbl_Rev.Caption = Lbl_Rev.Caption & Mid(phrase, pos, 1)
Next

final_Phrase = Lbl_Rev.Caption
End Sub


Private Sub Command2_Click()
Dim final_Phrase As String
final_Phrase = Lbl_Rev.Caption
Lbl_Rev.Caption = ""
For pos = Len(final_Phrase) To 1 Step -1
Lbl_Rev.Caption = Lbl_Rev.Caption & Mid(final_Phrase, pos, 1)
Next
End Sub
.

and here is the Interface

 

 

 

 [Back to VBToday]