Results 1 to 7 of 7

Thread: InputDialog Demo

  1. #1

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    InputDialog Demo

    Name:  10-12-2015 02.00.04.png
Views: 606
Size:  3.7 KB



    Many times when using the InputBox I've found it to be lacking in functionality with it not being a true Dialog. This is something most of the more experienced programmers online agree on, but you often see homework assignments that specify using an InputBox.

    This example encapsulates the creation of a DialogBox that has the appearance and functionality of an InputBox but also the functionality of a modal DialogBox, returning either DialogResult.OK or DialogResult.Cancel.
    The code used to call it is as you would call a Dialog, and if the result is DialogResult.OK, the returnedValue Property contains the Text the User entered.

    Compared to a standard InputBox, the InputDialog takes a few more lines of code to utilize it in your application than the single line InputBox, but gives you far more control over what is entered and retrieved from the Dialog.

    As it is, the InputDialog is a fully reusable Class that encapsulates everything necessary to use the Dialog. There are no additional Forms or Resources. All you need to do is add the class to your project and call it as shown in the example.



    Name:  10-12-2015 02.02.41.png
Views: 586
Size:  6.9 KB

    InputDialog_Demo.zip

    Version 2

    Version 2 introduces input types with testing that will not allow incorrect input.
    There are ten distinct datatypes to choose from:

    Name:  02-01-2016 13.08.40.png
Views: 457
Size:  6.8 KB

    InputDialog_Demo_v2.zip
    Last edited by .paul.; Jan 2nd, 2016 at 08:30 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: InputDialog Demo

    I haven't looked at your code but I did see the code you used in the thread you originally posted this idea in. The one thing I would say is that, if I was doing it, I would tend to look at the way MessageBox.Show is implemented compared to MsgBox and use as my model.

  3. #3
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,754

    Re: InputDialog Demo

    For your isValidInput() I'd suggest using this as a Delegate to shorten the code and make it more organized.

    All in all though
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  4. #4

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: InputDialog Demo

    Quote Originally Posted by dday9 View Post
    For your isValidInput() I'd suggest using this as a Delegate to shorten the code and make it more organized.

    All in all though
    I've seen some of your delegate examples. How would you implement that in this case?

  5. #5
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,754

    Re: InputDialog Demo

    You'd do the initial setup:
    Code:
    Private Delegate Function IsValidInput(ByVal input As String) As Boolean
    
    Private Function IsValidChar(ByVal input As String) As Boolean
        Dim value As Char
        If Char.TryParse(input, value) Then
            _returnedValue = value
            Return True
        Else
            Return False
        End If
    End Function
    
    Private Function IsValidString(ByVal input As String) As Boolean
        _returnedValue = input
        Return Not String.IsNullOrWhiteSpace(input)
    End Function
    
    'Etc...
    Then you'd use a Dictionary to hold your enumerated value and delegate function:
    Code:
    Private validationMethods As New Dictionary(Of returnTypes, IsValidInput) From {{returnTypes.Char, New IsValidInput(AddressOf IsValidChar)}, {returnTypes.String, New IsValidInput(AddressOf IsValidString), 'Etc...
    Finally when you'd want to call the delegate you'd use:
    Code:
    validationMethods.Values(returnType).Invoke("hello")
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  6. #6

    Thread Starter
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: InputDialog Demo

    It's interesting, but I don't see it as a space saver...

  7. #7
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,754

    Re: InputDialog Demo

    What I like to do is create my delegate functions inside of a Region so that they're easily collapsible and kind of out of the way. This is so that the relevant(ie - when you need to do the validation) is only one line.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width