locked
Writing a Small Basic extension and need help. RRS feed

  • Question

  • I am writing a simple SB extension that allows users to show a dialog box and specify a default button (which as far as I know hasn't been done). Please bear with me because I am learning C# as I go. Here's my code:

    using Microsoft.SmallBasic.Library;
    using System.Windows.Forms;
     
    namespace Dialogs_Extension
    {
        [SmallBasicType]
        public static class DialogsPlus
        {
            public static Primitive ShowMessage(Primitive content, Primitive title, buttons, icon, defaultbutton)
            {
                Primitive result;
                result =  MessageBox.Show(content.ToString(), title.ToString(), buttons, icon, defaultbutton);
                return result;
            }
        }
    }

    It shows errors about converting the variables to their respective types. I tried getting them in their right types from SB and outputting them as a MessageBoxResult, but SB wouldn't recognize the extension. Any ideas?

    Sunday, March 25, 2012 11:04 PM
    Answerer

Answers

  • You can think of a Primitive as a string that has methods to convert it to a number for arthmetic, or an array.  Basically it is just a string set of characters.  So you need to check this string and do something with it depending on its value.  This is an if elseif construct where you can set the inputs for MessageBoxButtons etc depending on Primitive input.

    Primitive value;
    if (value == "OK")
    {
    }
    else if (value == "Cancel")
    {
    }
    
    
    or
    
    if (value == 0)
    {
    }
    else if (value == 1)
    {
    }
    else
    {
    }
    
    etc

    Tuesday, March 27, 2012 8:16 AM

All replies

  • To get the intellisense to show up in SB you need to add it to the extension programming - type /// before the methods to bring it up to fill in.

    You also need to enable it and make sure you are referencing .Net 3.5.  Instructions for this can be found in a getting started guide I wrote called 'Guide to writing extensions' in the 'Other Resource Downloads' section (expand it), website here.

    To change a type you may need to recast it, perhaps in your case its as simple as converting it to a string - the Primitive to string conversion is implicit so you don't need to do it explicitly in the call to Show (you don't need the .ToString() there), but you do need it for the return result of the call to Show, e.g. 'return result.ToString()'.

    Also, don't pass the arguments buttons, icon, defaultbutton, just use defaults, perhaps:

    using Microsoft.SmallBasic.Library;
    using System.Windows.Forms;
     
    namespace Dialogs_Extension
    {
        /// <summary>
        /// You Methods name
        /// </summary>
        [SmallBasicType]
        public static class DialogsPlus
        {
            /// <summary>
            /// Describe method
            /// </summary>
            /// <param name="content">describe input</param>
            /// <param name="title">describe input</param>
            /// <returns>describe returns</returns>
            public static Primitive ShowMessage(Primitive content, Primitive title)
            {
                return MessageBox.Show(content, title, MessageBoxButtons.OK).ToString();
            }
        }
    }

    Monday, March 26, 2012 12:17 PM
  • Thanks! I read your guide. However, I'm still a little confused. Could you please show me how to take a Primitive input and convert it to a MessageBoxButtons or MessageBoxIcon or MessageBoxDefaultButton? I would like to add this functionality, or else it would just be like a copy of the Data Extension's Dialogs class.
    Monday, March 26, 2012 10:27 PM
    Answerer
  • You can think of a Primitive as a string that has methods to convert it to a number for arthmetic, or an array.  Basically it is just a string set of characters.  So you need to check this string and do something with it depending on its value.  This is an if elseif construct where you can set the inputs for MessageBoxButtons etc depending on Primitive input.

    Primitive value;
    if (value == "OK")
    {
    }
    else if (value == "Cancel")
    {
    }
    
    
    or
    
    if (value == 0)
    {
    }
    else if (value == 1)
    {
    }
    else
    {
    }
    
    etc

    Tuesday, March 27, 2012 8:16 AM
  • Thanks for all the help. My extension development is going smoothly now =)
    Tuesday, March 27, 2012 10:11 PM
    Answerer