Results 1 to 2 of 2

Thread: Palindrome Part 2

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Location
    Illinois
    Posts
    27
    Could someone explain this code line by line and explain how to create a form.

    Dim intPosition As Integer
    Dim strText As String
    Dim strResult As String

    strText = txtInput.Text

    While intPosition =< Len(strText)
    intPosition = intPosition + 1
    strResult = Mid(strText, intPosition, 1) & strResult
    Wend

    If strResult = strText Then
    MsgBox "The string is a palindrome!"
    End If
    I'm a MICKEY FAN

  2. #2
    Guest
    Line by line:
    Code:
    'In this part we declare all of our variables
    Dim intPosition As Integer 
    Dim strText As String 
    Dim strResult As String 
    
    'We store the text that the user inputted in a variable
    strText = txtInput.Text
    
    'This loop tells VB to perform the loop as
    'long as the position is in the bounds of the string.
    While intPosition =< Len(strText)
        'Increase the position by one
        intPosition = intPosition + 1
        'Put the current letter at the BEGINNING of
        'the resulting string.
        strResult = Mid(strText, intPosition, 1) & strResult
    'End the loop
    Wend 
    
    'If the result (the reversed text) is the same as the source, then it is a palindrome
    If strResult = strText Then 
        MsgBox "The string is a palindrome!" 
    End If
    About the form:
    Click on File > New Project > Standard EXE Project.
    A form will automatically be created.
    Put a TextBox on the form and name it txtInput.
    Put a CommandButton on the form and name it cmdCheck.
    Double-click on the button and you will be taken to the cmdCheck_Click() event.
    Put the above code in this procedure.

    Good luck!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width