Link to home
Start Free TrialLog in
Avatar of cjesgo
cjesgo

asked on

String Manipulation...

I need to create a function that will take a string from and input box (say a first name), read it one character at a time and redisplay it to the user. This is a school project so I can do this however I chose. My thought was to have a user input his name, the function would count the characters in the string, and redisplay it in a label box. I need help creating this function. I toyed around with the
Len(), and Mid() but I am lost.
Avatar of bobbit31
bobbit31
Flag of United States of America image

we can't do your homework for you, however, if you post what you have so far, i'm sure we can help you towards a solution
Avatar of cjesgo
cjesgo

ASKER

bobbit31 - after rereading my post I guess that is how I came across...sorry. I just need a some guideness. Here is what I have:

    Dim strFirst As String
    Dim strLast As String
    Dim strFull As String


    'Get the first name for the textbox
    strFirst = txtFname.Text

    'Get the last name from another textbox
    strLast = txtLname.Text

    'Concatenate the first and last name, putting
    'a space character between them.
    strFull = strFirst & " " & strLast
   
    'Display the Full Name
    lblResult.Caption = strFull

Dim szText As String
    Dim nStartingFrom As Integer
    Dim nNumChars As Integer

    '-- Assign szText
    szText = txtFname.Text
   
    '-- Set the starting position
    nStartingFrom = 1

    '-- Set the number of characters
    nNumChars = 1
   
    '-- Print the partial string
    Print Mid$(szText, nStartingFrom, nNumChars)

I imagine I need some sort of counter to keep track of how many characters in the string correct?  Thanks.
Do you mean something like this:

Dim MyValue As String
MyValue = InputBox(Message, Title, Default, 100, 100)

Dim TempChar As String
Dim CountChar As Integer
For I = 1 To Len(MyValue)
    CountChar = CountChar + 1
    TempChar = TempChar + Mid(MyValue, I, 1)
Next I
Label1.Caption = TempChar
Label2.Caption = CountChar
Short of doing your project for you, here's an example of how to use a FOR loop to display the string one character at a time.  This will display the results to a text box called Text1.

e.g.

Private Sub ShowResults(sINPUT As String)
   
    For i = 1 To Len(sINPUT)
        Text1.Text = Text1.Text & Mid(sINPUT, i, 1)
    Next i
   
End Sub
> I imagine I need some sort of counter to keep track of how many characters in the string correct?  Thanks

no, that's what the Len function is for

msgbox Len(szText)
ASKER CERTIFIED SOLUTION
Avatar of Thunder27
Thunder27

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cjesgo

ASKER

Thunder27 - Thanks! I guess I was closer than I thought.