Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tutorial Making command-line application
04-16-2012, 16:12
Post: #1
Making command-line application
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.
Related links

[Image: r212360a129ce9b84444093b6cd2699013a1fbn155.png]
Visit this user's website Find all posts by this user
Add Thank You Quote this message in a reply
[-] The following 1 user says Thank You to Arteq for this post:
JariZ (04-16-2012)
04-16-2012, 16:17 (This post was last modified: 04-16-2012 16:18 by SailorMoon.)
Post: #2
RE: Making command-line application
RAAAGE
Fuu Fuu
Fuu Fuu
Fuu Fuu

Steam: jaydi2112
[Image: userbar7q.gif]
[Image: 45296.png]
[Image: 3OM7E.gif]
Visit this user's website Find all posts by this user
Add Thank You Quote this message in a reply
04-16-2012, 16:33
Post: #3
RE: Making command-line application
Still can't get it. Practically everything that is possible with C# is possible with VB

[Image: r212360a129ce9b84444093b6cd2699013a1fbn155.png]
Visit this user's website Find all posts by this user
Add Thank You Quote this message in a reply
04-16-2012, 16:44
Post: #4
RE: Making command-line application
*insert bullshit about C# being better then VB.net here*
Related links

[Image: k5sVYyb.gif]
Visit this user's website Find all posts by this user
Add Thank You Quote this message in a reply
[-] The following 2 users say Thank You to JariZ for this post:
barata (04-16-2012), SailorMoon (04-16-2012)
04-16-2012, 18:29
Post: #5
RE: Making command-line application
(04-16-2012 16:44)JariZ Wrote:  *insert bullshit about C# being better then VB.net here*

True dat...

Thanks Barata...

[Image: 206852_10151457380881709_89654475_n.jpg]

We don't have public education, public hospitals, security neither justice, but we do have money to spend with a world cup, shame on you Brazil!
Find all posts by this user
Add Thank You Quote this message in a reply
04-16-2012, 21:02
Post: #6
RE: Making command-line application
Nice tutorial you're beginners, good job

[Image: MaEIQ.png]
Find all posts by this user
Add Thank You Quote this message in a reply
04-17-2012, 08:40
Post: #7
RE: Making command-line application
(04-16-2012 16:44)JariZ Wrote:  *insert bullshit about C# being better then VB.net here*

C++ pwns all!
Find all posts by this user
Add Thank You Quote this message in a reply
04-17-2012, 08:55
Post: #8
RE: Making command-line application


Related links

[Image: MaEIQ.png]
Find all posts by this user
Add Thank You Quote this message in a reply
[-] The following 1 user says Thank You to Pozzuh for this post:
Arteq (04-17-2012)
04-17-2012, 10:40
Post: #9
RE: Making command-line application
(04-17-2012 08:55)Pozzuh Wrote:  

OLD!!!111
But like this ^_^

[Image: r212360a129ce9b84444093b6cd2699013a1fbn155.png]
Visit this user's website Find all posts by this user
Add Thank You Quote this message in a reply
04-17-2012, 13:35
Post: #10
RE: Making command-line application
(04-17-2012 08:55)Pozzuh Wrote:  

pop ebx

(11-25-2012 14:44)kokole Wrote:  Scammer or not, that's why I never buy from people.
Visit this user's website Find all posts by this user
Add Thank You Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  [Tutorial] Making A Simple Calculator! Ivankec 4 3,661 12-14-2012 19:22
Last Post: Gam3rr0rZ

Forum Jump:


User(s) browsing this thread: 1 Guest(s)
Media Embeding by Simple Audio Video Embeder