Subject: Agent / Designer question
Kind of nearly does the job? Maybe, but it’s also awfully ugly, ain’t it? There are better ways to write more-or-less the same thing that are both more maintainable and less annoying to the user.
By more maintainable, I mean using explicit declarations and readable types (instead of type suffixes) and eliminating the gotos and labels. With the code as it is, you need a separate label for every possible returned number value.
By less annoying, I mean that the user should have a chance to bail out, and there’s no way for the user to change his/her mind about the font size adjustment using that code. Clicking “Cancel” beats the heck out of typing, say, “0” if the user does not want to change font sizes – the Prompt method of the NotesUIWorkspace serves better than Inputbox for most uses. The equivalent code might be:
Option Public
Option Declare
Dim session As NotesSession
Dim ws As NotesUIWorkspace
Dim adjustNumber As Integer
Dim promptReturn As Variant
Dim promptMessage As String
Dim currentSetting As String
Dim badValueReturned As Boolean
Const BAD_VALUE_MESSAGE = “The font size adjustment must be a number between 0 and 25”
Const TWO_NEW_LINES = {
} 'Two literal new lines
Const PROMPT_TITLE = “Adjust Font Size - Applies To All”
Const PROMPT_INTRO = “Please enter the amount of font enlargement you desire. Use a number between 0 and 25.”
Const PROMPT_VALUES = “0 (zero) uses the default size. 25 is VERY large.”
Const PROMPT_CURRENT = "Your current setting is: "
Sub Initialize
Set session = New NotesSession
Set ws = New NotesUIWorkspace
adjustNumber = 0
badValueReturned = False
currentSetting = session.GetEnvironmentString("Display_font_adjustment", True)
If currentSetting = "" Then
currentSetting = "0"
End If
On Error Goto ErrorHandler
Do
If badValueReturned Then
promptMessage = BAD_VALUE_MESSAGE + TWO_NEW_LINES + PROMPT_INTRO + TWO_NEW_LINES + PROMPT_VALUES + TWO_NEW_LINES + PROMPT_CURRENT + currentSetting
Else
promptMessage = PROMPT_INTRO + TWO_NEW_LINES + PROMPT_VALUES + TWO_NEW_LINES + PROMPT_CURRENT + currentSetting
End If
'Reset bad value flag for next attempt
badValueReturned = False
promptReturn = ws.Prompt(PROMPT_OKCANCELEDIT, PROMPT_TITLE, promptMessage, "")
If Isempty(promptReturn) Then
'User clicked Cancel -- Bail out
Exit Sub
Else
adjustNumber = Cint(promptReturn) 'This may error
Select Case adjustNumber
Case 0
If Not badValueReturned Then
Call session.SetEnvironmentVar("Display_font_adjustment", "", True) 'removes ini value if present
End If
Case 1 To 25
Call session.SetEnvironmentVar("Display_font_adjustment", adjustNumber, True)
Case Else
badValueReturned = True
End Select
End If
Loop While badValueReturned
ExitGracefully:
Exit Sub
ErrorHandler:
adjustNumber = 99 'An illegal value
Resume Next
End Sub
Sure, it’s a LOT longer, but it’s also a lot easier to follow and maintain AND it’s more user-friendly IMHO.