Reverse a String in VB6

Submitted by: 
Language: 
Visitors have accessed this post 3844 times.

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:

design

3.Now put this code for your code module. This code is for Command1_Click:

  1. Private Sub Command1_Click()
  2.  
  3. Dim lLen As Integer, lCtr As Integer
  4. Dim sChar As String
  5. Dim sAns As String
  6.  
  7. lLen = Len(Text1.Text)
  8. For lCtr = lLen To 1 Step -1
  9. sChar = Mid(Text1.Text, lCtr, 1)
  10. sAns = sAns & sChar
  11. Next
  12.  
  13. Label1.Caption = sAns
  14.  
  15. End Sub

Explanation:

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.

Output:

output

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.

Best Regards,

Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]

Add and Follow me on Facebook: https://www.facebook.com/donzzsky

Visit and like my page on Facebook at: https://www.facebook.com/BermzISware


Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.