|
-
Jul 2nd, 2002, 07:46 AM
#1
Thread Starter
Hyperactive Member
instr() error question *resolved*
The line
VB Code:
textlocation = InStr(start, text, test, vbTextCompare)
produces an error, but I can't figure out why... This is part of a larger sub, but I don't want to bore you guys with that
Does anyone know why this is giving an error ??
VB Code:
'declarations'
Dim dbase As Database
Dim recset As Recordset
Dim length As Integer
Dim str As String
Dim htmltag As String
Dim str2 As String
Dim result As String
Dim textlocation As Long
Dim start As Integer
Dim endlocation As Long
Set dbase = OpenDatabase(dblocation)
start = 0
Do
'look for the space and replace with   tag'
test = Chr(32)
textlocation = InStr(start, text, test, vbTextCompare)
start = textlocation
'exit the do in case of nothing found. The 0 value would cause errors in the subsequent lines'
If textlocation = 0 Then
Exit Do
End If
'read the part before the space, the -1 ensures the space itself is not read'
str = Mid(text, 1, (textlocation - 1))
'read the part after the space, the +1 ensures the space itself is not read'
str2 = Mid(text, (textlocation + 1))
'insert the space tag in between'
text = str & "   " & str2
Loop Until textlocation = 0
Last edited by The Dutch Dude; Jul 2nd, 2002 at 09:25 AM.
Obey the dragon thing. Or not. Or possibly just a bit.
-
Jul 2nd, 2002, 07:53 AM
#2
Banned
I think because start = 0.
I don't think you can start at position 0. It has to be position 1.
Denk ik.
-
Jul 2nd, 2002, 07:54 AM
#3
Member
If you are [start]ing at 0, you don't need to put anything in that argument so try:
textlocation = InStr(text, test, vbTextCompare)
-
Jul 2nd, 2002, 07:58 AM
#4
Thread Starter
Hyperactive Member
damn! that fixed it..
and the stupid thing is that in the mid() statements I DID use 1 as a start! Thanx allot!!
Obey the dragon thing. Or not. Or possibly just a bit.
-
Jul 2nd, 2002, 08:03 AM
#5
Thread Starter
Hyperactive Member
If you specify the compare you must also specify the start (or so my MSDN library says...
And specifying it makes it easier to read, but that could just be me..
Obey the dragon thing. Or not. Or possibly just a bit.
-
Jul 2nd, 2002, 08:12 AM
#6
Frenzied Member
Just a thought - why aren't you using the Replace function - it seems that you are finding spaces, and replacing them with something.
In that case you can do
Replace(ThisText," ","XX")
which would replace all the spaces in This Text with XX
'Buzby'
Visual Basic Developer
"I'm moving to Theory. Everything works there."
-
Jul 2nd, 2002, 08:19 AM
#7
Thread Starter
Hyperactive Member
because I kind of didn't know it exsisted...
Sounds like a very handy thing.
This replaces even more lines of code. Finding out instr() exsisted already trimmed the line count considerably
That's what I love about programming: finding out that something exsists that makes you look like a complete gimp, but it is alse something you can't live without the moment you hear about it..
Obey the dragon thing. Or not. Or possibly just a bit.
-
Jul 2nd, 2002, 08:28 AM
#8
Thread Starter
Hyperactive Member
because I kind of didn't know it exsisted...
Sounds like a very handy thing.
This replaces even more lines of code. Finding out instr() exsisted already trimmed the line count considerably
That's what I love about programming: finding out that something exsists that makes you look like a complete gimp, but it is alse something you can't live without the moment you hear about it..
Obey the dragon thing. Or not. Or possibly just a bit.
-
Jul 2nd, 2002, 08:36 AM
#9
Lively Member
Re: instr() error question
You start your search from the first character, i.e
start=1
Your attitude determines your altitude!!!
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
|