Question

How do I generate a string of 8 characters using lotusscript in this pattern? Eg: 0E 1F A3 ZK (there are spaces after every 2 characters including the last). Each character can only be either 0-9 or A-Z (uppercased only). I've used the Randomize and Rnd method before and thinking of applying it here but I'm not sure if that's the correct way and how to achieve that. Another thing is this string is going to be saved into my document and I have a view that list each of the generated string. Which means each time a string is generated, it has to be unique. If the string generated is already used in another document, then continue generating until one that hasn't been used is generated.

Was it helpful?

Solution

Yes, you can use Rnd in this case too.

Define a function getRandom() which gives you a random string in format "XX XX XX XX" with every call.

Function getRandom() As String
    Const charList = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    getRandom = _
    Mid(charList, 35*Rnd+1, 1) + Mid(charList, 35*Rnd+1, 1) + " " + _
    Mid(charList, 35*Rnd+1, 1) + Mid(charList, 35*Rnd+1, 1) + " " + _
    Mid(charList, 35*Rnd+1, 1) + Mid(charList, 35*Rnd+1, 1) + " " + _
    Mid(charList, 35*Rnd+1, 1) + Mid(charList, 35*Rnd+1, 1)
End Function
  • charList is a string with all allowed characters 0-9 and A-Z.

  • you get an random number between 1 and 36 with 35*Rnd+1. This is your index in charList to get randomly one of the characters.

Call the function getRandom() in a cycle as long as you get a string which is not yet in your view.

OTHER TIPS

sID = Join(Evaluate(|@Password(@Unique)|))

Mid$(sID, 2, 2) & " " & Mid$(sID, 4, 2) & " " & Mid$(sID, 6, 2) & " " & Mid$(sID, 8, 2)

How it works:

  1. @Unique is a sequential string token

  2. @Password(anyText) will return a unique 32 digit HEX string enclosed in parenthesis

  3. Evaluate will run the @Function formula and return an array of 1 element. So the Join around the Evaluate will turn that to a string scalar value.

  4. The Mid$ functions simply yield 2 character values at 2 character offsets.

The only issue regarding your original parameters of your question is that you will never see get values above F since we are using Hexadecimal characters (0-9, A-F)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top