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.

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.

 


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.