473,396 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Replace function issues.

I am coding for a text editor with a find and replace function. I am getting errors in my code and need help fixing them.

Expand|Select|Wrap|Line Numbers
  1. Private Sub ReplaceButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReplaceButton.Click
  2.         Dim StartPos, Counter As Integer
  3.         Dim FindString, ReplaceText As String
  4.         .FindString = ""
  5.         .ReplaceText = ""
  6.  
  7.         For Counter = 1 To Len(TextRichTextBox.Text)
  8.             StartPos = InStr(FindTextBox.Text, FindString)
  9.             If StartPos > 0 Then
  10.                 FindTextBox.Text = StartPos - 1
  11.                 FindTextBox.Text.SelLength = Len(FindString)
  12.                 FindTextBox.Text.SelText = "" + ReplaceText
  13.             End If
  14.             Next()
Oct 3 '10 #1
1 1329
Joseph Martell
198 Expert 128KB
First, what kind of errors are you getting? Are you not able to compile, is an exception being thrown, are alligators climbing out of your computer and attacking your furniture?

Second, if this code is an exact copy of your code as you have typed it in your editor, then I am going to say that there are some syntax errors that you need to take care of:

Lines 4 & 5 start with the dot operator, but there is no containing with statement. You need to get rid of the . or have an object before the dot.

Line 14 has "Next()" as though it were a function call. So your For loop has no Next statement to end it.

You do not have an End Sub statement so this sub is not closed. That would cause a compilation error and likely several other syntax errors.

Line 11 & 12 are apparently trying to access properties of the string class called "SelLength" and "SelText", but MSDN makes no reference to these properties of the string class. These could be extensions, and if so everything is fine, I just didn't know about them

You appear to be trying to use the "+" operator to concatenate text (line 12), but in VB the "&" is the concatenation operator.

Lastly, and this is a VB .Net thing not a VB syntax thing, VB .Net is very object oriented. You are using some older functions that are hold-overs from VB6 and earlier like Len() (line 11) and Instr() (line 8). If this truly is a VB .Net app, as the location of the post suggests, consider using the Length property and either the Contains method or the IndexOf method of the string class. It is more in keeping with an object oriented language, offers greater type safety, and is more efficient.
Oct 3 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: pembed2003 | last post by:
Hi all, I asked this question in the C group but no one seems to be interested in answering it. :-( Basically, I wrote a search and replace function so I can do: char source = "abcd?1234?x";...
2
by: Sharon | last post by:
I've had an Access 2000 app running successfully for many months on both Windows XP and Windows 2000. Recently when my Windows 2000 users call a particular report, they get first a dialog...
9
by: Not Me | last post by:
Hi, I'm having bother with the replace function in access 2002, a while back I remember not being able to get it to work... then suddenly the next time I tried it did work. Now it doesn't...
3
by: Dave | last post by:
I have an Access 2K application that is distributed to about a dozen users (all with identical NT environments and identical Access versions, object libraries and service packs). I am using the VBA...
3
by: Andy Sutorius | last post by:
Hi, I read the thread (2/16/05) regarding a replace function in C# however it didn't answer my question. I have a string which is building an insert sql statement and I would like to replace...
4
by: Cor | last post by:
Hi Newsgroup, I have given an answer in this newsgroup about a "Replace". There came an answer on that I did not understand, so I have done some tests. I got the idea that someone said,...
4
by: Lauren Wilson | last post by:
Hi folks, We have a need to replace sub strings in certain message text. We use the Office Assistant to display help and often use the imbedded formatting commands. Those of you who have used...
5
by: enno | last post by:
Dear Community, We have a problem with null-Bytes in varchar-Columns, which are not handled correctly in our application. Therefor we try to filter them out using the Transact-SQL REPLACE...
8
by: Warren Moxley | last post by:
Hi there, i've been searching for a C String search and replace function. I need to find all occurrences of " " in a char* array, and replace them with another char, I know how to do this in...
1
by: seanmatthewwalsh | last post by:
Hi I have a website that uses an Access 2003 database. I have controls on my pages that are bound to SqlDataSources that pull data from this database. In a couple of them, I need to use the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.