开始使用VB.net

时间:2011-05-03 15:15:36

标签: .net vb.net

我有一些问题,我正在使用visual basic,我正在编写程序。我对此仍然有点困惑。当你把你的Dim x作为整数或你想要放在那里的任何东西时,我知道你有你的开始。现在调用一个函数,你可以在end sub下面调用一个函数。我只是对如何调用以及函数应该是什么感到困惑。我知道这可能不会,因为我很抱歉。我不理解这一点。

这就是我所拥有的,我正在努力......

Module Module1

Sub Main()
    Dim x As Double
    Dim y As Double
    Console.WriteLine()
End Sub
Private Function 

End Module

我试图了解如何做到这一点,如果有人可以解释或有一个网站,将有助于感谢。

这里是我需要做的事情之一...在主程序中调用一个函数过程来输入并返回一个名为x的双变量的值,一个直角三角形的宽度。在主过程内部第二次调用相同的函数过程来获得一个名为y的双变量的值,即右三角形的高度。

2 个答案:

答案 0 :(得分:5)

你走在正确的轨道上;您的函数需要名称和返回类型。你也需要一个结束函数。

看看这个,我认为这可能有助于你想要做的事情。

Module Module1  
    Sub Main()     
        Dim x As Double     

        ' Here we call the function below; and it's value will be returned and stored 
        ' in the variable 'y'
        Dim y As Double = GetValue()

        ' Now we're going to display y so we can see that it worked correctly
        Console.WriteLine(y) 

        'So the console window doesn't close before you can see it
        Console.Read()       
    End Sub 

    ' This is a function that we can call from other parts of our code
    ' It's name is GetValue - we call it by it's name (y = GetValue())
    ' Double is what it returns; double is a big, precise number
    ' Private referes to who can call this function (I wouldn't worry about that too much now)
    ' You need to end the function with 'End Function'.  'Return' tells it to leave the function and give back the value specified (4.0 in this case)
    Private Function GetValue() As Double  
        Return 4.0
    End Function
End Module 

答案 1 :(得分:-1)

搜索'net on“Visual Basic教程”,找到代码对你有意义的页面,复制,编译,运行,修改和重复。从运行的代码开始总是更容易。