• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Guru: Playing Sounds From An RPG Program

    October 20, 2025 Mike Larsen

    I received a request to play audio sounds when an event took place on a display file. I hadn’t done this before, but I thought it was interesting to find out how it could be done. As with many tasks, it turns out there are more than one way to do this. My goal was to choose a method to make the process as seamless as possible.

    At first, the request was to play two sounds: one that would signal a positive event, and another to signal a negative event. But, as I started working with the project, I found other instances where an audible sound might be helpful. While it’s easy to remember what two sounds represent, it may become more difficult to remember what additional sounds might be alerting. With that in mind, I thought it would be great if the program could speak the words that would give the end user an understanding of what is going on. While I wasn’t able to achieve a text-to-speech solution, I recorded my own .wav file that would speak the words I wanted to end user to hear. There are free services available online that allowed me to do that. Once I had the .wav file built, I could then play that from my RPG program when necessary. So how did I do this? Let’s dig into the details!

    I have known for many years that one can execute Windows commands from IBM i, so I started there. I began working with the Start PC Command (STRPCCMD). I’ve used this command in the past to open Excel and Word documents, among other things. Having this knowledge, I thought I would also be able to open programs such as Windows Media Player, and that would allow me to play .wav files.

    When using this command, one must know the path to the executable. Once you have that, you should be able to launch the program. A quick Google search helped me find where I might find executables to Windows programs.

    While I was able to get Windows Media Player to work, I found SoundPlayer fit my needs better as I found it easier to close it and/or hide it when the sound stopped playing. I felt this created a better experience for the end user.

    Let’s look at the program I built. I’m going to show and explain snippets of the program, but the full source will be available to you.

    I start by defining the QCMDEXC prototype (Figure 1) that I’ll need to start the PC Organizer (STRPCO). In order to execute PC commands, the PC Organizer must be running. It only needs to be started once for the job in which the commands are running.

    Figure 1. QCMDEXC to start PC Organizer

    Next, I’ll start the PC Organizer (Figure 2).

    Figure 2. Start the PC Organizer

    Now that the PC Organizer is started, I can execute commands on the PC. Since I have three possible sounds to play, I created a Select statement (Figure 3) to determine which sound to play. As this is a sample program, I hard-coded the values to make it easier to demonstrate. In a production program, this would likely be a parameter passed to the program.

    Figure 3. Determine which sound to play

    It makes sense to stop at this point and explain what is happening in the PowerShell script. I’ll detail one of the scripts since they are mostly the same (except for the sound to play) and I’ll reference the parts by line number.

    On line 56, I’m declaring that I’m executing a PowerShell command (indicated by -c), and I’m creating a new instance of SoundPlayer.

    On line 57, I specify the path to the sound I want to play and that I want to play it. Two of the sounds (windowsCriticalStop and windowsDing are standard Windows sounds that are typically installed on the system by default. You should, however, verify the sounds are in that location for any PCs on which the program will be running. Additionally, in the production program, I soft-coded the paths to make the program more flexible.

    On line 58, I use the cmdlet, Start-Sleep to specify that I want the command to execute for one second (indicated by -s 1), then I want to exit the SoundPlayer. In my case, I know the sounds I’m using complete in one second. If your sounds need to play longer, you can increase the number of seconds for the SoundPlayer to execute.

    While two of these sounds are standard Windows sounds, they should already exist on the PC. But remember earlier I mentioned I created a custom sound? I need to make sure the path in my program points to the location of the sound. Since this is not a standard Windows sound, you will need to be careful to put the custom sound in the same location on all PCs that will be running the RPG program.

    There is one final item to point out. You’ll notice that on lines 52 and 57, I have the back tick mark specified in the sound name. I must do this to escape spaces that are present in the sound name, so the PowerShell script can interpret it correctly.

    With a short amount of code, I was able to play sounds from RPG. This program proved to be very successful to the end users and opens up potential for use in future projects.

    Mike Larsen is a director of information technology at Auburn Pharmaceutical and has been working with IBM i systems for over 20 years. He specializes in RPG, CL, and SQL and recently has been working with PHP and Python. Current projects have given Mike the opportunity to work with generating and parsing XML and JSON from SQL and consuming SOAP and REST web services. Although his main area of expertise is on IBM i, Mike has a passion for learning other languages and how he can integrate other platforms with IBM i.

    RELATED STORIES

    Guru: Creating An SQL Stored Procedure That Returns A Result Set

    Guru: Creating An RPG Stored Procedure That Returns A Result Set

    Guru: Creating An RPG Stored Procedure With Parameters

    Guru: Creating A Web Service With Basic Authentication

    Guru: Parsing JSON That Has Spaces In The Key

    Guru: Partitioning Result Sets Using SQL

    Guru: Comparing IFS Directories Using SQL

    Guru: String Manipulation Using SQL

    Guru: Regular Expressions, Part 1

    Guru: Regular Expressions, Part 2

    Guru: Debugging SQL Stored Procedures With ACS

    Guru: Creating PDF Documents With Python

    Guru: Creating Excel Spreadsheets With Python

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags: Tags: 400guru, FHG, Four Hundred Guru, IBM i, PowerShell, RPG

    Sponsored by
    Raz-Lee Security

    Start your Road to Zero Trust!

    Firewall Network security, controlling Exit Points, Open DB’s and SSH. Rule Wizards and graphical BI.

    Request Demo

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    A Bit More Insight Into IBM’s “Spyre” AI Accelerator For Power IBM Just Killed Merlin. Here’s Why

    Leave a Reply Cancel reply

TFH Volume: 35 Issue: 38

This Issue Sponsored By

  • Maxava
  • New Generation Software
  • Raz-Lee Security
  • ARCAD Software
  • WorksRight Software

Table of Contents

  • IBM Pulls The Curtain Back A Smidge On Project Bob
  • IBM Just Killed Merlin. Here’s Why
  • Guru: Playing Sounds From An RPG Program
  • A Bit More Insight Into IBM’s “Spyre” AI Accelerator For Power
  • IBM i PTF Guide, Volume 27, Number 42

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • IBM Pulls The Curtain Back A Smidge On Project Bob
  • IBM Just Killed Merlin. Here’s Why
  • Guru: Playing Sounds From An RPG Program
  • A Bit More Insight Into IBM’s “Spyre” AI Accelerator For Power
  • IBM i PTF Guide, Volume 27, Number 42
  • What You Will Find In IBM i 7.6 TR1 and IBM i 7.5 TR7
  • Three Things For IBM i Shops To Consider About DevSecOps
  • Big Blue Converges IBM i RPG And System Z COBOL Code Assistants Into “Project Bob”
  • As I See It: Retirement Challenges
  • IBM i PTF Guide, Volume 27, Number 41

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle