Reverse a String in VB6
Hi! In this tutorial, we will create a program that reverses a string. I already made this one in vb.net but it has different code in vb6.0.
Now, let's start this tutorial!
1.Let's start this tutorial by following the following steps in Microsoft Visual Basic 6.0: Open Microsoft Visual Basic 6.0, click Choose Standard EXE, and click Open.
2. Next, add only one Button named Command1 and labeled it as "Reverse". Add one TextBox named Text1 for your input and also one Label named Label1 that will serve to display your output.You must design your interface like this:
3.Now put this code for your code module. This code is for Command1_Click:
- Private Sub Command1_Click()
- Dim lLen As Integer, lCtr As Integer
- Dim sChar As String
- Dim sAns As String
- lLen = Len(Text1.Text)
- For lCtr = lLen To 1 Step -1
- sChar = Mid(Text1.Text, lCtr, 1)
- sAns = sAns & sChar
- Label1.Caption = sAns
- End Sub
We initialized lLen as Integer to hold the length of the text inputted in Text1. Len function returns an integer containing either the number of characters in a string or the nominal number of bytes required to store a variable. Then we have created a For Next loop that the lCtr variable will hold the value of variable lLen up to 1 Step -1. Step specifies an increment value for a loop counter. sChar variable was used to get the middle of Text1, the start of the mid which is lCtr and 1 as the length. Mid Function returns a string containing a specified number of characters from a string. Then sAns variable will hold the value of our variable sChar and will be displayed in Label1.
Download the source code and try it! :)
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.
Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
Add and Follow me on Facebook: https://www.facebook.com/donzzsky
Visit and like my page on Facebook at: https://www.facebook.com/BermzISware