Forum Discussion

mesg2anil's avatar
mesg2anil
Regular Contributor
14 years ago

Usage of Randomize in Log Filename

Hi,



I need help on using Randomize in the log filename which is generated after script is executed... Below is the code which I'm using but it is not adding random number to the log filename after getting created...




'Write the log file to folder



Randomize


Random = (1000)


FileName = Project.ConfigPath + "Exported Log Reports\MyResults"+Random+".mht"


Log.SaveResultsAs FileName, 2



Please suggest solution...

  • Hi,


    You can use the following script:



    function SaveResults()

    {

      var ran_number = randInt(0,1000)

      var FileName = Project.ConfigPath + "Log\\MyResults"+ ran_number + ".mht";

      Log.SaveResultsAs(FileName, 2);

    }



    function randInt(min, max) 

    {

      return Math.round(Math.random()*(max-min)+min)

    }

  • mesg2anil's avatar
    mesg2anil
    Regular Contributor
    Hi Margaret,



    Thank you for replying.

    A request... can you please give me code in VB script?
  • Hi Anil,


    Here is the code in VBScript:




    Sub SaveResults()

      Dim ran_number, FileName

      Randomize()

      ran_number= Round (rnd()* 1000)

      FileName = Project.ConfigPath & "Log\\MyResults" & ran_number & ".mht"

      Call Log.SaveResultsAs(FileName, 2)

    End Sub