BBjControl::setBeepOnValidationFailure

Description

In BBj 21.10 and higher, this method sets whether a BBjControl should beep when the application calls accept(0) during validation.

Syntax

Return Value

Method

void

setBeepOnValidationFailure(boolean p_shouldBeep)

Parameters

Variable Description
p_shouldBeep Indicates whether the control should beep when the application calls accept(0) in response to a validation event.

Return Value

None.

Remarks

By default, a control will beep when the application calls accept(0).

Example

rem ' BBjControl::setBeepOnValidationFailure

rem ' Initialization
open (unt)"X0"
sysgui! = BBjAPI().getSysGui()
error! = BBjColor.RED
valid! = BBjColor.WHITE
beep = msgbox("setBeepOnValidationFailure?",4+32)=6

rem ' Window
title$ = "BBjControl::setBeepOnValidationFailure"
window! = sysgui!.addWindow(100,100,500,350,title$,$00090083$)
window!.setCallback(sysgui!.ON_CLOSE,"Close")

statbar! = window!.addStatusBar(100)

rem ' Controls and control validation
edit! = window!.addEditBox(101,20,20,90,25,"")
edit!.setBeepOnValidationFailure(beep)
assert beep = edit!.getBeepOnValidationFailure()
edit!.setLongCue("TextValidation: Not empty")
edit!.setCallback(sysgui!.ON_CONTROL_VALIDATION,"TextValidation")

cedit! = window!.addCEdit(102,20,60,90,65,"Custom Edit",$8000$)
cedit!.setBeepOnValidationFailure(beep)
cedit!.setLongCue("TextValidation: Not empty")
cedit!.setCallback(sysgui!.ON_CONTROL_VALIDATION,"TextValidation")

inpute! = window!.addInputE(103,20,140,90,25,$$,32,"","InputE")
inpute!.setBeepOnValidationFailure(beep)
inpute!.setLongCue("TextValidation: Not empty")
inpute!.setCallback(sysgui!.ON_CONTROL_VALIDATION,"TextValidation")

inputn! = window!.addInputN(104,20,180,90,25,$$,"-###,###.00",$$,0,0)
inputn!.setBeepOnValidationFailure(beep)
inputn!.setLongCue("InputnValidation: Non-zero")
inputn!.setCallback(sysgui!.ON_CONTROL_VALIDATION,"InputnValidation")

inputd1! = window!.addInputD(105,20,220,90,25,$$,"",$$,0,0)
inputd1!.setBeepOnValidationFailure(beep)
inputd1!.setLongCue("InputdValidation: Within a year of today")
inputd1!.setCallback(sysgui!.ON_CONTROL_VALIDATION,"InputdValidation")
inputd1!.setValue(jul(0,0,0))

inputd2! = window!.addInputD(106,20,260,90,25,$$,"",$$,0,0)
inputd2!.setBeepOnValidationFailure(beep)
inputd2!.setLongCue("InputdValidation: Within a year of today")
inputd2!.setValue(jul(0,0,0)-1)
inputd2!.setCallback(sysgui!.ON_CONTROL_VALIDATION,"InputdValidation")

list$=$$
for letter=asc("A") to asc("Z")
    list$=list$+chr(letter)+$0a$
next letter

listbox! = window!.addListBox(108,140,20,90,100,list$)
listbox!.setBeepOnValidationFailure(beep)
listbox!.setCallback(sysgui!.ON_CONTROL_VALIDATION,"ListValidation")

listbutton! = window!.addListButton(109,140,140,90,100,list$)
listbutton!.setBeepOnValidationFailure(beep)
listbutton!.setLongCue("ListValidation: Vowel")
listbutton!.setCallback(sysgui!.ON_CONTROL_VALIDATION,"ListValidation")

listedit! = window!.addListEdit(110,140,180,90,100,list$)
listedit!.setBeepOnValidationFailure(beep)
listedit!.setLongCue("ListValidation: Vowel")
listedit!.setCallback(sysgui!.ON_CONTROL_VALIDATION,"ListValidation")

radio1! = window!.addRadioButton(111,140,220,90,25,"One",$0020$)
radio1!.setBeepOnValidationFailure(beep)
radio1!.setLongCue("RadioValidation")
radio1!.setCallback(sysgui!.ON_CONTROL_VALIDATION,"RadioValidation")

radio2! = window!.addRadioButton(112,140,260,90,25,"Two",$0020$)
radio2!.setBeepOnValidationFailure(beep)
radio2!.setLongCue("RadioValidation")
radio2!.setCallback(sysgui!.ON_CONTROL_VALIDATION,"RadioValidation")

vector! = BBjAPI().makeVector()
vector!.addItem(radio1!)
vector!.addItem(radio2!)
window!.addRadioGroup(vector!)

check1! = window!.addCheckBox(113,250,20,60,25,"Grid",$0004$)
check1!.setBeepOnValidationFailure(beep)
check1!.setLongCue("GridCheckValidation")
check1!.setCallback(sysgui!.ON_CONTROL_VALIDATION,"GridCheckValidation")

check2! = window!.addCheckBox(114,250,140,60,25,"Tree",$0004$)
check2!.setBeepOnValidationFailure(beep)
check2!.setLongCue("TreeCheckValidation")
check2!.setCallback(sysgui!.ON_CONTROL_VALIDATION,"TreeCheckValidation")

grid! = window!.addGrid(115,116,117,320,20,150,110,$81ce$,3,3)
grid!.setLongCue("GridValidation")
grid!.setBeepOnValidationFailure(beep)
grid!.setEditable(1)
grid!.setRowHeaderWidth(30)
grid!.setDefaultColumnWidth(30)
grid!.setRowHeight(20)
grid!.setCallback(sysgui!.ON_CONTROL_VALIDATION,"GridValidation")

