|
-
Nov 27th, 2000, 11:20 PM
#1
Thread Starter
Addicted Member
How can i speed up this Function?
Code:
Public Function InString(text As Variant, String1 As String) As Integer
Dim y As Integer
Dim x As Integer
Dim i As Integer
If String1 = "" Then
InString = 0
Exit Function
End If
For i = 1 To UBound(text)
DoEvents
x = InStr(1, text(i), String1)
If x <> 0 Then
y = y + 1
End If
Next i
InString = y
End Function
Edited to add code tags
[Edited by Bjwbell on 11-27-2000 at 11:23 PM]
-
Nov 27th, 2000, 11:59 PM
#2
transcendental analytic
Well what slows down the process for you there is doevents, you have to put it somewhere where it fires more seldom, like using a double loop:
Code:
Public Function InString(text As Variant, String1 As String) As Integer
Dim y%, i%, imax%
If Len(String1) Then Exit Function
For i = 1 To UBound(text)
imax = i + 5000
If imax > UBound(text) Then imax = UBound(text)
For i = i To imax
y = y - CBool(InStr(1, text(i), String1))
Next i
DoEvents
Next i
InString = y
End Function
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 28th, 2000, 12:02 AM
#3
transcendental analytic
On a second trought, if you are using vb6 you could also pass text as a string array instead of variant, i'm not sure if thats much speed gain, but it's probably faster to access it than a variant all the time
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 28th, 2000, 12:12 AM
#4
Thread Starter
Addicted Member
How do you pass the text as a string array?
[Edited by Bjwbell on 11-28-2000 at 12:27 AM]
-
Nov 28th, 2000, 12:25 AM
#5
Frenzied Member
I thought that would happen. Change i for j in the inner loop.
Harry.
"From one thing, know ten thousand things."
-
Nov 28th, 2000, 12:27 AM
#6
Frenzied Member
Just to clarify, use this code:
Code:
Public Function InString(text As Variant, String1 As String) As Integer
Dim y%, i%, imax%, j%
If Len(String1) Then Exit Function
For i = 1 To UBound(text)
imax = i + 5000
If imax > UBound(text) Then imax = UBound(text)
For j = i To imax
y = y - CBool(InStr(1, text(j), String1))
Next i
DoEvents
Next i
InString = y
End Function
Harry.
"From one thing, know ten thousand things."
-
Nov 28th, 2000, 12:28 AM
#7
Thread Starter
Addicted Member
I did just did thats why i edited my post just now
[Edited by Bjwbell on 11-28-2000 at 12:40 AM]
-
Nov 28th, 2000, 12:52 AM
#8
transcendental analytic
Hmm pretty stupid of me, well it worked in java though..
hehe "next j" there harry, you forgot that 
And heres how you declare the parameter a string array:
Code:
Public Function InString(text() as string, String1 As String) As Integer
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 28th, 2000, 01:06 AM
#9
Thread Starter
Addicted Member
Well here's what i came up with.
Public Function InString(text() As String, String1 As String) As Integer
Dim y%, x%, i%
If String1 = "" Then
InString = 0
Exit Function
End If
For i = 1 To UBound(text)
y = y - CBool(InStr(1, text(i), String1))
Next i
InString = y
End Function
[Edited by Bjwbell on 11-28-2000 at 01:18 AM]
-
Nov 28th, 2000, 01:31 AM
#10
Frenzied Member
Oh yeah *D'oh*
Harry.
"From one thing, know ten thousand things."
-
Nov 28th, 2000, 03:26 AM
#11
transcendental analytic
am i missing something here? well uh i don't know whats going on if you keep editing your posts
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|