StringInputDlg.cs
/// <summary>
/// Prompt the user for input for a 'set' command
/// </summary>
/// <param name="input">The input string to operate on</param>
/// <returns>empty string on cancel, 'SET' string when successful.</returns>
Prompt the user for input for a 'set' command
Prompt the user for input for a ' set ' command
public static string PromptForSetUserInput(string input)
        {
            string retVal = "";
            string msg = GetPromptUserMesage(input);
            string location = GetSetLocation(input);
            while (retVal == "")
            {
                StringBuilder rangeMsg = new StringBuilder(25);
                String userInputValue = "";
                int min = 0;
                int max = 0;
                if (input.IndexOf("int", StringComparison.OrdinalIgnoreCase) > -1 &&
                    (GetHexRange(ref min, ref max, input, rangeMsg) || GetDecimalRange(ref min, ref max, input, rangeMsg)))
                {
                    string rangeMessage = rangeMsg.ToString();
                    NumberStyles style = rangeMessage.IndexOf('x') > 0 ? NumberStyles.HexNumber : NumberStyles.Integer;
                    string initialText = style == NumberStyles.HexNumber ? "0x" : "";
                    StringInputDlg dlg = new StringInputDlg(msg, rangeMessage, initialText);
                    int userVal = Int32.MinValue;
                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        userInputValue = dlg.getResult();
                        if (userInputValue.StartsWith("0x"))
                            userInputValue = userInputValue.Substring(2);
                        try
                        {
                            userVal = Int32.Parse(userInputValue, style);
                            if (userVal < min || userVal > max)
                            {
                                userVal = Int32.MinValue;
                                throw new Exception("Invalid input.");
                            }
                        }
                        catch (Exception )
                        {
                            ShowError(string.Format(
                                "Error with '{0}'. Value '{1}' is invalid for range {2}",
                                msg, userInputValue, rangeMessage));
                        }
                        if (userVal > Int32.MinValue)
                        {
                            retVal = string.Format("SET({0}, 0x{1:x})", location, userVal);
                        }
                    }
                    else
                    {
                        retVal = " "; 
                    }
                    dlg.Dispose();
                }
                else
                {
                    ShowError("ERROR applying line: " + input);
                    retVal = null;
                }
            }
            return retVal;
        }
public static string PromptForSetUserInput ( string input ) { string retVal = " " ; string msg = GetPromptUserMesage ( input ) ; string location = GetSetLocation ( input ) ; while ( retVal == " " ) { StringBuilder rangeMsg = new StringBuilder ( 25 ) ; String userInputValue = " " ; int min = 0 ; int max = 0 ; if ( input . IndexOf ( " " , StringComparison . OrdinalIgnoreCase ) > - 1 && ( GetHexRange ( ref min , ref max , input , rangeMsg ) || GetDecimalRange ( ref min , ref max , input , rangeMsg ) ) ) { string rangeMessage = rangeMsg . ToString ( ) ; NumberStyles style = rangeMessage . IndexOf ( ' ' ) > 0 ? NumberStyles . HexNumber : NumberStyles . Integer ; string initialText = style == NumberStyles . HexNumber ? " " : " " ; StringInputDlg dlg = new StringInputDlg ( msg , rangeMessage , initialText ) ; int userVal = Int32 . MinValue ; if ( dlg . ShowDialog ( ) == DialogResult . OK ) { userInputValue = dlg . getResult ( ) ; if ( userInputValue . StartsWith ( " " ) ) userInputValue = userInputValue . Substring ( 2 ) ; try { userVal = Int32 . Parse ( userInputValue , style ) ; if ( userVal < min || userVal > max ) { userVal = Int32 . MinValue ; throw new Exception ( " " ) ; } } catch ( Exception ) { ShowError ( string . Format ( " " , msg , userInputValue , rangeMessage ) ) ; } if ( userVal > Int32 . MinValue ) { retVal = string . Format ( " " , location , userVal ) ; } } else { retVal = " " ; } dlg . Dispose ( ) ; } else { ShowError ( " " + input ) ; retVal = null ; } } return retVal ; }
Prompt the user for input for a 'set' command
Prompt the user for input for a ' set ' command
//SET(0x2224B, {32TeamNES,28TeamNES PromptUser:Msg="Enter desired quarter length":int(1-15)} ) //SET(0x2224B, {32TeamNES,28TeamNES PromptUser:Msg="Enter desired quarter length":int(0x1-0x15)} ) //SET(0x2224B, {32TeamNES,28TeamNES PromptUser:Msg="Enter name of...":string(len=8)} ) maybe not this one. // trigger us to leave the loop
empty string on cancel, 'SET' string when successful.
empty string on cancel ' SET ' string when successful .
input
string
The input string to operate on
The input string to operate on