Calling a routine to check for a valid anagram using user supplied values in vb.net

In the prior post we explored some vb.net code used to sort strings in an effort to help us find out if a text string was an anagram. We took the approach that if two strings are sorted the same way, and you compare them and they match then they are anagrams. We also created a console program to test this out and created a vb.net function to help us.

Now we will add some ability to enter a user input to make it easier to test out. Ultimately we want to make this a functional web page however console programs are so easy to create with visual studio that for bare bones functionality, I find they are quite useful to simple proof of concept exercises.

In our new revised program we will end up with output like the following:

this program will compare a user supplied dictionary word with
a user supplied anagram candidate. If the two sorted strings match,
it is a confirmed anagram. If they do not match, it is not an anagram.
Enter the dictionary word
alps
Enter the anagram
slap
tmp is now slap
tmp is now laps
tmp is now alps
tmp is now alps
tmp is now alps
tmp is now alps
unsorted text is: slap and the sorted text is: alps

Good job, this is an anagram

But what about the vb.net source code, how does that look? Please see the following:

Sub Main()

        Dim myDictionaryWord As String
        Dim sorted_dw As String
        Console.WriteLine("this program will compare a user supplied dictionary word with")
        Console.WriteLine("a user supplied anagram candidate. If the two sorted strings match,")
        Console.WriteLine("it is a confirmed anagram. If they do not match, it is not an anagram.")
        Console.WriteLine("Enter the dictionary word")
        myDictionaryWord = Console.ReadLine()
        Dim Anagram_candidate As String
        Console.WriteLine("Enter the anagram")
        Anagram_candidate = Console.ReadLine()
        Dim sorted_ac As String
        sorted_ac = GetSortedText(Anagram_candidate)
        sorted_dw = GetSortedText(myDictionaryWord)
        Console.WriteLine("unsorted text is: {0} and the sorted text is: {1}", Anagram_candidate, sorted_ac)
        Console.WriteLine()
        If StrComp(sorted_ac, sorted_dw) = 0 Then
            Console.WriteLine("Good job, this is an anagram")
        Else
            Console.WriteLine("Sorry, this is not an anagram")
        End If

    End Sub

Notice that the code relies only on user input.

In the few test runs it does seem to work though more testing is needed.

Ideally we would want to include some database functionality in the program in order to make sure a word is listed in a valid list of words however that functionality will take some additional work that I will leave to a future post to explore. Also, vb.net is used in dot net framework in ASP.NET but many sites rely on PHP as a server-side language. So, in a future post we can explore what that code would look like.