Results 1 to 11 of 11

Thread: And or & or....?[Resolved]

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Posts
    566

    Question And or & or....?[Resolved]

    Code:
    If InStr(1, sBuffer, ip.Text And hd.Text, vbTextCompare) <> 0 Then
    MsgBox "blahblah"
    End If
    the bold is what i suspect is wrong and what's stopping it from workin. so, what this is doing is searching a file for 2 things, which is an IP and Harddrive Serial. IP is in ip.Text and Harddrive Serial is in hd.Text, but when it searches for both it doesn't work and im thinking this is why "ip.Text And hd.Text" is wrong i suspect. so, instead of using "And" what should i use?
    Last edited by emyztik; Sep 13th, 2004 at 04:51 PM.

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,174
    Try "Or"

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    Boolean logic on strings????

    If the IP and Hardrive serial numbers are consecutive within the file use

    If InStr(1, sBuffer, ip.Text & hd.Text, vbTextCompare) <> 0 Then


    otherwise you will need to use two Instr statements.

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,174
    I think I skipped the contents of the post...

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Posts
    566
    If the IP and Hardrive serial numbers are consecutive within the file use

    If InStr(1, sBuffer, ip.Text & hd.Text, vbTextCompare) <> 0 Then
    i tried that also but it gives a "Type mismatch" error.

  6. #6
    Addicted Member vigge89's Avatar
    Join Date
    May 2002
    Location
    Sweden
    Posts
    172
    are you sure that you can check if 2 strings are inside with just 1 function call?


  7. #7
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,047
    Originally posted by emyztik
    i tried that also but it gives a "Type mismatch" error.
    Then one of your arguments probably isnt a String Type ... this test works fine:
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim s1 As String, s2 As String
    3. Dim s3 As String
    4. s3 = "12345"
    5. s1 = "3"
    6. s2 = "4"
    7. If InStr(1, s3, s1 & s2, vbTextCompare) Then
    8.     MsgBox "Hi"
    9. End If
    10.  
    11. End Sub

  8. #8
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: And or & or....?

    Originally posted by emyztik
    Code:
    If InStr(1, sBuffer, ip.Text And hd.Text, vbTextCompare) <> 0 Then
    MsgBox "blahblah"
    End If
    the bold is what i suspect is wrong and what's stopping it from workin. so, what this is doing is searching a file for 2 things, which is an IP and Harddrive Serial. IP is in ip.Text and Harddrive Serial is in hd.Text, but when it searches for both it doesn't work and im thinking this is why "ip.Text And hd.Text" is wrong i suspect. so, instead of using "And" what should i use?
    Only use & to concatenate Strings

  9. #9
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    35,235
    What you are trying to do can't be done. You are passing arguments to a function, and counting on the function to handle two different arguments where one is expected. This won't work, but it just might do something you really don't want.

    I would have to test it, and I don't think it is true, but what you are doing may do a bitwise AND between the bytes of the two strings (that's what would happen if they were numerical arguments, but strings probably won't do anything). If that were to happen, you would be searching for something virtually random.

    To do what you are trying to do, you will have to have two InStr calls, one for each target, and compare the results.

  10. #10
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961
    Oh, I see what you're trying to do. No you must break that into 2 calls:

    VB Code:
    1. If InStr(1, sBuffer, ip.Text) <> 0 And InStr(1, sBuffer, hd.Text) <> 0 Then
    2. MsgBox "blahblah"
    3. End If

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Posts
    566
    everything works thanks guys!!

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