Skip to content

User Prompts and Input

Summary

In this example we’ll look at a few ways to use user prompts and receive user input.

Key functions used:

Function
MFGS.Terminal.Prompt
MFGS.Terminal.Get

1. Basic Prompt and Input:

'#Language "WWB-COM"
Option Explicit
Sub Main
Dim data As String
MFGS.Terminal.Prompt( _
"Example Prompt" _
, "You can add text on" _
, "multiple lines so" _
, "so a single message doesn't" _
, "exceed the terminal width." _
, _
, "Press Enter" _
, "or Q to Quit")
'Use the function below to wait for user input:
data = UCase(MFGS.Terminal.Get())
'Test for specific input string to handle system events.
'These can be anything that fits your situation.
If UCase(data) = "Q" Then
Exit Sub
End If
End Sub

2. Paging Data with Prompts

In the example below we show how it is possible to page between items in an array, in this case the array is the stockData variable which is declared and populated eslewhere. It is possible to display multiple items on a single page by introducing integer variables for pageSize and pageStartIndex. For each given page the stockData item would be accessed from the current page starting index to the current page ending index, pageStartIndex + pageSize, in increments of 1. Next, for each page, the page start index should be increased by the page size + 1.

Dim index As Integer
index = 1
Dim pageCount As Integer
pageCount = stockData.Count
Dim currentPage As Integer
currentPage = 1
MFGS.Log.Info("Page Count: " & pageCount)
Dim inputData As String
Do While True
Dim item As LocationStockDetail
Set item = stockData.GetLocationStockDetail(index)
MFGS.Terminal.Prompt( _
"Inventory by Location: " & currentPage & " of " & pageCount _
, item.warehouseID & ": " & item.locationID _
, item.inventoryID _
, "On Hand: " & item.locationOnHand _
, "Available: " & item.locationAvailable _
, _
, "Page Num or, B) Back" _
, "N, F1) Next, P, F2) Prev, Q) Quit")
inputData = MFGS.Terminal.Get()
Select Case UCase(inputData)
Case "Q"
Return inputData
Case "N", "F1"
index = index + 1
currentPage = currentPage + 1
If currentPage > pageCount Then
'There is no next page. Stay on current page.
index = index - 1
currentPage = currentPage - 1
End If
Case "P", "F2"
'Go to previous page.
index = index - 1
currentPage = currentPage - 1
If currentPage < 1 Then
index = 1
currentPage = 1
End If
Case "B"
GoTo PREVIOUS_STEP
Case 1 To stockData.Count
index = CInt(inputData)
currentPage = CInt(inputData)
Case Else
MFGS.Terminal.Prompt("Inventory by Location. . .", , , , , , "Invalid Selection. . ." & inputData, "Press any key to continue." )
inputData = MFGS.Terminal.Get()
End Select
Loop