IsDate with textboxes

How would I put a date into for example textbox3.text from textbox1.text if textbox1.text contains other data aswell?
The below works, but only if the date is on its own and not with other letters and stuff.
Thanks if anyone can help.

[code]
Dim Birth As Long

For Birth = 1 To Len(Text1.Text)
If IsDate(Text1.Text) Then
Text3.Text = (Text1.Text)
End If
Next Birth
[code]
[420 byte] By [Iamjohn66] at [2007-11-19 2:00:40]
# 1 Re: IsDate with textboxes
Well first of all, you'll need to determine how the datas are formatted into your textbox to be able to extract the part you need. Secondly, your code is not correct, your using a loop (a for-next statement) that do always the same time, what are you trying to do exactly?

JeffB
JeffB at 2007-11-9 21:00:37 >
# 2 Re: IsDate with textboxes
I have textbox1.text with data like JOHN/ BORN IN 19/11/1982 DIED 12/05/2000 RIP.
But the dates could be written in many different ways.

Then wanted to move the smallest date to for example to textbox3.text.

But I thought IsDate could work with many different formats of dates.
Iamjohn66 at 2007-11-9 21:01:37 >
# 3 Re: IsDate with textboxes
IsDate() support different date format, but not when there is other text in it. Thinking of it, I think I understand your loop, your trying to search in the string to find a valid date inbetween, the problem is you don't know the length of the date in string. If it's always written the same way (BORN IN #DATE# DIED #DATE#), then you can use InStr() to search for "BORN IN" and "DIED" and then get your dates. In other case, it will be possible to loop the string and try to match a valid date like you wanted to do by using the Mid$() function and two loops.

JeffB
JeffB at 2007-11-9 21:02:36 >
# 4 Re: IsDate with textboxes
If you have something like
JOHN/ BORN IN 19/11/1982 DIED 12/05/2000
or
blsadbf;lasdf j;lk jasdf; j; ;lkj 10/24/04

You can tokenize the whole string (parse through each token separated by spaces: ie JOHN/, BORN, IN, 19/11/1982, etc and then check to see if it's in this format:

"##/##/####" or "##/##/##"

so some sample code would look like this (don't know if this will work as it is but it'll be close):
dim strTemp as string, strText1 as string, strText2 as string
dim intSpace as integer

strText1 = Text1.text
intSpace = InStr(1, strText1, " ")

do while intSpace <> 0

if intSpace <> 1 then
strTemp = Mid(1, strText1, intSpace -1)
if strTemp = "##/##/####" or strTemp = "##/##/##" then
strText2 = strText2 & " " & strTemp
endif
endif

'cut off the token we just checked
strText1 = Mid(strText1, intSpace+1)
intSpace = InStr(1, strText1, " ")
loop

Text2.text = strText2

(instead of the strTemp = "##/##/####" you might have to use:
if strTemp Like "##/##/####" i can't remember for sure)

good luck
prosh0t at 2007-11-9 21:03:46 >
# 5 Re: IsDate with textboxes
Prosh0t,

I am using the above code, but the If strTemp = "##/##/##" doesn't work?
When I changed the mask to the actual date 6/7/01 the IF statement worked ok.

It appears the IF test is reading the # symbols as text rather than symbolic formats?

Is there something I can try to fix this?
T2T2 at 2007-11-9 21:04:41 >