Skip to main content
simply more productive

The Data Specialist

Thanks to our intuitive transformation designer, you can convert data effortlessly to a variety of formats without knowing how to program. It’s not only efficient, it’s also easy to use.
Flowheater Download

Generating Random Strings

  • Herbert Berkley
  • Topic Author
  • Offline
  • User
  • User
More
10 years 10 months ago #2281 by Herbert Berkley
Generating Random Strings was created by Herbert Berkley
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..

12345Workorder.txt
12346Workorder.txt

And so forth.

Thanks,

Herb

Please Log in to join the conversation.

More
10 years 10 months ago #2282 by FlowHeater-Team
Replied by FlowHeater-Team on topic Re:Generating Random Strings
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
Code:
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.
Attachments:

Please Log in to join the conversation.

Time to create page: 0.273 seconds

FlowHeater - The Data Specialist

Efficient data integration and transformation with FlowHeater – the perfect solution for a seamless transfer of your data.

Rechtliches

Support & Contact

Kontaktinformation

Telefon:0951 / 99339792 E-Mail:This email address is being protected from spambots. You need JavaScript enabled to view it.

Copyright © 2009-2024 by FlowHeater GmbH. All rights reserved.