' Dialog Input — demonstrates console-based input dialog simulation, no string arrays
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN() AS LONG
    LOCAL inputStr AS STRING
    LOCAL defaultVal AS STRING
    LOCAL result AS STRING
    LOCAL validated AS LONG
    LOCAL i AS LONG
    LOCAL j AS LONG
    LOCAL ch AS LONG
    LOCAL isEmpty AS LONG
    LOCAL exceedsMax AS LONG
    LOCAL valStr AS STRING
    LOCAL tempStr AS STRING
    LOCAL f0 AS STRING
    LOCAL f1 AS STRING
    LOCAL f2 AS STRING
    LOCAL f3 AS STRING
    LOCAL v0 AS STRING
    LOCAL v1 AS STRING
    LOCAL v2 AS STRING
    LOCAL v3 AS STRING
    LOCAL o0 AS STRING
    LOCAL o1 AS STRING
    LOCAL o2 AS STRING
    LOCAL o3 AS STRING
    LOCAL o4 AS STRING
    LOCAL optCount AS LONG
    LOCAL selected AS LONG
    LOCAL it0 AS STRING
    LOCAL it1 AS STRING
    LOCAL it2 AS STRING
    LOCAL it3 AS STRING
    LOCAL it4 AS STRING
    LOCAL it5 AS STRING
    LOCAL itemCount AS LONG
    LOCAL matches AS LONG
    PRINT "============================================"
    PRINT "        INPUT DIALOG DEMONSTRATION"
    PRINT "============================================"
    PRINT ""
    PRINT "Simulated dialog input with validation"
    PRINT ""
    PRINT "--- Text Input Demo ---"
    defaultVal = "Default text"
    PRINT "Enter text (default: " + defaultVal + ")"
    PRINT ">"
    LINE INPUT inputStr
    IF LEN(inputStr) = 0 THEN
        inputStr = defaultVal
    END IF
    PRINT "You entered: " + inputStr
    PRINT ""
    PRINT "--- Numeric Input with Validation ---"
    PRINT "Enter a number between 1 and 100:"
    PRINT ">"
    LINE INPUT inputStr
    validated = 0
    IF LEN(inputStr) > 0 THEN
        valStr = ""
        FOR i = 1 TO LEN(inputStr)
            ch = ASC(MID$(inputStr, i, 1))
            IF ch >= 48 AND ch <= 57 THEN
                valStr = valStr + CHR$(ch)
            END IF
        NEXT i
        IF LEN(valStr) > 0 THEN
            validated = 1
        END IF
    END IF
    IF validated = 1 THEN
        PRINT "Valid number: " + valStr
    ELSE
        PRINT "Invalid input"
    END IF
    PRINT ""
    PRINT "--- Name Input with Max Length ---"
    PRINT "Enter name (max 20 characters):"
    PRINT ">"
    LINE INPUT inputStr
    IF LEN(inputStr) > 20 THEN
        inputStr = MID$(inputStr, 1, 20)
        PRINT "Truncated to: " + inputStr
    ELSE
        PRINT "Name: " + inputStr
    END IF
    PRINT ""
    PRINT "============================================"
    PRINT "     MULTI-FIELD INPUT DIALOG"
    PRINT "============================================"
    PRINT ""
    f0 = "First Name"
    f1 = "Last Name"
    f2 = "Email"
    f3 = "Phone"
    PRINT f0 + ":"
    PRINT ">"
    LINE INPUT v0
    PRINT f1 + ":"
    PRINT ">"
    LINE INPUT v1
    PRINT f2 + ":"
    PRINT ">"
    LINE INPUT v2
    PRINT f3 + ":"
    PRINT ">"
    LINE INPUT v3
    PRINT ""
    PRINT "--- Summary ---"
    PRINT f0 + ": " + v0
    PRINT f1 + ": " + v1
    PRINT f2 + ": " + v2
    PRINT f3 + ": " + v3
    PRINT ""
    PRINT "============================================"
    PRINT "     CONFIRMATION DIALOG"
    PRINT "============================================"
    PRINT ""
    PRINT "Are you sure? (Y/N)"
    PRINT ">"
    LINE INPUT inputStr
    IF UCASE$(inputStr) = "Y" OR UCASE$(inputStr) = "YES" THEN
        PRINT "Confirmed"
    ELSE
        PRINT "Cancelled"
    END IF
    PRINT ""
    PRINT "============================================"
    PRINT "     OPTION SELECTION"
    PRINT "============================================"
    PRINT ""
    o0 = "Option Alpha"
    o1 = "Option Beta"
    o2 = "Option Gamma"
    o3 = "Option Delta"
    o4 = "Option Epsilon"
    optCount = 5
    PRINT "Select an option (1-" + STR$(optCount) + "):"
    PRINT ""
    PRINT " 1. " + o0
    PRINT " 2. " + o1
    PRINT " 3. " + o2
    PRINT " 4. " + o3
    PRINT " 5. " + o4
    PRINT ""
    PRINT ">"
    LINE INPUT inputStr
    selected = VAL(inputStr)
    IF selected >= 1 AND selected <= optCount THEN
        IF selected = 1 THEN tempStr = o0
        IF selected = 2 THEN tempStr = o1
        IF selected = 3 THEN tempStr = o2
        IF selected = 4 THEN tempStr = o3
        IF selected = 5 THEN tempStr = o4
        PRINT "You selected: " + tempStr
    ELSE
        PRINT "Invalid selection"
    END IF
    PRINT ""
    PRINT "============================================"
    PRINT "     PASSWORD INPUT (masked)"
    PRINT "============================================"
    PRINT ""
    PRINT "Enter password:"
    PRINT ">"
    LINE INPUT inputStr
    IF LEN(inputStr) > 0 THEN
        PRINT "Password length: " + STR$(LEN(inputStr)) + " characters"
    ELSE
        PRINT "Password is empty"
    END IF
    PRINT ""
    PRINT "============================================"
    PRINT "     SEARCH INPUT"
    PRINT "============================================"
    PRINT ""
    it0 = "Apple"
    it1 = "Banana"
    it2 = "Cherry"
    it3 = "Date"
    it4 = "Elderberry"
    it5 = "Fig"
    itemCount = 6
    PRINT "Search items (enter partial match):"
    PRINT ">"
    LINE INPUT inputStr
    matches = 0
    IF LEN(inputStr) > 0 THEN
        IF UCASE$(MID$(it0, 1, LEN(inputStr))) = UCASE$(inputStr) THEN
            PRINT "  " + it0
            matches = matches + 1
        END IF
        IF UCASE$(MID$(it1, 1, LEN(inputStr))) = UCASE$(inputStr) THEN
            PRINT "  " + it1
            matches = matches + 1
        END IF
        IF UCASE$(MID$(it2, 1, LEN(inputStr))) = UCASE$(inputStr) THEN
            PRINT "  " + it2
            matches = matches + 1
        END IF
        IF UCASE$(MID$(it3, 1, LEN(inputStr))) = UCASE$(inputStr) THEN
            PRINT "  " + it3
            matches = matches + 1
        END IF
        IF UCASE$(MID$(it4, 1, LEN(inputStr))) = UCASE$(inputStr) THEN
            PRINT "  " + it4
            matches = matches + 1
        END IF
        IF UCASE$(MID$(it5, 1, LEN(inputStr))) = UCASE$(inputStr) THEN
            PRINT "  " + it5
            matches = matches + 1
        END IF
    END IF
    IF matches = 0 THEN
        PRINT "No matches found"
    ELSE
        PRINT STR$(matches) + " match(es) found"
    END IF
    PRINT ""
    PRINT "Input dialog demonstration complete"
    FUNCTION = 0
END FUNCTION
