Re: replacing text in textfile
- From: "Jack" <Jack@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 14 Sep 2005 10:44:11 -0700
Thank you again Tim for they reply. Maybe I should start from stratch as to
what I am looking for.
I have a .txt file with 3 variables that are located throughout the file
(##replace1##,##replace2##,etc) These are FIXED points.
I am wanting to have the table I have with 4 fields (one for each replace#
and one for what the output filename should be)
I am wanting to have a command button on form that when clicked will go
through text file and replace ALL instances of ##replace1## with
[replace1.tbl_replace] and do the same thing for ##replace2## and ##replace3##
After its complete I want it saved as [saveitas_tbl_replace]
Two things are important 1) It needs to loop through ALL the records I
believe I would use a dcount and dlookup to do that. A new file would be
created for EACH record. 2) the text that is replaced does not include any
additional whitespace (ie i want ##replace1## apples -> i want [green] apples
OR I want [to buy more] apples.)
In meantime I will look at your suggestions. Again thanks for your help.
Jack
"Tim Ferguson" wrote:
> "=?Utf-8?B?SmFjaw==?=" <Jack@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
> news:4AD0FD76-0A1C-4978-92C5-DEE11000447A@xxxxxxxxxxxxx:
>
> > Please take a look at the code and give me a clue as
> > to what may be going on.
>
> See below: I'm not very impressed with the standard of coding going on
> here...
>
> > I am really trying to learn and am not asking
> > to have code rewritten.
>
> I guess it probably needs it...
>
>
> > Call ReplaceText(MyTextBox.Text, TextOld.Text, TextNew.Text)
>
> This is garbage and never, ever, could have worked. The text property is
> only available when a control has the focus, and three controls cannot
> have the focus at the same time. In addition, there is no check that the
> passed objects are text boxes (or listboxes, or combos..?)
>
> The .Value property would have worked here.
>
> > Public Function ReplaceText(CleanThis As String, _
> > OldText As String, _
> > NewText As String)
>
> It's not strictly illegal, but it's really shabby to declare a function
> without a return: this should be a Sub not a Function.
>
> > Do While InStr(1, CleanThis, OldText) <> 0
>
> Unfortunately, this is going to fall apart badly if the target text is a
> substring of the inserted text. Try
>
>
> ReplaceText(ExampleText, "open", "unopened")
>
> and wait for a very long time...
>
> > 'REBUILD THE STRING BEFORE NEXT LOOP
> > 'This adds a space before and after NewText
> > 'and trims out unneccessary spaces too!
> >
> > CleanThis = Trim(PartA) & " " & _
> > Trim(NewText) & " " & _
> > Trim(PartB)
>
> This is pretty wanton inserting and removing white space, which may or
> may not be appropriate depending on the user's needs...
>
> In my view, you probably need to start again, this time with a properly
> working algorithm. If I had to do it, I'd use a tool other than VBA; but
> I do recognise that I don't really understand what it is you are trying
> to do.
>
> Best wishes
>
>
> Tim F
>
>
.
- References:
- replacing text in textfile
- From: Jesper
- Re: replacing text in textfile
- From: Tim Ferguson
- Re: replacing text in textfile
- From: Tim Ferguson
- Re: replacing text in textfile
- From: Jack
- Re: replacing text in textfile
- From: Tim Ferguson
- replacing text in textfile
- Prev by Date: Re: Populate report list box
- Next by Date: Re: What is the opposite of SetFocus?
- Previous by thread: Re: replacing text in textfile
- Next by thread: Re: replacing text in textfile
- Index(es):
Loading