• 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:

    • Share on Reddit (Opens in new window) Reddit
    • Share on Facebook (Opens in new window) Facebook
    • Share on LinkedIn (Opens in new window) LinkedIn
    • Share on X (Opens in new window) X
    • Email a link to a friend (Opens in new window) Email

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

    Sponsored by
    WorksRight Software

    Do you need area code information?
    Do you need ZIP Code information?
    Do you need ZIP+4 information?
    Do you need city name information?
    Do you need county information?
    Do you need a nearest dealer locator system?

    We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

    The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

    PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

    Just call us and we’ll arrange for 30 days FREE use of either ZIP/CITY or PER/ZIP4.

    WorksRight Software, Inc.
    Phone: 601-856-8337
    Fax: 601-856-9432
    Email: software@worksright.com
    Website: www.worksright.com

    Share this:

    • Share on Reddit (Opens in new window) Reddit
    • Share on Facebook (Opens in new window) Facebook
    • Share on LinkedIn (Opens in new window) LinkedIn
    • Share on X (Opens in new window) X
    • Email a link to a friend (Opens in new window) Email

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

    2 thoughts on “Guru: Playing Sounds From An RPG Program”

    • Bryan Dietz says:
      October 27, 2025 at 4:59 pm

      i’ve used ” callprc ‘QsnBeep’ ” from RPG program, and you can use ALARM in DDS

      Reply
    • mk1 says:
      September 28, 2026 at 10:29 am

      Great tip. I don’t understand how to run in the RPG program the PowerShell script stored in the variable powerShellScript. Could you explain this last bit to me?
      Thanks.

      Reply

    Leave a ReplyCancel 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

  • Power Systems Turns In Another Great Quarter
  • Big Blue Is Right On Schedule With Fall 2026 IBM i Tech Refreshes
  • Guru: Environment Variables – Global Variables Wearing Hiking Boots
  • A New IBM i Entity Takes Shape: Power By Fortra
  • IBM i PTF Guide, Volume 28, Number 38
  • Critical PHP2Shell Security Vulns Evoke ‘Black October’
  • Why Fortra Partnered with FalconStor to Launch Continuity Care: A Validated Recovery Service for IBM i
  • Guru: Analyzing User Session Statistics, Part 2
  • Fresche Launches OpsIQ, a Free AI-Based Operation Assistant for IBM i
  • IBM i PTF Guide, Volume 28, Number 37

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