3 Replies - 4452 Views - Last Post: 18 March 2013 - 08:24 AM Rate Topic: -----

#1 emjei  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 17-March 13

Converting into different alternate CaSe after reversing the text

Posted 17 March 2013 - 07:10 AM

Hi guys! I'm a beginner here in vb.net world

My main task is to reverse the input text from a textbox to another textbox and change the casing of the output to:

Example:

Input: visual
Output: LaUsIv

I already searched for the proper code to use but it seems that my syntax is not appropriate. . .
What do I need to do? Thanks!


Attached Image

 Public Class frmReverse

    Private Sub btnReverse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReverse.Click
        txtOutput.Clear()

        Dim intLen As Integer
        Dim KeyAscii As Integer
        Dim j As Integer = Len(txtInput.Text)

        For i As Integer = 0 To Len(txtInput.Text) - 1
            txtOutput.Text += Mid(txtInput.Text, j - i, 1)
            intLen = Len(txtInput.Text)
                    If intLen Mod 2 = 0 Then
                        ' Upper case
                        KeyAscii = Asc(UCase(Chr(KeyAscii)))
                    Else
                        ' Lower case
                        KeyAscii = Asc(LCase(Chr(KeyAscii)))
                    End If
        Next

    End Sub

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        txtInput.Focus()
        txtInput.Clear()
        txtOutput.Clear()
    End Sub
End Class 


Is This A Good Question/Topic? 0
  • +

Replies To: Converting into different alternate CaSe after reversing the text

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Converting into different alternate CaSe after reversing the text

Posted 17 March 2013 - 07:48 AM

To start with, a string is just an array of characters. And like any array, you can get an element anywhere in it by specifying an index.

For example
strInput = "Visual Basic"
MessageBox.Show(strInput(1).ToString)

Would result in a message showing i because it is the char that is at element 1 in the array.

So knowing this you could effectively reverse a string just by using a reverse for...loop and building off the char(index) where index is the iterator of the loop.

Now with the casing, I would use a for each block. and increment an index to check for no remainder with Mod 2
ndx = 0
for each c as char in strInput
  if  modding the index with 2 shows no remainder
    concatenate to a variable the current char ( c.tostring.toupper)
  else
    concatenate same as above only toLower
  end if
increment your ndx
Next

This post has been edited by CharlieMay: 17 March 2013 - 07:49 AM

Was This Post Helpful? 1
  • +
  • -

#3 emjei  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 17-March 13

Re: Converting into different alternate CaSe after reversing the text

Posted 17 March 2013 - 07:57 AM

Hi CharliMay!

Thanks for the great help!

I'll do what I can from your given hint. . .
Was This Post Helpful? 0
  • +
  • -

#4 emjei  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 17-March 13

Re: Converting into different alternate CaSe after reversing the text

Posted 18 March 2013 - 08:24 AM

.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1