04-16-2012, 16:12
Hello guys, this is just a random tutorial I decided to share with you. That was just my school project, nothing special, just some shit to get an A mark. The only interesting thing in this project is its construction. So let me tell you how to do this...
Okay, now once you are ready to start - let's do this.
First of all, we are making a console application in VB.NET (I was using 4.5 Framework, although all these commands will work on older versions either). At very beginning of our Module1 let's make few imports:
Nice, now let's pass over to fundamental functions. I want to notice that I made my tool in NOT STANDARD way, invented by myself (I don't care if somebody made it before me, ALL OF THESE CODES were written only and only by me, without even internet connection while writing). It is a bit specific, but it works
Okay, firstly declare new string "Decision". Make new subs output & stext & input & info:
Now in main sub write Output() and (each new command goes on new line) console.title = "YOUR APP TITLE" and some introduction message. In my app:
Now after this we have to make sub Action() and put it after introductory part. I think the name of sub describes what it does
This means that action command will be repeated until decision string (full explanation a bit later - in short - it is the command user types in) is "exit". Now we can see that Action() uses two new susbs - let's add them.
Now you can see that string decision is the command the user types in. We are close to the end... Let's make the com() as this sub is still remaining undeclared.
This is the main part - user typed in the command -> it was written to string DECISION -> if decision = some specified command then something happens. Example:
If you want to add more codes, just add elseif struct to com() sub and voila. Finally at the end of main() sub add
You are done now! Try it, you will have a command-line app with your own commands, you can customize all my "settings" (colors, text, etc) to make your own app.
Full source code in spoiler
Thanks for reading, I guess the explanation was not the best one, but I'm porud to share this since I made the structure myself.
spoiler (Click to View)
First of all, we are making a console application in VB.NET (I was using 4.5 Framework, although all these commands will work on older versions either). At very beginning of our Module1 let's make few imports:
VB Code
- Imports Microsoft.Win32
- Imports System
- Imports System.IO
- Imports System.Runtime.CompilerServices
Nice, now let's pass over to fundamental functions. I want to notice that I made my tool in NOT STANDARD way, invented by myself (I don't care if somebody made it before me, ALL OF THESE CODES were written only and only by me, without even internet connection while writing). It is a bit specific, but it works
Okay, firstly declare new string "Decision". Make new subs output & stext & input & info:
VB Code
- Sub output()
- Console.ResetColor()
- End Sub
-
- Sub stext()
- Console.ForegroundColor = ConsoleColor.Red
- End Sub
-
- Sub input()
- Console.ForegroundColor = ConsoleColor.Yellow
- End Sub
-
- Sub info()
- Console.ForegroundColor = ConsoleColor.Green
- End Sub
Now in main sub write Output() and (each new command goes on new line) console.title = "YOUR APP TITLE" and some introduction message. In my app:
VB Code
- output()
- Console.Title = "PC Info - console version"
- Console.WriteLine("Welcome to PC Info. This application can be used in the same way as cmd. If you want to know something about your PC - type right code and hit ENTER. To see allavailable codes type HELP and hit ENTER.")
- Console.WriteLine()
- Console.Write("Notice that all commands have to be typed with ")
- stext()
- Console.Write("lower case letters.")
- Console.WriteLine()
- Console.WriteLine()
Now after this we have to make sub Action() and put it after introductory part. I think the name of sub describes what it does
VB Code
- Sub action()
- Do Until decision = "exit"
- say()
- com()
- Loop
- End Sub
This means that action command will be repeated until decision string (full explanation a bit later - in short - it is the command user types in) is "exit". Now we can see that Action() uses two new susbs - let's add them.
VB Code
- Sub say()
- output()
- Console.Write("User: ")
- input()
- decision = Console.ReadLine
- End Sub
Now you can see that string decision is the command the user types in. We are close to the end... Let's make the com() as this sub is still remaining undeclared.
VB Code
- Sub com()
- output()
- If decision = "<YOUR-COMMAND>" Then
- <YOUR CODE GOES HERE>
- End if
- End sub
This is the main part - user typed in the command -> it was written to string DECISION -> if decision = some specified command then something happens. Example:
VB Code
- Sub com()
- output()
- If decision = "help" Then
- <ALL-AVAILABLE-COMMANDS>
- End if
- End sub
If you want to add more codes, just add elseif struct to com() sub and voila. Finally at the end of main() sub add
VB Code
- action()
- If decision = "exit" Then
- End
- End If
You are done now! Try it, you will have a command-line app with your own commands, you can customize all my "settings" (colors, text, etc) to make your own app.
Full source code in spoiler
VB.NET Source (Click to View)