Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
 
					
				
		
Hi Qliks!
I need to make a button that will select a single random value from a listbox. I am thinking that to make it easier the listbox could contain a linear range of numbers from 0 -> n.
I tried to write a macro like
Sub test
x=4
ActiveDocument.Fields("F1").Select x
End Sub
Now - I just need to figure out how to generate the variable x based on the total number of rows from the list box since the row number will grow in the model.
Your help is highly appreciated
Lars Madsen
 
					
				
		
Hi,
I am using 9.00.7440.8 SR3
Lars
 
					
				
		
hi lars,
probably check with your document properties security settings
thanks
 
					
				
		
hi lars,
i think you have your "current local security" set as " dont run at all " in the edit module for macros.
pls set it to as only safe mode.
i hope that it should work now.pls check the attached application
thanks
 
					
				
		
Based on the feedback I trust that Rob's solution does the trick!
Unfortunately it just doesn't work on my installation. I even tried another installation on QlikView with the same negative result. My security is set as proposed, but when I hid the button the selection is cleared completely from the listbox.
I can see though that the "back/forward" changes as if selections are in fact made with the macro - but no effect in the list box [:'(]
Thanks anyway
Lars
 
					
				
		
Hi
I did'nt get Rob's function to work first... But then I realized that the number returned from the Rnd() funktion contained a , and QV expected a . inorder to evaluate the function...
So I could be due to system settings...
I did a simple replace and got Rob's script to work...
BR
Hans
 
					
				
		
Hi there,
Does anyone have an idea how i can use this code and randomly select for example 100 random articles?
BR Daniel
 
					
				
		
 rwunderlich
		
			rwunderlich
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		You could wrap it in a While loop that runs until you get the count you want. Be careful 🙂
-Rob
Sub SelectRandom
 ActiveDocument.Fields("F1").Clear
 While ActiveDocument.Evaluate("getSelectedCount(F1)") < 100
 val = ActiveDocument.Evaluate("FieldValue('F1', ceil(" & Rnd() _
 & " * FieldValueCount('F1')))")
 ActiveDocument.Fields("F1").ToggleSelect val
 Wend
End Sub
 
					
				
		
 llauses243
		
			llauses243
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		Hi Lars,
This is my offer, no depending on version
Pls to see image attached
Good luck, Luis
Very thx Rob.
