Results 1 to 9 of 9

Thread: Function

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    If I wanted to extract all of the characters in a text box prior to the first space what would be the coding?

  2. #2
    Guest
    0 to 32 are not characters.

    Set TextBox's multiline property to True.

    Code:
    For i = 33 to 255
         Text1.text = Text1.text & Chr(i) & vbCrLf
    Next i
    If you intend to state from 0 to 32, you will recieve either spaces or squares.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    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..

  4. #4
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357
    put a text box and a command button on a form and run this code:
    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
    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.

    [Edited by seaweed on 11-09-2000 at 08:11 PM]
    ~seaweed

  5. #5
    Guest
    Why didn't you say so?
    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

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    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.

  7. #7
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357

    Lightbulb Another solution

    Just format the output like this:
    Code:
    Text1 = Format(Text1, "mm/dd/yyyy")
    That will format whatever is in your text box to display just the month, day, and year. The time should be hidden.

    I think this will work for you.
    ~seaweed

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    954
    Thanks! It worked great!

  9. #9
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357
    Depends on the machines date settings. Again, the format function can change the way it's displayed.
    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
    [Edited by seaweed on 11-09-2000 at 08:23 PM]
    ~seaweed

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width