IBM i Global

IBM i 

A space for professionals working with IBM’s integrated OS for Power systems to exchange ideas, ask questions, and share expertise on topics like RPG and COBOL development, application modernization, open source integration, system administration, and business continuity.


#Power


#IBMi
#Power
#Operatingsystems
#Servers
 View Only
  • 1.  HAScript: How to generate random characters [A-Z]?

    Posted 02/09/24 05:24 AM
    Using 'Character.toString(65)' from the Java.lang.Character combining with Java.lang.Math is my first attempt.
     
    But on some of the computers I tried, 
    It throws a runtime error: 'Java.lang.Character does not contain the specified method toString'
     
    As I am not allowed to make much changes on those computers,
    is there any way to generate random characters [A-Z]?
     
    Thank you very much.


    ------------------------------
    tudis lei
    ------------------------------

    #IBMiAccessClientSolutions


  • 2.  RE: HAScript: How to generate random characters [A-Z]?

    Posted 09/25/25 08:26 AM
    <HAScript name="test" description="" timeout="6000" pausetime="20" promptall="true" blockinput="false" author="sr" creationdate="" supressclearevents="false" usevars="true" ignorepauseforenhancedtn="true" delayifnotenhancedtn="0" ignorepausetimeforenhancedtn="true" continueontimeout="false">
    
        <import>
            <type class="java.util.Random" name="javaRandom"/>
            <type class="java.lang.String" name="javaString"/>
            <type class="javax.swing.JOptionPane" name="javaOptionPane"/>
    
        </import>
    
        <vars>
            <create name="$random$" type="javaRandom" value="$new java.util.Random()$"/>
            <create name="$letters$" type="javaString" value="$new java.lang.String('ABCDEFGHIJKLMNOPQRSTUVWXYZ')$"/>
            <create name="$randIndex$" type="integer" value="$random.nextInt(26)$"/>
            <create name="$randLetter$" type="javaString" value=""/>
        </vars>
    
        <screen name="ScreenStart" entryscreen="true" exitscreen="true" transient="false">
            <description>
                <oia status="NOTINHIBITED" optional="false" invertmatch="false"/>
            </description>
            <actions>
    
                <varupdate name="$randIndex$" value="$random.nextInt(26)$"/>
                <!-- <trace type="SYSOUT" value="$randIndex$" /> -->
                <varupdate name="$randLetter$" value="$letters.substring($randIndex$,$randIndex$+1)$" />
                <!-- <trace type="SYSOUT" value="'Random Letter: ' + $randLetter$"/> -->
                <perform value="$javaOptionPane.showMessageDialog(null,'Random Letter: ' + $randLetter$)$" />
                
            </actions>
        </screen>
    
    </HAScript>


    ------------------------------
    Sabine Rein
    ------------------------------