Using MS VB - Create a program that obtains two strings within text boxes entere
ID: 3673016 • Letter: U
Question
Using MS VB - Create a program that obtains two strings within text boxes entered by a user and stores them to variables. Send the two variables as arguments to a Sub Procedure called SortStrings() that compares the strings and orders them so the first variable always contains the "lower" string. After the Sub completes, from the event-procedure that called the SortStrings() procedure, display the two variables in a label on the form in the correct order. The event-procedure should do input, calling of SortString(), and output, and the SortStrings() Sub Procedure should do the sorting, but not the input or output.
Submit a listing of the code and a working form that displays input and output
Explanation / Answer
Public Class sort
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim firstString As String = Me.firstTextBox.Text.Trim
Dim secondString As String = Me.secondTextBox.Text.Trim
Call SortStrings(firstString, secondString)
If firstString.Length.ToString > secondString.Length.ToString Then
Me.lblOutput.Text = (secondString & ", " & firstString)
ElseIf firstString.Length.ToString < secondString.Length.ToString Then
Me.lblOutput.Text = (firstString & ", " & secondString)
End If
If firstString.Length.ToString = secondString.Length.ToString Then
MessageBox.Show("yoo,Strings are equal")
End If
End Sub
Private Sub SortStrings(ByRef firstString As String, ByRef secondString As String)
If firstString.Length.ToString > secondString.Length.ToString Then
Me.lblOutput.Text = (secondString & ", " & firstString)
ElseIf firstString.Length.ToString < secondString.Length.ToString Then
Me.lblOutput.Text = (firstString & ", " & secondString)
End If
End Sub