Micro Focus QTP (UFT) Forums
Need help on this function - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Need help on this function (/Thread-Need-help-on-this-function)



Need help on this function - faqtest2009 - 10-29-2009

I have been using following function to find a value between two words. It returns correct value when I have no duplicate words but in the opposite case this function returns me incorrect value.
Code:
Function ParseScreenVal(varString,varCurr,varNext)
i = varString
i = CStr(i)
varCount = instr( 1,i,varCurr,vbTextCompare)
varCount2 = instr( 1,i,varNext,vbTextCompare)
ParseScreenVal = Mid(i, varCount + len(varCurr),varCount2-varCount - len(varCurr))

End Function


Please see the attachment for more details. Any help would be really appreciated

Thanks in advance


RE: Need help on this function - venkatbatchu - 10-29-2009

Hi,
Really i have spent more than 2 hours and finally i have get the conclusion
use this function

Code:
Function fbtwds(p,p1,p2)
l=len(p)
l1=len(p1)
l2=len(p2)
if1=instr(1,p,p1)
m=right(p,l-(if1+l1-1))
m=trim(m)
ml=len(m)
if2=instr(1,m,p2)
m=left(m,if2-1)
msgbox m
End Function
call fbtwds("abdul kalam is scinetist and former president","kala","and")
incase if u have duplicates in a variable "p" then proceed the same operation until u get the correct one....

Please let me know if i am going in wrong direction..


RE: Need help on this function - faqtest2009 - 10-29-2009

Hi Venkat,
Thanks for your time on this. I tried your function but still returns me an incorrect value. Please see the attachment with updated info on this issue. Please let me know if you have any other ideas to get the correct value.
Once again thanks for your help.


RE: Need help on this function - Saket - 10-30-2009

hi faqtest2009,
I have modified your code, check out if this works
Code:
Function ParseScreenVal(varString,varCurr,varNext)
i = varString
i = CStr(i)
varCount = instr( 1,i,varCurr,vbTextCompare)
varCount2 = instr( 1,i,varNext,vbTextCompare)
'ParseScreenVal = Mid(i, varCount + len(varCurr),varCount2-varCount - len(varCurr))
sResult = Mid(i, varCount + len(varCurr),varCount2-varCount - len(varCurr))
Do
    varCount = instr( 1,sResult,varCurr,vbTextCompare)
    If varCount > 0Then
        sResult  = Mid(sResult, varCount + len(varCurr),len(sResult))
    End If
Loop while  varCount > 0
ParseScreenVal = sResult
End Function
I have verified with the data in your attachment.
let me know if you find any issue with other data.

@Everyone - Please use proper tags to wrap your code and make your post readable.


RE: Need help on this function - faqtest2009 - 10-30-2009

Thank you very much, it works for me with the given text.