当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET Console.Beep方法代码示例

本文整理汇总了VB.NET中System.Console.Beep方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Console.Beep方法的具体用法?VB.NET Console.Beep怎么用?VB.NET Console.Beep使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Console的用法示例。


在下文中一共展示了Console.Beep方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。

示例1: Sample

' This example demonstrates the Console.Beep() method.
Class Sample
   Public Shared Sub Main(args() As String)
      Dim x As Integer = 0
      Dim i As Integer
      '
      If      (args.Length = 1) _
      AndAlso (Int32.TryParse(args(0), x) = True) _
      AndAlso ((x >= 1) AndAlso (x <= 9)) Then
         For i = 1 To x
            Console.WriteLine("Beep number {0}.", i)
            Console.Beep()
         Next i
      Else
         Console.WriteLine("Usage: Enter the number of times (between 1 and 9) to beep.")
      End If
   End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System,代码行数:18,代码来源:Console.Beep

输出:

>beep
Usage: Enter the number of times (between 1 and 9) to beep

>beep 9
Beep number 1.
Beep number 2.
Beep number 3.
Beep number 4.
Beep number 5.
Beep number 6.
Beep number 7.
Beep number 8.
Beep number 9.

示例2: Sample

' This example demonstrates the Console.Beep(Int32, Int32) method
Imports System.Threading

Class Sample
   Public Shared Sub Main()
      ' Declare the first few notes of the song, "Mary Had A Little Lamb".
      Dim Mary As Note() =  { _
            New Note(Tone.B, Duration.QUARTER), _
            New Note(Tone.A, Duration.QUARTER), _
            New Note(Tone.GbelowC, Duration.QUARTER), _
            New Note(Tone.A, Duration.QUARTER), _
            New Note(Tone.B, Duration.QUARTER), _
            New Note(Tone.B, Duration.QUARTER), _
            New Note(Tone.B, Duration.HALF), _
            New Note(Tone.A, Duration.QUARTER), _
            New Note(Tone.A, Duration.QUARTER), _
            New Note(Tone.A, Duration.HALF), _
            New Note(Tone.B, Duration.QUARTER), _
            New Note(Tone.D, Duration.QUARTER), _
            New Note(Tone.D, Duration.HALF)}
      ' Play the song
      Play(Mary)
   End Sub
   
   ' Play the notes in a song.
   Protected Shared Sub Play(tune() As Note)
      Dim n As Note
      For Each n In  tune
         If n.NoteTone = Tone.REST Then
            Thread.Sleep(CInt(n.NoteDuration))
         Else
            Console.Beep(CInt(n.NoteTone), CInt(n.NoteDuration))
         End If
      Next n
   End Sub
   ' Define the frequencies of notes in an octave, as well as 
   ' silence (rest).
   
   Protected Enum Tone
      REST = 0
      GbelowC = 196
      A = 220
      Asharp = 233
      B = 247
      C = 262
      Csharp = 277
      D = 294
      Dsharp = 311
      E = 330
      F = 349
      Fsharp = 370
      G = 392
      Gsharp = 415
   End Enum 'Tone
   
   ' Define the duration of a note in units of milliseconds.
   
   Protected Enum Duration
      WHOLE = 1600
      HALF = WHOLE / 2
      QUARTER = HALF / 2
      EIGHTH = QUARTER / 2
      SIXTEENTH = EIGHTH / 2
   End Enum 'Duration
   
   ' Define a note as a frequency (tone) and the amount of 
   ' time (duration) the note plays.
   Protected Structure Note
      Private toneVal As Tone
      Private durVal As Duration
      
      ' Define a constructor to create a specific note.
      Public Sub New(frequency As Tone, time As Duration)
         toneVal = frequency
         durVal = time
      End Sub
      
      ' Define properties to return the note's tone and duration.
      Public ReadOnly Property NoteTone() As Tone
         Get
            Return toneVal
         End Get
      End Property
      
      Public ReadOnly Property NoteDuration() As Duration
         Get
            Return durVal
         End Get
      End Property
   End Structure 'Note '
'This example produces the following results:
'
'This example plays the first few notes of "Mary Had A Little Lamb" 
'through the console speaker.
'
End Class
开发者ID:VB.NET开发者,项目名称:System,代码行数:96,代码来源:Console.Beep


注:本文中的System.Console.Beep方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。