Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

String Manipulation...

Posted on 2003-03-18
7
Medium Priority
?
207 Views
Last Modified: 2010-04-07
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.
0
Comment
Question by:cjesgo
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 8161162
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
0
 

Author Comment

by:cjesgo
ID: 8161218
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.
0
 
LVL 1

Expert Comment

by:GERTJAN
ID: 8161226
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
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:Thunder27
ID: 8161269
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
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 8161280
> 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)
0
 
LVL 1

Accepted Solution

by:
Thunder27 earned 375 total points
ID: 8161303
Sorry i was typing when you posted that...
To print it out one character at a time, try the following at the end of your code:

'-- Set the number of characters
nNumChars = len(szText)
   
'-- Print the partial string character by character
For i = nStartingFrom to nNumChars
   Print Mid$(szText, i, 1)
Next i
0
 

Author Comment

by:cjesgo
ID: 8161643
Thunder27 - Thanks! I guess I was closer than I thought.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question