If I wanted to extract all of the characters in a text box prior to the first space what would be the coding?
Printable View
If I wanted to extract all of the characters in a text box prior to the first space what would be the coding?
0 to 32 are not characters.
Set TextBox's multiline property to True.
If you intend to state from 0 to 32, you will recieve either spaces or squares.Code:For i = 33 to 255
Text1.text = Text1.text & Chr(i) & vbCrLf
Next i
I am not following. What I am doing is trying to extract some numbers from a text box. The way I have it setup right now is that in this text box on the get focus method it grabs the date created attribute from a file on the network. I would like to trim the time off at the end (because in the created attribute it will show something like this: 11/8/2000 1:03:06 PM). I want to just get 11/8/2000..
put a text box and a command button on a form and run this code:
Type something into the textbox (with a space...) and click the button. It will only display the text from the textbox to the left of the space in a message box.Code:Option Explicit
Private Sub Command1_Click()
MsgBox GetLeftOfSpace(Text1)
End Sub
Private Function GetLeftOfSpace(asText As String) As String
GetLeftOfSpace = Left$(asText, InStr(1, asText, " ") - 1)
End Function
[Edited by seaweed on 11-09-2000 at 08:11 PM]
Why didn't you say so? :rolleyes:
I didn't understand you the first time.
Now we're getting somewhere.
11/8/2000 1:03:06 PM
11/8/2000
Use the Left function.
Left(Text1.text, 9) 'returns 11/8/2000
Or you can use the Mid function.
Mid(Text1.text, 1, 9) 'returns 11/8/2000
It works great one more question.
Why would some computers read the date as 11/9/2000 and others as 11/9/00? These are all Windows machines.
Just format the output like this:
That will format whatever is in your text box to display just the month, day, and year. The time should be hidden.Code:Text1 = Format(Text1, "mm/dd/yyyy")
I think this will work for you.
Thanks! It worked great!
Depends on the machines date settings. Again, the format function can change the way it's displayed.
[Edited by seaweed on 11-09-2000 at 08:23 PM]Code:Format(Now, "mm/dd/yy") ' displays: 11/09/00
Format(Now, "mm/dd/yyyy") ' displays: 11/09/2000
Format(Now, "dddd, mmmm dd, yyyy") ' displays: Thursday, November 09, 2000