Question How do I operate this function?

FroDesigns

Member
Joined
Aug 23, 2009
Messages
6
Programming Experience
1-3
Well I am trying to use functions in one of my program so I tried a function with an If, then statement that returns a value either true or false.
This is my code:
VB.NET:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        strings11 = True
        MsgBox(strings11)
    End Sub
    Public Function strings11(ByVal a As String) As Boolean
        a = InputBox("enter number:")
        If (a = "1" Or "2") Then

        Else

            Return False
        End If
    End Function

When I ran it, it came up with an error: Error 1 Argument not specified for parameter 'a' of 'Public Function strings11(a As String) As Boolean'. C:\Users\Dennis_2\Documents\Visual Studio 2005\Projects\UsingADLL2\UsingADLL2\Form1.vb 6 9 UsingADLL2

Can anyone help me figure out how to run the function?
 
First of all, turn Option Strict On, which will make sure you don't try to assign the wrong type data to a variable.

You failed to declare variables by the correct type.

The function returns a Boolean value, not a string. It starts out as False by default.

You should never include an input inside a function procedure. It belongs in your button Click event.

The result of an input box is a string. That should be the argument to pass down to the function.

The result of the function is passed back to the Boolean variable in the button event.

The messagebox output must be converted from a Boolean to a String.

Here is the correct code:


VB.NET:
Option Strict On
Public Class Form1

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim ans As Boolean
		Dim a As String
		a = InputBox("Enter number:")
		ans = strings11(a)
		MessageBox.Show(ans.ToString)
	End Sub
	Public Function strings11(ByVal a As String) As Boolean
		If (a = "1" Or a = "2") Then
			Return True
		End If
	End Function

End Class
 
Back
Top