?
Solved

Character Editing

Posted on 1998-08-29
7
Medium Priority
?
195 Views
Last Modified: 2013-12-03
Dear Experts,
    While writing a recent program of mine, I ran into a couple of problems that i side stepped in order to complete the project.  But now since I have the opportunity to go back, I am hoping to fix/solve those problems that i encountered.  Anyway, one of the main problems that I am having, is how to get my program to take a multi-line textbox and go through character by character to see if that character matches one that i specified earlier in the program.  If it does match, I would like it to replace the found character with a new character.
    An example of this would be, in the text box it said...
"Hi, how are you
today?"
I would like the program to recognize the comma and replace it with something like a hyphen.  I am using Visual Basic5.0 (sp3) under a windows95 platform.  Please help me out here.
-xtreasonx-
0
Comment
Question by:xTrEaSoNx
[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
  • 4
  • 3
7 Comments
 
LVL 4

Expert Comment

by:mcix
ID: 1431842
Would you like the program to replace as Text is typed in the TextBox or more like a Search and Replace at a later point?
0
 

Author Comment

by:xTrEaSoNx
ID: 1431843
mcix,
  I would like it to replace it at a later time.  Like when a menu item is clicked.
-xtreasonx-
0
 
LVL 4

Accepted Solution

by:
mcix earned 200 total points
ID: 1431844
Here is one of many approaches:

Public Sub ReplaceAChar(SourceTextBox As TextBox, ReplaceThis As String, WithThat As String)

    Dim mlngTextLength As Long
    Dim mlngCurrentPosition As Long
   
    mlngTextLength = Len(SourceTextBox)
   
    For mlngCurrentPosition = 1 To mlngTextLength
        If Mid$(SourceTextBox.Text, mlngCurrentPosition, 1) = ReplaceThis Then
            SourceTextBox.SelStart = mlngCurrentPosition - 1
            SourceTextBox.SelLength = 1
            SourceTextBox.SelText = WithThat
        End If
    Next
   
End Sub


To use it you would code:

ReplaceAChar Text2, ",", "-"

This would replace the letter commas with hyphens

If this doesn't do what you want, then give me more details and I will get you something that does...
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!

 

Author Comment

by:xTrEaSoNx
ID: 1431845
mcix,
    I'm not sure what i'm doing wrong, but that code you gave me does nothing.  I have a multi-line textbox and a menuitem on my form.  i tried that code first in the declarations section of the form first and put the calling code in the menu and it had no result.  Second, i tried putting the code in a module and calling it from there.  Still no result.  Last of all i tried putting the code directly into the menu and still, no result.  Is there something that I'm missing?

please help,
-xtreasonx-
0
 
LVL 4

Expert Comment

by:mcix
ID: 1431846
xtreasonx,

Sorry that you are having trouble...

The Public Sub should be in either the declarations of the form or in a separate BAS module.

The calling code should be in the Event you want to have the Search and Replace to occur.

Did you replace the Text2 with the name of your Textbox?

0
 

Author Comment

by:xTrEaSoNx
ID: 1431847
mcix,
   I got it working,  thanks,this was a big help.
-xtreasonx-
0
 
LVL 4

Expert Comment

by:mcix
ID: 1431848
No problem...

If you have any more problems/questions you can e-mail me @:
marko_justus@hotmail.com
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month8 days, 22 hours left to enroll

764 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