Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the features of the VB 2005 console

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you what the characteristics of the VB 2005 console, I believe most people do not know much, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Computer users often treat console applications as "relics", but they are still a favorite part of system administrators and one of the "toolkits" for master users. In addition, this console application is used when you need a lot of repetitive scripting operations and, of course, more complex operations.

There was little support for creating console applications in earlier versions of Visual Basic. And although VB 6 and earlier versions can create console applications, this is not a simple or straightforward process. Creating a console application in VB 6 requires a Win32 API call; even so, you can't control the cursor position or the color of the text, and to a large extent you can only be limited to coding from left to right and top to bottom.

Today, VB.net introduces new console application features. It's not only in "New Project..." The dialog box provides a console application project and, most importantly, a console (Console) object. So you don't have to "worry" about Win32 API anymore. However, you are still limited to left-to-right and top-to-bottom coding. However, VB.net still lacks methods or properties for changing the position or color of the cursor or text, as well as many other more advanced features.

First, the characteristics of the new console application in VB 2005

Based on the Console objects provided in earlier versions of VB.NET, today's VB 2005 adds many excellent features to console applications. The following are just some of the more exciting features in VB 2005:

◆ clears the console window

◆ gets and sets the cursor position and size

◆ gets and sets the window height and width

◆ gets and sets the foreground and background colors

◆ selects and moves some text within the console window

The rest of this article will analyze the creation of a console application in detail to demonstrate the use of these features.

2. Example application-DirCopy

I often copy files from one directory to another from the console window. When I copy a directory that contains a large number of files, I often want to get some hints-how is the replication process going? Is the copy almost over or will you wait a little longer? To achieve this, I built a console application that displays a progress bar in the console window to graphically show the progress of the replication.

III. Defining functions

To simplify the demonstration in this article, DirCopy will use two command-line arguments: a source directory and a destination directory. It then copies all files from the source directory to the destination directory. Note that this simple program cannot copy subdirectories under the source directory. First of all, I write a DisplayUsing subroutine. If you call DirCopy with too many or too few command-line arguments, it calls DisplayUsage and ends. The following is the code for the DisplayUsage subroutine:

Private Sub DisplayUsage () Dim originalForegroundColor As ConsoleConsoleColor = Console.ForegroundColor Console.Clear () Console.ForegroundColor = ConsoleColor.Green Console.WriteLine ("DirCopy 1.0") Console.WriteLine ("Written by Josh Fitzgerald") Console.WriteLine (New String ("-", Console.WindowWidth)) Console.WriteLine ("DirCopy will copy all of the files from the source folder to the") Console.WriteLine ("destination folder. While the files are copying, a progress bar") Console.WriteLine ("will display the percent complete.") Console.WriteLine () Console.WriteLine (If a directory name contains spaces, enclose it in double quotes. ") Console.WriteLine () Console.Write ("Example:") Console.ForegroundColor = ConsoleColor.Magenta Console.WriteLine ("DirCopy C:\ MyFolder C:\ MyNewFolder") Console.ForegroundColor = ConsoleColor.Green Console.WriteLine () Console.Write ("Example:") Console.ForegroundColor = ConsoleColor.Magenta Console.WriteLine ("DirCopy"C:\ MyFolder" C:\ MyNewFolder ") Console.ForegroundColor = originalForegroundColor End Sub

What the subroutine does is create a variable originalForegroundColor, which then stores the value of Console.ForegroundColor. In the * of the subroutine, the code sets the Console.ForegroundColor property back to originalForegroundColor. When you analyze this part of the code, you will notice that this is done in every subroutine that modifies the foreground or background color. Before actually running DirCopy, I want to make sure that DirCopy always makes the console display the same color.

The next thing DisplayUsage does is clear the console screen using the Console.Clear method. This is one of the new approaches in VB2005; this way, programmers can easily have a clean console window.

I want the help text to stand out, so I set the ForegroundColor property to green. Then I use the Writeline and Write methods to output a few lines of text to the screen. In the description of * *, I include some examples of how to run DirCopy. I want to make these examples stand out; so I set ForegroundColor to magenta. The new console of VB 2005 is introduced above.

These are all the contents of this article entitled "what are the characteristics of the VB 2005 console?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report