本文整理汇总了VB.NET中System.Console.Error属性的典型用法代码示例。如果您正苦于以下问题:VB.NET Console.Error属性的具体用法?VB.NET Console.Error怎么用?VB.NET Console.Error使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Console 的用法示例。
在下文中一共展示了Console.Error属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: ExpandTabs
' 导入命名空间
Imports System.IO
Public Class ExpandTabs
Private Const tabSize As Integer = 4
Private Const usageText As String = "Usage: EXPANDTABSEX inputfile.txt outputfile.txt"
Public Shared Sub Main(args() As String)
Dim writer As StreamWriter = Nothing
If args.Length < 2 Then
Console.WriteLine(usageText)
Exit Sub
End If
Try
writer = New StreamWriter(args(1))
Console.SetOut(writer)
Console.SetIn(New StreamReader(args(0)))
Catch e As IOException
Console.Error.WriteLine(e.Message)
Console.Error.WriteLine(usageText)
Exit Sub
End Try
Dim i As Integer = Console.Read()
While i <> -1
Dim c As Char = Convert.ToChar(i)
If c = ControlChars.Tab Then
Console.Write("".PadRight(tabSize, " "c))
Else
Console.Write(c)
End If
i = Console.Read()
End While
writer.Close()
' Reacquire the standard output stream so that a
' completion message can be displayed.
Dim standardOutput As New StreamWriter(Console.OpenStandardOutput)
standardOutput.AutoFlush = True
Console.SetOut(standardOutput)
Console.WriteLine("EXPANDTABSEX has completed the processing of {0}.", args(0))
End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System,代码行数:45,代码来源:Console.Error
示例2: ViewTextFile
' 导入命名空间
Imports System.IO
Module ViewTextFile
Public Sub Main()
Dim args() As String = Environment.GetCommandLineArgs()
Dim errorOutput As String = ""
' Make sure that there is at least one command line argument.
If args.Length <= 1 Then
errorOutput += "You must include a filename on the command line." +
vbCrLf
End If
For ctr As Integer = 1 To args.GetUpperBound(0)
' Check whether the file exists.
If Not File.Exists(args(ctr)) Then
errorOutput += String.Format("'{0}' does not exist.{1}",
args(ctr), vbCrLf)
Else
' Display the contents of the file.
Dim sr As New StreamReader(args(ctr))
Dim contents As String = sr.ReadToEnd()
sr.Close()
Console.WriteLine("***** Contents of file '{0}':{1}{1}",
args(ctr), vbCrLf)
Console.WriteLine(contents)
Console.WriteLine("*****{0}", vbCrLf)
End If
Next
' Check for error conditions.
If Not String.IsNullOrEmpty(errorOutput) Then
' Write error information to a file.
Console.SetError(New StreamWriter(".\ViewTextFile.Err.txt"))
Console.Error.WriteLine(errorOutput)
Console.Error.Close()
' Reacquire the standard error stream.
Dim standardError As New StreamWriter(Console.OpenStandardError())
standardError.AutoFlush = True
Console.SetError(standardError)
Console.Error.WriteLine("{0}Error information written to ViewTextFile.Err.txt",
vbCrLf)
End If
End Sub
End Module
' If the example is compiled and run with the following command line:
' ViewTextFile file1.txt file2.txt
' and neither file1.txt nor file2.txt exist, it displays the
' following output:
' Error information written to ViewTextFile.Err.txt
' and writes the following text to ViewTextFile.Err.txt:
' 'file1.txt' does not exist.
' 'file2.txt' does not exist.
开发者ID:VB.NET开发者,项目名称:System,代码行数:53,代码来源:Console.Error
示例3: Example
Module Example
Public Sub Main()
Dim increment As Integer = 0
Dim exitFlag As Boolean = False
Do While Not exitFlag
If Console.IsOutputRedirected Then
Console.Error.WriteLine("Generating multiples of numbers from {0} to {1}",
increment + 1, increment + 10)
End If
Console.WriteLine("Generating multiples of numbers from {0} to {1}",
increment + 1, increment + 10)
For ctr As Integer = increment + 1 To increment + 10
Console.Write("Multiples of {0}: ", ctr)
For ctr2 As Integer = 1 To 10
Console.Write("{0}{1}", ctr * ctr2, If(ctr2 = 10, "", ", "))
Next
Console.WriteLine()
Next
Console.WriteLine()
increment += 10
Console.Error.Write("Display multiples of {0} through {1} (y/n)? ",
increment + 1, increment + 10)
Dim response As Char = Console.ReadKey(True).KeyChar
Console.Error.WriteLine(response)
If Not Console.IsOutputRedirected Then
Console.CursorTop = Console.CursorTop - 1
End If
If Char.ToUpperInvariant(response) = "N" Then exitFlag = True
Loop
End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:33,代码来源:Console.Error
注:本文中的System.Console.Error属性示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论