• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tutorial] Making command-line application
#1
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:
VB Code
  1. Imports Microsoft.Win32
  2. Imports System
  3. Imports System.IO
  4. 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 Tongue

Okay, firstly declare new string "Decision". Make new subs output & stext & input & info:
VB Code
  1. Sub output()
  2. Console.ResetColor()
  3. End Sub
  4.  
  5. Sub stext()
  6. Console.ForegroundColor = ConsoleColor.Red
  7. End Sub
  8.  
  9. Sub input()
  10. Console.ForegroundColor = ConsoleColor.Yellow
  11. End Sub
  12.  
  13. Sub info()
  14. Console.ForegroundColor = ConsoleColor.Green
  15. 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
  1. output()
  2. Console.Title = "PC Info - console version"
  3. 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.")
  4. Console.WriteLine()
  5. Console.Write("Notice that all commands have to be typed with ")
  6. stext()
  7. Console.Write("lower case letters.")
  8. Console.WriteLine()
  9. 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 Smile
VB Code
  1. Sub action()
  2. Do Until decision = "exit"
  3. say()
  4. com()
  5. Loop
  6. 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
  1. Sub say()
  2. output()
  3. Console.Write("User: ")
  4. input()
  5. decision = Console.ReadLine
  6. 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
  1. Sub com()
  2. output()
  3. If decision = "<YOUR-COMMAND>" Then
  4. <YOUR CODE GOES HERE>
  5. End if
  6. 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
  1. Sub com()
  2. output()
  3. If decision = "help" Then
  4. <ALL-AVAILABLE-COMMANDS>
  5. End if
  6. 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
  1. action()
  2. If decision = "exit" Then
  3. End
  4. 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)
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.
[Image: r212360a129ce9b84444093b6cd2699013a1fbn155.png]
  Reply
#2
RAAAGE
Fuu Fuu
Fuu Fuu
Fuu Fuu
C++/Obj-C developer. Neko engine wip
Steam: Click
  Reply
#3
Still can't get it. Practically everything that is possible with C# is possible with VB
[Image: r212360a129ce9b84444093b6cd2699013a1fbn155.png]
  Reply
#4
*insert bullshit about C# being better then VB.net here*
  Reply
#5
(04-16-2012, 16:44)JariZ Wrote: *insert bullshit about C# being better then VB.net here*

True dat...

Thanks Barata...
Don't worry if things aren't the way you planned, in the end everything will solve itself...
  Reply
#6
Nice tutorial you're beginners, good job
[Image: MaEIQ.png]
  Reply
#7
(04-16-2012, 16:44)JariZ Wrote: *insert bullshit about C# being better then VB.net here*

C++ pwns all!
  Reply
#8
[Image: MaEIQ.png]
  Reply
#9
(04-17-2012, 08:55)Pozzuh Wrote:

OLD!!!111
But like this ^_^
[Image: r212360a129ce9b84444093b6cd2699013a1fbn155.png]
  Reply
#10
(04-17-2012, 08:55)Pozzuh Wrote:

pop ebx
[Image: lQDUjba.jpg]
  Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Making an apocalyptic themed Minecraft map AZUMIKKEL 54 25,730 08-31-2013, 02:54
Last Post: AZUMIKKEL
  Help auto command Dynasty 6 3,977 08-26-2013, 16:05
Last Post: hillbilly
  Making a Heli's angles match my angles? akillj 1 2,446 06-16-2013, 15:01
Last Post: Yamato
  Making a harrier crash into the map? akillj 6 4,410 06-09-2013, 05:57
Last Post: akillj
Brick Lesson 3: Making game in C++ Nekochan 2 3,261 06-03-2013, 15:25
Last Post: Nekochan
  Making a gametype multi-rounded? DidUknowiPwn 6 4,157 04-22-2013, 22:14
Last Post: Pozzuh
Information [Tutorial] Making MORE glass in your form. Nekochan 27 10,849 03-22-2013, 22:04
Last Post: kokole
  !come command Dr3am95 12 6,979 02-12-2013, 12:08
Last Post: SgtLegend
Rainbow Lesson 1: Making game in C++ Nekochan 6 4,728 02-04-2013, 15:27
Last Post: Nekochan
Rainbow Lesson 2: Making game in C++ Nekochan 1 2,512 02-04-2013, 15:14
Last Post: Ich1994

Forum Jump:


Users browsing this thread: 2 Guest(s)