Home > Archive > Visual Basic > April 2006 > odd Type Mismatch error with Mid$
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
odd Type Mismatch error with Mid$
|
|
| Matt Williamson 2006-04-27, 6:56 pm |
| When I run the following routine, I'm getting a type mismatch error 13 and I
can't figure out why. sFullName is dim'd as a string at the beginning of the
routine. I am using it in another routine, but I tried setting it = "" just
before the error line but that didn't change anything. I also tried using
sFullName = cstr(Trim(Mid$(2, sTmp))) but get the same results. At the point
of the error the value of sTmp = "|John|J.|Anderson Jr " (no quotes)
If I replace the Mid$ line with the error with
sFullName = Trim(Right$(sTmp, Len(sTmp) - 1))
which accomplishes the same goal of removing the first Pipe, it works.
what is the major difference?
'Code
If bSuffix Then
For x = 0 To UBound(sSplit)
If x = UBound(sSplit) Then
sTmp = sTmp & " " & sSplit(x)
sFullName = sTmp
Exit For
Else
sTmp = sTmp & "|" & sSplit(x)
End If
Next
sFullName = Trim(Mid$(2, sTmp)) ' <---- Type Mismatch??
Else
For x = 0 To UBound(sSplit)
sTmp = sTmp & "|" & sSplit(x)
Next
sFullName = Trim(Mid$(2, sTmp))
End If
'End Code
TIA
Matt
| |
| Ken Halter 2006-04-27, 6:56 pm |
| "Matt Williamson" <ih8spam@spamsux.org> wrote in message
news:OME$Q5iaGHA.2356@TK2MSFTNGP04.phx.gbl...
> what is the major difference?
> sFullName = Trim(Mid$(2, sTmp)) ' <---- Type Mismatch??
The first argument you need to use with Mid$ is the string <g> It should
show in intellisense.
if 'sTmp' holds the entire string and you want to chop off the first 2
characters, you'd need something like...
sFullName = Trim$(Mid$(sTmp, 2))
--
Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
| |
| Ken Halter 2006-04-27, 6:56 pm |
| "Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message
news:%23tTwq$iaGHA.4788@TK2MSFTNGP02.phx.gbl...
>
> if 'sTmp' holds the entire string and you want to chop off the first 2
> characters, you'd need something like...
>
err... umm... I mean 'Chop the first character off' (darned 0/1 getting to
me again <g> )
--
Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
| |
| Matt Williamson 2006-04-28, 7:56 am |
| Doh! Now I see what happened. I was working with Instr() quite a bit and it
takes the starting char as the first argument. Later on in the code I used
Mid$ properly. Go figure.
"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message
news:%23tTwq$iaGHA.4788@TK2MSFTNGP02.phx.gbl...
> "Matt Williamson" <ih8spam@spamsux.org> wrote in message
> news:OME$Q5iaGHA.2356@TK2MSFTNGP04.phx.gbl...
>
> The first argument you need to use with Mid$ is the string <g> It should
> show in intellisense.
>
> if 'sTmp' holds the entire string and you want to chop off the first 2
> characters, you'd need something like...
>
> sFullName = Trim$(Mid$(sTmp, 2))
>
> --
> Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
> DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
>
|
|
|
|
|