Welcome to Dream.In.Code
Getting Help is Easy!

Join 118,921 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,997 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Using a Console

 
Reply to this topicStart new topic

> Using a Console, implmenting a console in VB6

m2s87
Group Icon



post 5 Jan, 2007 - 11:59 PM
Post #1


[Intro]
VB 6 lacks on 1 important thing and that a console. So every time you need a simple program to give output or receive input, you need to create tools for that. As creating objects and event driven code is not a difficult thing in vb, one might forget that creating it all by code, will produce something that is not easy to read.

[Why]
So what is so different between C and VB 6? - a lot. But this tutorial tries to fill one huge gap, that novice programmers would find. This tutorial teaches how to use console as they are used in C.

[How]
Well we need a console, something that did not came with vb 6, so we need to write it. As writing 1 is not to difficult, many could do it, but probably it would be lacking some functionality or would not be powerful as it is in C.

So knowing the fact, that +95% of code you ever write, is already written by someone in some form, would make you think:"Has someone ever thought of this problem before me, and was the problem solved?". In this case, it has been solved - look on this web page; and download the VB console written by Karl E. Peterson.

Now you have the console written for you (file:MConsole.bas), and you can start using it. One could write his(/hers) own console, but this is quite impressive by itself.

[Hello world]
1) Start VB 6, make new standard exe.
As to show we are not using other means, then just code, remove the form IDE builder. (Project->remove form1)
2) Add a module (Project->add module)
Note that now there must be a Main() procedure in module, and when you run a program, the programs lifetime is determined by the lifetime of the main() procedure.
Sample program of Hello World would now look like:
CODE
Sub Main()
    MsgBox ("Hello World")
End Sub

Now lets try to do this on console
3) Add an existing module MConsole.bas to the project. (Project->add module->existing module:navigate and choose MConsole.bas from the zipped file)
4) Now you need to initialize the console, so 1 why to do this is:
CODE
Option Explicit
Public Sub Main(): If Con.Initialize = conLaunchExplorer Then Con.Visible = False
    Con.WriteLine "Hello world!"
End Sub


[c2vb]
Now when you understand how to create simplest console program, learn some simple things like input Data = Con.Readline() or something like that.

Write a code that asks users - name and year of bright and would greet him and calculate something about his age.
CODE
Option Explicit
Public Sub Main(): If Con.Initialize = conLaunchExplorer Then Con.Visible = False
    Dim Data1 As String, Data2 As Integer
        
    Con.WriteLine "What is your name?"
    Data1 = Con.ReadLine
    
    Con.WriteLine "On which year where you born?"
    Data2 = Con.ReadLine
    
    Con.WriteLine "Hello " & Data1 & " i am CPU. You are " & _
                  IIf(2007 - Data2 < 19, "a kid.", "eligable to drink vodka.")
End Sub


Now if you think that is simple, translate some C snippets to vb.
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 10/13/08 04:46AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month