大家好,Stackoverflow guyz,我的代码有问题,最后一行的值始终为零。我不知道为什么我的公共职能是对还是错,但是我感觉它就在那里。
Imports System
Public Class Dog
Private Dogname As String
Private DogAge As Integer
Private ToHumanAge As Integer
Private DogBreed As String
Public Sub AcceptDetails()
Console.Write("Enter Dog's Name: ")
Dogname = Console.ReadLine
Console.Write("Enter Age in calendar years: ")
DogAge = Console.ReadLine
Console.Write("Enter Dog's Breed: ")
DogBreed = Console.ReadLine
End Sub
Public Function GetDogAge()
If DogAge <= 2 Then
GetDogAge = DogAge * 11
Else
GetDogAge = (((DogAge - 2) * 5) + 22)
End If
End
End Function
Public Sub Display()
Console.WriteLine("Dog Name: " & Dogname)
Console.WriteLine("Dog Breed: " & DogBreed)
Console.WriteLine("Dog Age to Human:" & GetDogAge())
Console.Read()
End Sub
End Class
Module Module1
Sub Main()
Dim D As New Dog()
D.AcceptDetails()
D.Display()
Console.Read()
End Sub
End Module
答案 0 :(得分:0)
您没有返回从函数中获得的值, 我做了一些调整,这是我的版本:
Module Dog
Private Dogname As String
Private DogAge As Integer
Private DogBreed As String
Sub Main(args As String())
AcceptDetails()
Display()
Console.Read()
End Sub
Public Sub AcceptDetails()
Console.Write("Enter Dog's Name: ")
Dogname = Console.ReadLine
Console.Write("Enter Age in calendar years: ")
DogAge = Console.ReadLine
Console.Write("Enter Dog's Breed: ")
DogBreed = Console.ReadLine
End Sub
Public Function GetDogAge()
If DogAge <= 2 Then
GetDogAge = DogAge * 11
Else
GetDogAge = (((DogAge - 2) * 5) + 22)
End If
Return GetDogAge
End Function
Public Sub Display()
Console.WriteLine("Dog Name: " & Dogname)
Console.WriteLine("Dog Breed: " & DogBreed)
Console.WriteLine("Dog Age to Human:" & GetDogAge())
Console.Read()
End Sub
End Module