tree! = window!.addTree(118,320,140,150,145)
tree!.setBeepOnValidationFailure(beep)
tree!.setLongCue("GridValidation")
tree!.setCallback(sysgui!.ON_CONTROL_VALIDATION,"TreeValidation")

dim music$[2,4]
music$[0,0]="The Beatles"
music$[0,1]="Hey Jude",MUSIC$[0,2]="Let It Be",MUSIC$[0,3]="Twist and Shout",MUSIC$[0,4]="Yesterday"
music$[1,0]="Paul Simon"
music$[1,1]="Bridge Over Troubled Waters",MUSIC$[1,2]="Hearts and Bones",MUSIC$[1,3]="Kathy's Song",MUSIC$[1,4]="The Sound of Silence"
music$[2,0]="Willie Nelson"
music$[2,1]="Always On My Mind",MUSIC$[2,2]="Getting Over You",MUSIC$[2,3]="Old Fords and Natural Stone",MUSIC$[2,4]="This Morning"

parent=0,node=1
tree!.setRoot(parent,"Music Tree")
for artist=0 to 2
    node=node+1
    tree!.addExpandableNode(node,parent,music$[artist,0])
    song_parent=node
    for song=1 TO 4
        node=node+1
        tree!.addNode(node,song_parent,music$[artist,song])
    next song
next artist

rem ' ToolButton should not trigger validation
ToolButton! = window!.addToolButton(9999,20,300,90,25,"ToolButton",$$)

rem ' OK Button causes form validation

OK! = window!.addButton(1,380,300,90,25,"OK")
OK!.setBeepOnValidationFailure(beep)
OK!.setCallback(sysgui!.ON_BUTTON_PUSH,"OK")
OK!.setCallback(sysgui!.ON_FORM_VALIDATION,"FormValidation")

rem ' Cancel Button suppresses all validation

Cancel! = window!.addButton(2,260,300,90,25,"Cancel")
Cancel!.setBeepOnValidationFailure(beep)
Cancel!.setCallback(sysgui!.ON_BUTTON_PUSH,"Cancel")
Cancel!.setCausesControlValidation(0)

process_events

TextValidation:
    event! = sysgui!.getLastEvent()
    text! = event!.getControl()
    print "TextValidation: '"+text!.getValidationText()+"'"
    valid=len(text!.getValidationText())
    if valid
        text!.setBackColor(valid!)
    else
        text!.setBackColor(error!)
    endif

    rem 'text!.accept(valid)
    event!.accept(valid)
return

InputnValidation:
    print "InputnValidation: '"+inputn!.getValidationText()+"'"
    valid=inputn!.getValue()
    if valid
        inputn!.setBackColor(valid!)
    else
        inputn!.setBackColor(error!)
    endif
    inputn!.accept(valid)
return

InputdValidation:
    event! = sysgui!.getLastEvent()
    inputd! = event!.getControl()
    print "InputdValidation: '"+event!.getValueAsText()+"'"
    valid=0,today=jul(0,0,0),date=jul(inputd!.getValidationText(),err=InvalidDate)
    valid=inputd!.isValid() and date>=today-366 and date<=today+366

InvalidDate:
    if valid
        inputd!.setBackColor(valid!)
        statbar!.setText("")
    else
        inputd!.setBackColor(error!)
        statbar!.setText("Please enter a date within one year of today.")
    endif
    inputd!.accept(valid)
return

ListValidation:
    list! = sysgui!.getLastEvent().getControl()
    print "ListValidation: '"+list!.getValidationText()+"'"
    valid=pos(list!.getValidationText()="AEIOU")
    if valid
        list!.setBackColor(valid!)
        statbar!.setText("")
    else
        list!.setBackColor(error!)
        statbar!.setText("Please select a vowel from the list!")
    endif
    list!.accept(valid)
return

RadioValidation:
    radio! = sysgui!.getLastEvent().getControl()
    print "RadioValidation: '"+radio!.getValidationText()+"'"
    print "Accept Radio Button: ",radio!.getText()
    radio!.accept(1)
return

GridCheckValidation:
    print "GridCheckValidation: '"+check1!.getValidationText()+"'"
    grid!.setEnabled(check1!.isSelected())
    check1!.accept(1)
return

TreeCheckValidation:
    print "TreeCheckValidation: '"+check2!.getValidationText()+"'"
    tree!.setEnabled(check2!.isSelected())
    check2!.accept(1)
return

GridValidation:
    print "GridValidation: '"+grid!.getValidationText()+"'"
    grid!.accept(1)
return

TreeValidation:
    print "TreeValidation: '"+tree!.getValidationText()+"'"
    tree!.accept(1)
return

FormValidation:
    event! = sysgui!.getLastEvent()
    control! = event!.getControl()
    valid=0,valid=jul(inputd1!.getText(),err=*next)<=jul(inputd2!.getText(),err=*next)
    if valid
        inputd1!.setBackColor(valid!)
        inputd2!.setBackColor(valid!)
        statbar!.setText("")
    else
        inputd1!.setBackColor(error!)
        inputd2!.setBackColor(error!)
        statbar!.setText("Second date must be >= first date.")
    endif

    rem 'control!.accept(valid)
    event!.accept(valid)
return

OK:
    x = msgbox("Form validation was successful")
return

Cancel:
    x = msgbox("The cancel button bypasses validation")
release

Close:
release

See Also

BBjAPI

BBjSysGui

BBjControl

BBjWindow

See the BBj Object Diagram for an illustration of the relationship between BBj Objects.