Page 1 of 1 1
Topic Options
#119505 - 2004-05-13 02:33 PM first shot at useing UDF
burnsc Offline
Starting to like KiXtart

Registered: 2004-04-14
Posts: 171
I am giveing my first shot at useing UDFs, and am haveing a problem. I am trying to replace all occurances of ( in a sendkeys with {(}. This script is not working though. Can someone give me some pointers as to where my problem is?

I tried it with the UDF below my code first. It did not work that way. Next I tried it as shown. It did nto work this way either. After that I was stumped

Code:
  
Function Replace($SourceString, $SearchString, $ReplaceString, Optional $First, Optional $CaseSensitive)
Dim $String1
Dim $String2
Dim $Finished $Finished = 0
$Counter = 0
$String1 = $SourceString
If $CaseSensitive
$PreviousState = SetOption("CaseSensitivity", "On")
EndIf
While Not $Finished
$String2 = $String1
$Location = InStr($String1, $SearchString)
If $Location > 0
$String1 = Substr($String1, 1, $Location - 1) + $ReplaceString + Substr($String1, $Location + Len($SearchString), Len($SourceString) - $Location + Len($SearchString) + 1)
Else
$Finished = 1
EndIf
If $First
$Finished = 1
EndIf
If $String1 = $String2
$Finished = 1
EndIf
Loop
$Replace = $String1
$Nul = SetOption("CaseSensitivity", $PreviousState)
EndFunction

Sleep(2)
$string = "test()this()"
$string = Replace($string,"(","{(}")
$string = Replace($string,")","{)}")
SendKeys($String)


Top
#119506 - 2004-05-13 03:12 PM Re: first shot at useing UDF
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, removing the sendkeys line and showing the context of the string:
? $string

what it gives?
_________________________
!

download KiXnet

Top
#119507 - 2004-05-13 03:15 PM Re: first shot at useing UDF
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
oh, and if you want an efficient replace udf, try this:

Function replace($string,$replacewhat,$replacewith)
$replace=join(split($string,$replacewhat),$replacewith)
endfunction
_________________________
!

download KiXnet

Top
#119508 - 2004-05-13 03:51 PM Re: first shot at useing UDF
burnsc Offline
Starting to like KiXtart

Registered: 2004-04-14
Posts: 171
MAJOR THANKS. This worked GREAT. It was more efficient and it bypassed what was killing me(My replace string contained the search string ). I think I was getting an infinate loop due to my problem.
This script will be processing on a 4000 line master text file

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Henriques) and 2516 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.12 seconds in which 0.083 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org