>> I challenge you to make a dos prompt say "Hello World" with Visual Basic. You can't. <<
Challenge accepted.
Code:
Option Explicit
Private Const STD_OUTPUT_HANDLE = -11&
Private Declare Function AllocConsole Lib "kernel32" () As Long
Private Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Long) As Long
Private Declare Function WriteConsole Lib "kernel32" Alias "WriteConsoleA" ( _
ByVal hConsoleOutput As Long, ByVal lpBuffer As String, ByVal nNumberOfCharsToWrite As Long, _
lpNumberOfCharsWritten As Long, lpReserved As Any) As Long
Sub PrintConsole(sOut As String)
Dim hStdOut As Long, cWritten As Long
AllocConsole
hStdOut = GetStdHandle(STD_OUTPUT_HANDLE)
If (WriteConsole(hStdOut, sOut, Len(sOut), cWritten, ByVal 0&) = 0) Then _
Err.Raise 1
End Sub
Sub main()
PrintConsole "Hello World!" & vbCrLf
PrintConsole "The time is " & Time & vbCrLf
PrintConsole "The date is " & Date & vbCrLf
PrintConsole "The date in 100,000 minutes will be " & DateAdd("n", 100000, Now)
End Sub
More VB Console Examples
>> By the way, I'm still in my first year of VB, is it usable for web applications? I've never really been clear on that.. Just asking. <<
Yes. VBScript is the language of choice for ASP classic. VB.NET is one language that can be used for ASP.NET.
>> C++ has a much wider range. <<
I totally disagree. VB is in common use for scripting (VBScript), CGI scripts (VBScript or VB.NET), executable programs (VB), .NET interpreted programs (VB.NET) and macros (VBA for Word, Excel, Wordperfect, Access etc). C++ is in common usage only for executable programs.
>> there are still many things that you HAVE to use C++ for. <<
There are still some things you have to use plain C or even assembly for. Does that lessen the value of C++?
>> It's too basic to be of use to more than 10% of programmers. <<
I would lay a small bet that there is as many programmers making money from writing in VB as their is from writing in C++. It is certainly a useful language for windows programmers to know. It is a common misunderstading that VB is too simple to do many things. This is wrong. VB can do just about anything that a standard executable can do that is written in any other language.
Have a look at what vbAccelerator does with VB and then call it simple. I challenge you to implement any one of those things in C++.
There are some drawbacks to VB, but to claim that it is not a useful language is simply false. As C/C++ programmers we look at VB program with an air of superiority. The user on the other hand, looks at a working, quickly implemented program, that crashes less often and costs them half the price.