Page 1 of 1

Using a Console implmenting a console in VB6 Rate Topic: -----

#1 m2s87  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 21
  • View blog
  • Posts: 390
  • Joined: 28-November 06

Posted 05 January 2007 - 11:59 PM

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.

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.

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:
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:
Option Explicit
Public Sub Main(): If Con.Initialize = conLaunchExplorer Then Con.Visible = False
	Con.WriteLine "Hello world!"
End Sub

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.
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.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1