Generate random numbers in InfoPath

Learn which options are available if you want to generate random numbers in an InfoPath form either with or without writing code.

ADVERTISEMENTS

InfoPath does not have a function you can use to generate random numbers.

So if you want to generate random numbers in InfoPath, you must either write code or find another way to generate random numbers without having to write code.

With code

If you are writing C# code for InfoPath, you can use the Random class and if you are writing VB code for InfoPath, you can use the Rnd function in VB to generate random numbers through code.

Without code

If you cannot or do not want to write code, you can make use of Excel and Excel Services in SharePoint to generate random numbers in InfoPath.

In such a solution, you would first have to create an Excel workbook and publish it to SharePoint. Then once you have done this, you can set up web service calls from within InfoPath to call Excel Services web service operations to retrieve a random number from the Excel workbook that is stored in SharePoint.

The following InfoPath 2010 video demonstrates how such a solution would work.

A second way to generate random numbers without having to write code is to make use of a basic formula that can generate a random number. The video shown below demonstrates how this formula would work.

 


Related Posts

 

Copyright: This article may not be used on web sites (whether personal or otherwise), copied, disseminated, altered, printed, published, broadcasted, or reproduced in any way without an expressed written consent. The techniques demonstrated in this article may be used within any Microsoft InfoPath project. This article is provided without any warranties. Copyright for this article is non-transferrable and remains with the author.

InfoPath 2013 Cookbook: 121 Codeless Recipes for Beginners

InfoPath 2013 Cookbook 2: 121 Codeless Recipes for SharePoint 2013

InfoPath 2010 Cookbook: 101 Codeless Recipes for Beginners

InfoPath 2010 Cookbook 2: 101 Codeless Recipes for SharePoint 2010

InfoPath 2010 Cookbook 3: 101 Code Recipes for C# Developers

InfoPath 2010 Cookbook 4: 101 Code Recipes for VB Developers

InfoPath 2010 Cookbook 5: Integrating InfoPath with Excel and Excel Services