Link to home
Start Free TrialLog in
Avatar of hess
hess

asked on

Fix it please

I have my progect in a zip file at <A HREF="www.shasta.cc.ca.us/cfdocs/test/myvb.zip"> www.shasta.cc.ca.us/cfdocs/test/myvb.zip</A>. Every time i run it it hangs when it tries to run the szreplace function. I f anyone could make this run again i'll shell ou all of my points (currently 135). It was done in VB4.
 
ASKER CERTIFIED SOLUTION
Avatar of brunchey
brunchey

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hess
Do you have the Microsoft DAO Object library loaded?  If not, try that.

Regards,
Sekans
brunchey,
I don't think that is the problem.  Every time a match is found, it is replaced with something else.  So even if it starts at the beginning again, it won't find the same occurrance, because it won't be there anymore.

assume temp = "test text"
search for "t" and replace with "X"

first pass starts at first character finds "t" at position 1 changes to X"
now temp = "Xest text"
second pass starts at first character finds "t" at position 4
now temp = "XesX test"

Regards,
Sekans

brunchey,
Please accept my apology.  I failed to check the values of sfind and sreplace.  You are absolutely correct.  Your answer should solve the problem.  Good work.

Regards,
Sekans
hess,
You do need to initialize the variable ll_begin.

Dim ll_begin as Integer
ll_begin = 0

put this before the Do...Loop

Sekans
Avatar of hess
hess

ASKER

Why are there to loop statements at the end of the answer is one not suposed to be there
Avatar of hess

ASKER

I'll test it now and if it works i'll give you the 135 points
Avatar of hess

ASKER

could you please rewrite the answer so that the whole szReplace function is included, From "Public Function" to "End Functioin" I've been working with vb for only a couple of days and i would like to be able to just paste it in.
Avatar of hess

ASKER

Never Mind. It works great and thanks for the help sekans and Brunchey. But why did you say to set II_Begin to 0 instead of 1 sekans
That was a mistake, 1 is correct.
Function szReplace(szText As String, szFind As String, szRepl As String) As String
'-- This function replaces all occurances of szFind with szRepl within
          '   szText and returns the resulting string.

              Dim nThere As Long
              Dim szTemp As String
              Dim ll_begin
              '-- Copy the incoming text so that szText is not altered.
              szTemp = szText
              ll_begin = 1
              '-- Go into a loop
              Do
                  '-- Is szFind part of szTemp?
                  nThere = InStr(ll_begin, szTemp, szFind)
                  If nThere Then
                      '-- Yes. nThere is now the position of szFind within szTemp
                     
                      '        [---------- A ----------]   [-B -]   [------------- C ----------------]
                      szTemp = Left$(szTemp, nThere - 1) & szRepl & Mid$(szTemp, nThere + Len(szFind))
                      ll_begin = nThere + Len(szRepl)
                  Else
                      '-- No. There is nothing more to do, so exit the loop
                      Exit Do
                  End If
              Loop

              '-- Assign szReplace to the szTemp string, which contains the
              '   modified original text.
              szReplace = szTemp
End Function