Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 136,558 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,926 people online right now. Registration is fast and FREE... Join Now!




How would i program to reverse my name?

 
Reply to this topicStart new topic

How would i program to reverse my name?

BadwithVB
10 May, 2008 - 12:55 PM
Post #1

New D.I.C Head
*

Joined: 10 May, 2008
Posts: 5



I have tried a bunch of way but i still can't figure it out:

CODE

        Dim fullName As String
        Dim firstName As String
        'Dim lastName As String
        Dim indexNum As Integer

        fullName = fullNameTextBox.Text

        indexNum = fullName.IndexOf(" ")


        firstName = fullName.Substring(0, indexNum)


        fullNameLabel.Text = firstName
        fullNameTextBox.Focus()

User is offlineProfile CardPM
+Quote Post

Martyr2
RE: How Would I Program To Reverse My Name?
10 May, 2008 - 01:15 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,213



Thanked: 217 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Well here is one way right off the top of my head... probably not the most efficient but surely will work...

vb

Private Sub Command1_Click()
Dim name As String
Dim namereversed As String

name = "Martyr2"
namereversed = ""

Dim i As Integer
For i = Len(name) To 1 Step -1
namereversed = namereversed & Mid(name, i, 1)
Next

fullNameLabel.Caption = namereversed
End Sub


This is written assuming you are talking about vb6. If you are talking about .NET then you can write this even simpler...

vb

Dim name As String = "Martyr2"
Dim namereversed As String = ""

For i As Integer = name.Length - 1 To 0 Step -1
namereversed &= name.Substring(i, 1)
Next

fullNameLabel.Text = namereversed


Play with them and I am sure they will do as you like. Enjoy!

smile.gif
User is offlineProfile CardPM
+Quote Post

BadwithVB
RE: How Would I Program To Reverse My Name?
10 May, 2008 - 01:25 PM
Post #3

New D.I.C Head
*

Joined: 10 May, 2008
Posts: 5

oh i forgot to mention I'm using 2005 version..@_@ hense why i dont really understand alot of your variables
User is offlineProfile CardPM
+Quote Post

kyrotomia
RE: How Would I Program To Reverse My Name?
10 May, 2008 - 01:39 PM
Post #4

D.I.C Head
**

Joined: 5 May, 2007
Posts: 50



Thanked: 1 times
My Contributions
Martyr2's code is doing this :
you set Martyr2 in a variable "name"
declare a variable "namereversed" to put in the reversed name (letter by letter).

Then does a loop starting from the last letter of the name to the first one (Name.Length gives the length of the name, you can then substract each letters (note that their index starts at 0, thus "length -1")). In that loop, you fill "namereversed" with the letters from martyr2 (backward...).

Finally, he puts the results in a label(presuming you have one in your form).

Hope that may help you!
User is offlineProfile CardPM
+Quote Post

BadwithVB
RE: How Would I Program To Reverse My Name?
10 May, 2008 - 01:50 PM
Post #5

New D.I.C Head
*

Joined: 10 May, 2008
Posts: 5

i see but its not right, its spelling the name backwards.

I want my program to do this:

I want to enter my name from a textbox and then it displays in a label

so if i enter Jerry Springer

then i get

Lastname(comma)(Space) first name

like this Springer, Jerry


I dont think i made it clear, =(
thanks for info thou
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: How Would I Program To Reverse My Name?
10 May, 2008 - 01:56 PM
Post #6

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,997



Thanked: 125 times
Dream Kudos: 8625
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Moved to VB.NET
User is offlineProfile CardPM
+Quote Post

BadwithVB
RE: How Would I Program To Reverse My Name?
10 May, 2008 - 02:03 PM
Post #7

New D.I.C Head
*

Joined: 10 May, 2008
Posts: 5

I dont know why you moved to .net. I'm using Visual Basic 2005
User is offlineProfile CardPM
+Quote Post

aNiXtEr
RE: How Would I Program To Reverse My Name?
10 May, 2008 - 02:26 PM
Post #8

New D.I.C Head
Group Icon

Joined: 8 Feb, 2007
Posts: 25


My Contributions
.NET refers to versions of VB past VB6. The VB language contained in Visual Studio 2005 uses the .NET framework.
User is offlineProfile CardPM
+Quote Post

aNiXtEr
RE: How Would I Program To Reverse My Name?
10 May, 2008 - 03:00 PM
Post #9

New D.I.C Head
Group Icon

Joined: 8 Feb, 2007
Posts: 25


My Contributions
This is an example off the top of my head but at least it is functional.
CODE

        Dim firstName As String = "Jerry"
        Dim lastName As String = "Springer"

        MessageBox.Show(lastName + ", " + firstName)


User is offlineProfile CardPM
+Quote Post

BadwithVB
RE: How Would I Program To Reverse My Name?
10 May, 2008 - 06:13 PM
Post #10

New D.I.C Head
*

Joined: 10 May, 2008
Posts: 5

ya i know that part, but i'm having a problem with figuring the lenth from frist to last night..

Can it really be this difficult to do Springer, Jerry in a Labelbox?


User is offlineProfile CardPM
+Quote Post

FutureC0der
RE: How Would I Program To Reverse My Name?
11 May, 2008 - 07:55 PM
Post #11

New D.I.C Head
*

Joined: 11 May, 2008
Posts: 2

QUOTE(BadwithVB @ 10 May, 2008 - 02:50 PM) *

i see but its not right, its spelling the name backwards.

I want my program to do this:

I want to enter my name from a textbox and then it displays in a label

so if i enter Jerry Springer

then i get

Lastname(comma)(Space) first name

like this Springer, Jerry


I dont think i made it clear, =(
thanks for info thou


Okay, I think this MAY help you. Let me know if it works!

FYI you can replace "me.inputBox.text" with the input textbox name in your form. Also, you can replace "Me.Output.Text" with the LABEL name in your form.

CODE

    Private Sub convertButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles convertButton.Click
        Dim input As String
        Dim indexNum As Integer
        Dim lastName As String
        Dim firstName As String
        Dim output As String

        input = Me.inputBox.Text

        indexNum = input.IndexOf(" ", 0)
        lastName = input.Remove(0, indexNum + 1)
        firstName = input.Remove(indexNum)

        output = lastName + ", " + firstName
        Me.Output.Text = output


    End Sub

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 11:29PM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month