473,609 Members | 1,880 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Replace function issues.

4 New Member
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 1335
Joseph Martell
198 Recognized Expert New Member
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
3126
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"; char search = '?'; char* replace = "***"; char* result = search_and_replace(source,search,replace);
2
2693
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 requesting a "Replace" parameter. If the user clicks OK, the report opens, but only displays #Error. When the user tries to close the report, he is next presented with the choice of halting the code in break mode or not. Regardless of his choice, the app...
9
4398
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 again! I must be doing something wrong but I don't really know how to change my approach to getting it working. For example, if I type this in the vba immediate window: ?replace("HELLO","ELLO","ello")
3
3774
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 Replace function in a couple of queries to reformat some data. The application works flawlessly on 8 of the workstations, but on the other 4 throws a "Unrecognized function Replace" error when the queries in question are encountered. I have...
3
5445
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 apostrophes of the form fields. I was trying to do something like this: string sqlInsertEmails = "insert into tblContent (content, subject) values ('" + Replace(txtBody.Text,"'","''") + "', '" + Replace(txtSubject.Text,"'","''") + "')";
4
3838
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, that the split method and the regex.replace method was better than the string.replace method and replace function. I did not believe that.
4
22989
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 them know they look like this: "{cf 5}" or "{cf 0}" or "{ul 1}" or "{ul 0}", etc. The commonality they have is that they are always 6 charters long and always begin and end with curly brackets. This all works great if the user is running the...
5
6700
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 function. The Problem was, that the REPLACE-function didn't behave the way we expected. Following Example demonstrates the behavior:
8
22116
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 managed environments, but i'm still learning C, does anyone have a quicky function handy? or point me in the right direction on how to acccomplish this? your help is greatly appreciated. Also a note, this is running on a embedded device, so i can't...
1
2826
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 replace function to replace some text in the results. Access' REPLACE function is only available if executed within the environment, as it's a VBA function, not a SQL function. So how can I implement this is the EASIEST possible way? I don't to...
0
8076
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8573
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8541
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7002
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5510
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4021
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2531
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1672
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1389
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.