在vb中做出改变

时间:2012-10-17 18:48:20

标签: vb.net

  

可能重复:
  Visual Basic Friend Error

我正在尝试创建一个使用不同子进行更改的程序。到目前为止,我只是在处理美元和季度,但我有一些重大问题。有人可以帮忙吗?提前谢谢。

Option Explicit On
'Option Strict On

Imports System

Module Conversion
  Sub Coin()
    Number = (Number mod 1.00)
    Console.Writeline(Number)
    Number = (Number mod 0.25)
    Console.Writeline(Number)
  End Sub

  Sub Main()
    Console.Write("Enter the Canadian dollar amount: ")
    Dim input As Decimal = Console.ReadLine()
    Dim Number As Decimal = Input
    Coin()
  End Sub

End Module

2 个答案:

答案 0 :(得分:1)

Coin无法看到Number。您必须将Number作为参数传递给Coin(),如下所示:

Sub Main()
  Console.Write("Enter the Canadian dollar amount: ")
  Dim input As Decimal = Console.ReadLine()
  Dim Number As Decimal = Input
  Coin(Number)
End Sub

Sub Coin(Number as Decimal)
  Number = (Number mod 1.00)
  Console.Writeline(Number)
  Number = (Number mod 0.25)
  Console.Writeline(Number)
End Sub

答案 1 :(得分:0)

{p> Number未在Coin()方法中定义。您必须让Coin()获取参数或让Number成为Coin()

可访问的模块成员

例如:

Sub Coin(Byval Number as Decimal)
  Number = (Number mod 1.00)
  Console.Writeline(Number)
  Number = (Number mod 0.25)
  Console.Writeline(Number)
End Sub