?
Solved

String Manipulation...

Posted on 2003-03-18
7
Medium Priority
?
203 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

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!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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

762 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