SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 4 of 4
  1. #1
    Senior Member
    Join Date
    Aug 2005
    Posts
    151
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Instr function always returns 0

    Hi,
    I need to search whether string2 appears in string2. The string2 contains value from datatable,String1 contains a value from webtable dispalyed dynamically in the webpage. I used the following method
    Name1=Browser(x).Page(y).Webtable("sss").GetCellDa ta(1,1)

    Name2=Trim(DataTable(Name2)

    msgbox Name2&vbcrld&Name1
    mypos=Instr(Name1,Name2)
    Both the variables has the values expected. but when I use the function it always returns 0. Can someone tell me any suggestions on this?.
    Thanx

  2. #2
    Moderator
    Join Date
    Oct 2005
    Location
    UK
    Posts
    407
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Instr function always returns 0

    InStr - Returns the position of the first occurrence of one string within another.

    I would suggest initially you look at the help to see when 0 is a return value (3 possibilities). I this case you may be better using a regular expression for the comparison.
    Ron
    *******
    If you had to identify, in one word, the reason
    why the human race has not achieved, and never
    will achieve, its full potential that word would be "meetings".

  3. #3
    SQA Knight
    Join Date
    Jan 2002
    Location
    Highlands Ranch, CO, USA
    Posts
    2,860
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Instr function always returns 0

    Jim
    -------------------------------------------
    For all the general stuff to know about QA/Test go here http://www.softwareqatest.com/

  4. #4
    Senior Member
    Join Date
    Jan 2000
    Location
    USA, CA
    Posts
    1,998
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Instr function always returns 0

    </font><blockquote><font size="1" face="Verdana, Arial, Helvetica">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">'' Retrieve Substring from the middle of given String. &lt;BR&gt;
    ' @param sString [String] String source to get Substring from
    ' @param sSubstringBefore [String] Unique known Substring before Target Substring
    ' @param sSubstringAfter [String] Unique known Substring after Target Substring
    ' @return [String] Substring between given Substrings from String &lt;BR&gt;
    ' or zero length String if Substrings parameters are not found in the SourceString
    ' @remarks s = &quot;asdf#asdfJannawerwer6666Julia*asdfasdfwerwer &quot; &lt;BR&gt;
    ' SimpleParsing = GetSubstringInBetween(s, &quot;Janna&quot;, &quot;Julia&quot &lt;BR&gt;
    ' DoubleParsing = GetSubstringInBetween(GetSubstringInBetween(s, &quot;#&quot;, &quot;*&quot, &quot;Janna&quot;, &quot;Julia&quot
    ' @require Use unique known Substring to make parsing, &lt;BR&gt;
    ' If not - first avalable match will be taken and might make a big mess in the next logic
    Function GetSubstringInBetween(sString, sSubstringBefore, sSubstringAfter)
    GetSubstringInBetween = &quot;&quot;
    iPositionBeforeTarget = InStr(sString, sSubstringBefore)
    If iPositionBeforeTarget &lt; 1 Then
    Exit Function
    Else
    iPositionBeforeTarget = iPositionBeforeTarget + Len(sSubstringBefore)
    End If

    iPositionAfterTarget = InStr(sString, sSubstringAfter)
    If iPositionAfterTarget &lt; 1 Then
    Exit Function
    End If

    iCutFromRight = iPositionAfterTarget - iPositionBeforeTarget
    sFoundTarget = Trim(Mid(sString, iPositionBeforeTarget, iCutFromRight))

    If NOT Len(sFoundTarget) = 0 Then
    GetSubstringInBetween = sFoundTarget
    End If
    End Function 'GetSubstringInBetween</pre><hr /></blockquote><font size="2" face="Verdana, Arial, Helvetica">You can modefy it a little bit to return true\false if you prefer. I wrote it to get value.

    Janna

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 10.71%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 10:06 AM.

Copyright BetaSoft Inc.