Results 1 to 2 of 2

Thread: Using the InStr Function

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Location
    Leeds, UK
    Posts
    287

    Post

    Hi,

    I am having a little trouble using the InStr function. I don’t have a clue how to use it? I was making a program that found the “ – “ in the title bar and added some text to the right of it. How would I do this? I tried this statement:

    Dim intFound As Integer
    intFound = InStr(form1.Caption, “ – “)
    Form1.caption = Left$(Form1.Caption, intFound) & Text1.Text

    For some reason this is not working. Could you please tell me the correct statement and explain is it is not too much bother.

    Thanks

  2. #2
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523

    Post

    This seems to work for me:
    Code:
    Private Sub Command1_Click()
        Dim intFound As Integer
        intFound = InStr(Form1.Caption, "–")
        Form1.Caption = Form1.Caption & Left$(Form1.Caption, intFound) & Text1.Text
    End Sub
    Your code doesn't work because when You use Left function it automatically erases everything in a caption and then just adds whatever Left came up with.

    Note: It will only work if there is no more than one (1) '-' in Form1.Caption


    ------------------
    Visual Basic Programmer (at least I want to be one)
    ------------------
    PolComSoft
    You will hear a lot about it.

    [This message has been edited by QWERTY (edited 11-14-1999).]

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