Dynamic data import / export

simply more productive
Welcome, Guest
Username: Password: Remember me
Welcome to the FlowHeater support forum.

Questions about using FlowHeater are answered here.

TOPIC: Generating Random Strings

Generating Random Strings 3 years 5 months ago #2281

  • Herbert Berkley
  • Herbert Berkley's Avatar
  • Offline
  • New Member
  • Posts: 15
I need to be able to generate some series of numbers that must always be greater than the last ones created. They must always be unique and no one number must exist in more than one instance when being generated.

Ideally the output would be used to name the file.

Such as..


And so forth.


The administrator has disabled public write access.

Re:Generating Random Strings 3 years 5 months ago #2282

  • FlowHeater-Team
  • FlowHeater-Team's Avatar
  • Offline
  • Administrator
  • Posts: 233
Hi Herbert,

Sorry for my misunderstanding but for me isn’t clear why you need a random number?

I’ve made a short example for you. Here I used a text file (lastnumber.txt) where you can store a start number. Per each run the .NET Script Heater read this file, increment the number and generates a new unique filename based on this number. Last but not least the .NET Script Heater stores the last used number to the text file for the next run.

The result form this script is passed to the Set Parameter Heater to set the FlowHeater Parameter $FILENAME$. This parameter $FILENAME$ is used as a placeholder in the TextFile Adapter on the WRITE side for the file name.

Please have a look to the attached example.

C# script code to generate unique file names
string filename = null;

public object DoWork()
  if (filename == null)
    // Read last number from file lastnumber.txt, the file have to be exist!
    string number = File.ReadAllText("lastnumber.txt");

    // add 1 to lastnumber
    int i = Convert.ToInt32(number) + 1;
    number = i.ToString("0");

    // store the new number to lastnumber.txt
    File.WriteAllText("lastnumber.txt", number);

    // build new file name
    filename = number + "WorkOrder.csv";

  // return new file name
  return filename;

Attachment filename_sequence.zip not found

Best wishes
Robert Stark

Did this answer your question? We would be grateful if you provide a brief comment as feedback. It may also help others who may have encountered a similar problem.
The administrator has disabled public write access.
Moderators: FlowHeater-Team
Time to create page: 0.071 seconds