- Posts: 15
Generating Random Strings
- Herbert Berkley
- Topic Author
- Offline
- User
Less
More
11 years 7 months ago #2281
by Herbert Berkley
Generating Random Strings - Post(2281) 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
Ideally the output would be used to name the file.
Such as..
12345Workorder.txt
12346Workorder.txt
And so forth.
Thanks,
Herb
Please Log in or Create an account to join the conversation.
- FlowHeater-Team
- Offline
- Admin
11 years 7 months ago #2282
by FlowHeater-Team
Best wishes
Robert Stark
Replied by FlowHeater-Team on topic Re:Generating Random Strings - Post(2282)
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
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
Attachments:
Please Log in or Create an account to join the conversation.
Time to create page: 0.252 seconds