[snip]
> i am kind of new to this and dont understand how this works
> how would i use this to look for a letter in a string like for instance
> mystring = instr(thestring, " ") would find any spaces what character can i
> insert that will return the first letter that is found in the string?
There is no predefined function to do what you want.
Here's the VB6 way to do what you're asking:
private function GetCharPos(strSearch as string, bSearchMode as byte) as
integer
dim bFlag as boolean
dim Position as integer
dim LenStr as integer
bFlag=false
'if bSearchMode=1 : detect the first letter position
'if bSearchMode=2 : detect the first number position
'if bSearchMode=3 : detect the first other char. position
LenStr=len(strSearch)
Position=0
do while not bFlag and Position <= LenStr
Position=Position+1
select case mid$(strSearch,Position,1)
case 'a' to 'z','A' to 'Z':
if bSearchMode=1 then bflag=true
case '0' to '9':
if bSearchMode=2 then bflag=true
case else:
if bSearchMode=3 then bflag=true
end select
loop
'if Position is greater than the length of the string
'there are no chars. of the requested type, so return 0
if Position > LenStr then Position = 0
GetCharPos=Position
end Function
Geoff - 29 Feb 2004 19:14 GMT
> [snip]
>
[quoted text clipped - 17 lines]
> 'if bSearchMode=2 : detect the first number position
> 'if bSearchMode=3 : detect the first other char. position
<SNIP>
You could use the Like operator to add flexibility it
if it appeals
e.g
Option Explicit
Const strMyString = "Whats this VB6! - or 5 ? "
Private Sub Command1_Click()
Debug.Print "First Ucase Character Pos = "; GetFirstPos(strMyString,
"[A-Z]")
Debug.Print "First Lcase Character Pos = "; GetFirstPos(strMyString,
"[a-z]")
Debug.Print "First Character Pos = "; GetFirstPos(strMyString, "[A-Z
,a-z]")
Debug.Print "First Number Pos = "; GetFirstPos(strMyString, "#")
Debug.Print "First Exclamation = "; GetFirstPos(strMyString, "!")
Debug.Print "First Question Mark Pos = "; GetFirstPos(strMyString,
"[?]")
Debug.Print "First space Pos = "; GetFirstPos(strMyString, " ")
End Sub
Public Function GetFirstPos(strfSearch As String, strLikeSearch As String)
As Integer
Dim Position As Integer
Dim LenStr As Integer
LenStr = Len(strfSearch)
Position = 1
Do Until Position > LenStr
If Mid$(strfSearch, Position, 1) Like strLikeSearch Then Exit Do
Position = Position + 1
Loop
'if Position is greater than the length of the string
'there are no chars. of the requested type, so return 0
If Position > LenStr Then Position = 0
GetFirstPos = Position
End Function