Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Write Table now available in Qlik Cloud Analytics: Read Blog
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Vb script to check if a Field contains a specific value

Hi Guys,

How do I use Vb script to check if a Field contains a specific value?

The statement below is not working..

x = ActiveDocument.Fields("HolidayDate").SearchFor("05/10/2010",true,1)

Thanks?

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Aldo,
Probably not the best way, but it works. You can start from here and agjust for your needs:


sub test
set f = ActiveDocument.Fields("HolidayDate").GetPossibleValues
c = f.Count
ctr=0
for i=0 to c-1
if f.item(i).text="05/10/2010" then
ctr=ctr+1
end if
next
' if ctr >0, the value exists
msgbox(ctr)
end sub


View solution in original post

7 Replies
syed_muzammil
Partner - Creator II
Partner - Creator II

Hi,

SearchFor returns an array of elements which contain the string you provided. Check the lenght of the returned String or array. If it is 0 then it means your date is not found. I don't have much experience in Macro's this is jus a suggestion. Also please check whether the date format you provided is correct ?

Regards,

Syed.

Not applicable
Author

Hi there,

Even searching for "05" or "*05*" is returning {...} and I Know I have the value 05/10/2010 in my listbox..

Is there any other way to check if the value 05/10/2010 is in the list box?

Anonymous
Not applicable
Author

Aldo,
Probably not the best way, but it works. You can start from here and agjust for your needs:


sub test
set f = ActiveDocument.Fields("HolidayDate").GetPossibleValues
c = f.Count
ctr=0
for i=0 to c-1
if f.item(i).text="05/10/2010" then
ctr=ctr+1
end if
next
' if ctr >0, the value exists
msgbox(ctr)
end sub


Not applicable
Author

Thanks man.

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

I find it easiest to use QV expressions with ActiveDocument.Evaluate. Then you just have to write the same QV expression you would use in a text box. Makes it easy to test.

Searching all values:
=FieldIndex('HolidayDate', '05/10/2010')

Searching possible values:
=sum(if(Date='05/05/2010',1,0))

Any of those expressions can be used in vb using the Evaluate() function.
x = ActiveDocument.Evaluate(" sum(if(Date='05/05/2010',1,0)) ")

-Rob

Not applicable
Author

Thanks.

Anonymous
Not applicable
Author

I knew there was a simpler way... Yes