mardi 26 avril 2016

visual basic excel if

Fishing Control want a program where the fishermen can enter the name of the fish and the size. The program shall tell the user if the fish is legal or not. Below min size is illegal.This is the fish names and sizes

I wrote the below code but it is not giving me a msgbox in result. after inputting values, there is not output. very frustrating. tried many things but no result. Also tell me a shorter way of doing this. I do confess that it is a bit lengthy

Sub FishControl()
    Dim dName As String
    Dim dSize As Integer
    dName = InputBox("Please enter the name of the fish")
    dSize = InputBox("Please enter the size of the fish")

    If ((dName = trout) And (dSize < 40)) Then
    MsgBox ("This fish is illegal to hunt")

    ElseIf ((dName = trout) And (dSize >= 40)) Then
    MsgBox ("This fish is legal to hunt")

    End If

End Sub

Aucun commentaire:

Enregistrer un commentaire