jep.jpg (13389 bytes)

Chaos Manor Special Reports

BASICS of Visual BASIC

Wednesday, September 26, 2001

Email Jerry

Sections

Chaos Manor Home

View From Chaos Manor

Reader Mail

Columns

Special Reports

Book &; Movie Reviews

Picture Gallery

Links

Table of Contents

What's New

The BYTE Fiasco

 

I got a great deal of mail about getting started with VBASIC if you had experience with the older variety. It's all pretty good, and together makes an intro to the subject that's worth preserving. This began with my lament that I used to write programs by opening and editor and writing a header and some structure and working top down, but Visual Basic presents me with forms and seems incomprehensible as to how I begin; I need examples.

This is not well organized but if you read through all of it you will learn some things worth knowing. Or I did.

Begin by going to this link.

 


 

 

Jerry

Apologies for the brevity or unclearness of the message but I was trying to give you an easy message to post in your mail page if you saw fit to do so.

Attached are the three examples.

The first two files jerrytest.vbp &; jerrytest.bas are the VB examples. You can open this in VB by saving them to a directory and doing the usual double click on the vbp file

The other two vbs files could be put anywhere (for example on the desktop). If you have the scripting host enabled (it is by default) then double clicking on each file will run the program. I hope your mail client prevents them from being opened directly otherwise you would be a very likely candidate for all sorts of virus mischief.

I hope this helps to get you started again with Visual Basic but I suspect that you will find like me that a clear scripting language (which I find VBScript to be) to be much more useful for simple tasks where you need more than a batch file but less than a C or VB or whatever program. I have no time for the loudmouth language or operating system bigots - most of them need to get a life and realize that we are trying to solve problems and get a job done, not invent new "solutions". The constant trade off that those of us with real jobs to do need to make is - can I get it done faster using a less efficient language I already know or should I invest the time to learn something new. As busy as you are I suspect the former.

On a more personal note, your column in the lamented Byte magazine got me started in this crazy world of technology and allows me to earn a very good living doing something I enjoy. I have read many of your works with much pleasure and even though I did not enjoy your last novel with Niven I still look forward to each work you release.

Do you have any plans to do a similar column to your now defunct and much missed "intellectual capital" columns?

I hope that the current turmoil at byte.com does not impact your entertaining weekly columns

Regards

Mike Howard ----- Original Message ----- From: Jerry Pournelle To: Michael A. Howard Sent: Wednesday, April 04, 2001 10:10 PM Subject: RE: Visual Basic Code Example

Where do you PUT it?

 

 

-----Original Message----- From: Michael A. Howard [mailto:mhoward@mahoward.com] Sent: Wednesday, April 04, 2001 1:44 PM To: jerryp@jerrypournelle.com Subject: Visual Basic Code Example

 

Jerry the code below does exactly what you wanted to see using the full blown VB IDE

 

'Follow good coding practice

Option Explicit

'define the variables Dim strHello As String Dim strWorld As String Dim strMessage As String

 

Sub Main()

'Set the values of the variables strHello = "Hello" strWorld = "World"

 

'concatenate and print strMessage = strHello &; " " &; strWorld MsgBox strMessage, vbOKOnly, "Jerry's Test Program"

 

End Sub

 

 

In VB Script the code is even simpler

 

'Jerry's Test Program in VBScript

 

'Note VBScript does not support data types Dim strHello Dim StrWorld Dim strMessage

 

'Set the values of the variables strHello = "Hello" StrWorld = "World"

 

'concatenate strMessage = strHello &; " " &; StrWorld MsgBox strMessage, vbOKOnly, "Jerry's Test Program"

 

Or if you wanted to be asked for the values...

 

'Jerry's Test Program in VBScript - Prompting for values

 

'Note VBScript does not support data types Dim strHello Dim strWorld Dim strMessage

 

'Set the values of the variables strHello = InputBox("First Variable") strWorld = InputBox("Second Variable")

 

'concatenate strMessage = strHello &; " " &; strWorld MsgBox strMessage, vbOKOnly, "Jerry's Test Program"

 

 

Easy once you know how.

In fact I am using VBScript more and more to do quick programming tasks that I used to use a spreadsheet model for.

 

Regards

 

 

Mike Howard


dyarker@leon.unimedya.net.tr

Been watching BASIC language discussion.

Take a look at Power Basic Console Compiler or DLL Compiler (also makes .exe). Both have some networking comands built in; and compile to stand-alone exe's, no run file like VBRUN.

I don't work for them. My first copy was called Turbo Basic (by Borland), then it was from Sectrum Publishing, now PowerBasic Inc.

URL is: http://www.powerbasic.com 

Hope that helps - Dale


Dear Jerry,

As per your Wednesday request for a VB example, here is a short one:

Open a new Project, in the Project Explorer: right click on "Form1 (Form1)", click on "Remove Form1", right click on "Project1 (Project1)", click on "Add", click on "Module", if the Add Module dialog box appears click the "Open" button. Set the Startup Object to "Sub Main" ("Project", click on "Project1 Properties"). To see the output of this example, the Immediate Windows must be open (View, Immediate Window).

-=-=-=-=-=-=-=- Code Snippet -=-=-=-=-=-=-=-

Option Explicit

Dim H As String Dim W As String

Sub main() H = "Hello " W = "World"

Debug.Print H &; W

End Sub

-=-=-=-=-=-=-=--=-=-=-=-=-=-=--=-=-=-=-=-=-=-

I have used this method to write several quick &; dirty data filter programs for customers. I then compile to .EXE and package them for installation with the Package &; Deployment Wizard.

John G. Ruff. J R u f f @ E x c i t e . c o m


Jerry,

I was just trying to answer your request, which was

I really need a couple of good examples of VB programs written WITHOUT using mouse and drag and click: that start with initialization block, declare 2 variables, load the string "Hello" into one, and the string "World" into a second, concatenate them, and print the results; as you would do in QBASIC but in Visual Basic without ever ever ever "opening a control" or if it is required then to have that control empty.

The point is that you don't need a control or a form to do that, as the two examples show. Is the question how to write a program WITH a form without using drag and drop? That's also possible.

Cheers, German

-----Original Message----- From: Jerry Pournelle [mailto:jerryp@jerrypournelle.com] Sent: Wednesday, April 04, 2001 10:10 PM To: German Rodriguez Subject: RE: Basic

It'\s the forms and their relationships I don't understand.

I know how to run a control program.

-----Original Message----- From: German Rodriguez [mailto:grodri@Princeton.EDU] Sent: Wednesday, April 04, 2001 5:31 PM To: jerryp@jerrypournelle.com Subject: Basic

Jerry,

Here are two answers to your request. Enjoy.

Cheers, German

' ---------------------------------------------------------------------

' [1] Visual Basic Scripting Edition

' Save as hello.vbs and run from command (a.k.a. DOS) window

'

dim var1, var2

var1 = "Hello"

var2 = "Jerry"

msg = var1 &; " " &; var2 ' separated with a space

wscript.echo msg

' ---------------------------------------------------------------------

 

' ---------------------------------------------------------------------

' [2] Visual Basic

' Save as hello.bas. Double click and the file should open in VB's IDE

' The project will have a single module, no forms and no controls.

' Run from there. Or compile, save, and then run from a command window

'

Sub Main

dim var1 as String, var2 as String

var1 = "Hello"

var2 = "Jerry"

msg = var1 &; " " &; var2

MsgBox msg

End Sub

' ---------------------------------------------------------------------

Jerry,

Thanks for replying. I benefit so much from your comments on computing

and other matters that I figured I'd contribute my two-cents worth

(maybe even do a silly thing or two so you don't have to). So let me

try again. If this doesn't work, I guess I'll just have to subscribe

to your site like everybody else :-)

With VB you can write code in a form, but you can also write code in

a *module*. That's the secret. It is also the answer to your question

how do I write a subroutine and then later call it

when I am on a different form?

The answer is write the code in a module. With VB you can do *almost*

exactly what you want, namely open an editor, write a program (without

a form!) and then run it. Let me show you how. I read in your site that

you had installed Visual Studio including Visual Basic 6.0, so fire

up VB 6.0

A dialog will pop up asking what type of program you want. Select

New, Standard Exe (the default) and click Open. You get a project with

a darned form. In the Project menu select Remove Form1. Presto, the

form is gone. Back in the Project menu select Add Module. A dialog

pops up, select New, Module (the default) and click on Open. Type your

code in Sub Main. For example type

Sub Main

MsgBox "Hello World"

End Sub

In the Run menu select Start. Your program is running. You can also

compile and save it. Except for having to delete the form, this sounds

like what you wanted to do. (You can also write the code in a file with

extension ".bas" and double click on it. Windows will start the VB IDE

and open an empty project with your module ... and no form!)

Why did this work? By default VB starts execution with Form1, but if

you delete the form it will look for a module. If you have a module

with a Sub called Main, as the toy example did, execution will start

there. In fact you can tell VB exactly where to start: go to the

Project menu, select Project1 Properties, and choose your Start Up

Object, which can be Sub Main or a form.

The one thing VB doesn't have is the equivalent of a console app,

that reads from standard input and writes to standard output, so you

could interact with the user in a DOS box a la QBasic. (In fact, you

*can* write a console app in VB, but this requires calling the Windows

API, see http://www.vb-world.net/articles/console/index6.html).

However, you can read from a file and write to another without ever

opening a form. And you can interact with the user via the MsgBox and

InputBox function, as in this example:

Sub Main()

Dim Age As String

Age = InputBox("How old are you?")

MsgBox Age &; "? I can't believe that"

End Sub

You can get rid of the "Project1" caption in these dialogs by adding

a Title argument (the second argument to InputBox and the third to

MsgBox). A nice feature of the IDE is that when you type the name of

a function and the left paren you get a ToolTip reminding you of the

arguments. Try editing the MsgBox line to read

MsgBox Age &; "? I can't believe that",,"Chaos Manor"

Now you have a program without those forms you hate. Have a nice weekend!

Cheers,

German

-----Original Message-----

From: Jerry Pournelle [mailto:jerryp@jerrypournelle.com]

Sent: Friday, April 06, 2001 1:41 PM

To: German Rodriguez

Subject: RE: Basic

 

I guess I am merely confused.

With BASIC you simply open an editor and write a program. You then compile

it. No "forms".

With VB a "form" opens. I know how to make things happen on that form, but I

don't know know to simply write a program with control logic that RUNS.

Interacting with the program is fine but suppose I need text only

interaction and I want it do DO something?

I fear the "forms" and "methods" confuse the holy hell out of me. And I

wonder if I am getting too old to learn.

I had no problems with Pascal, with BASCI, and hell even with C although I

hate it, but Visual Basic has left me wondering: how do I write a subroutine

and then later call it when I am on a different form? I hate forms.

-----Original Message-----

From: German Rodriguez [mailto:grodri@Princeton.EDU]

Sent: Thursday, April 05, 2001 9:12 AM

To: Jerry Pournelle

Subject: RE: Basic

Jerry,

I was just trying to answer your request, which was

I really need a couple of good examples of VB programs written WITHOUT using

mouse and drag and click: that start with initialization block, declare 2

variables, load the string "Hello" into one, and the string "World" into a

second, concatenate them, and print the results; as you would do in QBASIC

but in Visual Basic without ever ever ever "opening a control" or if it is

required then to have that control empty.

The point is that you don't need a control or a form to do that, as the two

examples show. Is the question how to write a program WITH a form without

using drag and drop? That's also possible.

Cheers,

German

-----Original Message-----

From: Jerry Pournelle [mailto:jerryp@jerrypournelle.com]

Sent: Wednesday, April 04, 2001 10:10 PM

To: German Rodriguez

Subject: RE: Basic

 

It'\s the forms and their relationships I don't understand.

I know how to run a control program.

-----Original Message-----

From: German Rodriguez [mailto:grodri@Princeton.EDU]

Sent: Wednesday, April 04, 2001 5:31 PM

To: jerryp@jerrypournelle.com

Subject: Basic

Jerry,

Here are two answers to your request. Enjoy.

Cheers,

German

' ---------------------------------------------------------------------

' [1] Visual Basic Scripting Edition

' Save as hello.vbs and run from command (a.k.a. DOS) window

'

dim var1, var2

var1 = "Hello"

var2 = "Jerry"

msg = var1 &; " " &; var2 ' separated with a space

wscript.echo msg

' ---------------------------------------------------------------------

 

' ---------------------------------------------------------------------

' [2] Visual Basic

' Save as hello.bas. Double click and the file should open in VB's IDE

' The project will have a single module, no forms and no controls.

' Run from there. Or compile, save, and then run from a command window

'

Sub Main

dim var1 as String, var2 as String

var1 = "Hello"

var2 = "Jerry"

msg = var1 &; " " &; var2

MsgBox msg

End Sub

' ---------------------------------------------------------------------

 

 

 


As currently reported Microsoft first made a conscious decision to break past Visual Basic work in the interests of making things more compatible across Visual Studio and the new C# initiative - and is now backing off. On the one hand I think Microsoft was right the first time to make the change (if not now when) and on the other hand I think Microsoft breaking things would be simply incompatible with a widely used lay person's language.

Interesting to look at the changes over time of the Advanced Placement Tests as an indicator for computer languages - going from teaching languages like Pascal to jumping into production languages in high school (granted the distinction here is somewhat artificial but the change is significant)

Microsoft scales back changes in VB.Net By Roberta Holland, eWEEK April 4, 2001 2:28 PM PT URL: http://www.zdnet.com/zdnn/stories/news/0,4586,2704915,00.html

Criticized by many among its base of developers, who felt that too much is being changed in the upcoming Visual Basic.Net, Microsoft Corp. today announced plans to scrap some of those changes and stick with the way VB has traditionally worked.

Microsoft officials said the changes, which are being made now and will be included in the Beta 2 version slated for release this summer, are based on developers' feedback.

"The goal of all these changes is to make developers' experience going from Visual Basic 6 to Visual Basic.Net much more seamless," said Ari Bixhorn, Microsoft's product manager for VB.Net, in Redmond, Wash.

The three biggest changes are as follows:

Visual Basic in the past had the value of the constant true as "negative 1." Microsoft changed that to "positive 1" for better consistency with other programming languages, Bixhorn said. But developers were more concerned with consistency with past versions of Visual Basic, he added.

In Visual Basic 6 and earlier versions, the Boolean operators "and" and "or" were both logical operators and bitwise operators. In the .Net version, Microsoft had scrapped the bitwise operator, which was used only in specific circumstances for graphics. But complaints led Microsoft to add it back in for the second beta.

The first two changes help maintain internal consistency within Visual Basic.Net.

Microsoft also scrapped a change to the declaration of an array of integers. In the current version of Visual Basic, DIM Arrayname(10) creates an 11-element array with numbered storage locations from Arrayname(0) through Arrayname(10). In the first beta of VB.Net, Microsoft changed the meaning of such a statement to define a 10-element array, with locations numbered from 0 through 9. The second beta will revert to the original syntax.

Bixhorn said that while this seems like a small change, it would have required a lot of coding to adapt.

"What we decided is, we can have seamless language interoperability and at the same time maintain consistency" with past versions of Visual Basic, he said.

For the estimated 3.5 million VB developers, "these changes are going to make their lives a lot easier," Bixhorn said. He added that the changes should not cause any delay in release of the second beta or in the first commercial release, which is scheduled for the end of the year.

Users persuade MS to retool Visual Studio.Net By Wylie Wong, News.com April 4, 2001 1:05 PM PT URL: Microsoft has gone back to the drawing board to retool its Visual Basic programming language in response to developer complaints over planned changes.

Microsoft has been developing a new version of its software development tools, called Visual Studio.Net, that will allow people to write and build Web-based software and services.

But in its first public test version of the tools released in November, software developers complained about three revisions to the Visual Basic language that changed the way programmers historically wrote their software.

Now Microsoft plans to undo those changes in its next public test version that will be released this summer.

The new suite of software development tools is part of Microsoft's new .Net strategy aimed at making Microsoft's Windows operating system and existing software available over the Web for traditional PCs and handheld devices. The package, expected by the end of this year, includes updates to programming languages Visual Basic, Visual C++, and the first version of C#, a new Java-like language intended to simplify the building of Web-based software and services using Microsoft software.

Microsoft has been sprucing up Visual Basic, a visual-oriented tool that will allow software developers to build Web software as easily as writing a Windows-only application.

Visual Basic, which has some 3.5 million users, revolutionized Windows development in 1991 because of its ease of use: Instead of writing all the software code by hand, programmers dragged and dropped pre-built software code on their computer screens.

Testers of the new version of Visual Basic didn't like three of the proposed changes to the language, however. The alterations were akin to changing the spelling or definition of words in the English language, for instance.

Microsoft executives said they originally made the Visual Basic changes to make the language work better with other development languages and to make the programming syntax more consistent with C++ and Java. Visual Basic programmers didn't like the modifications because it forced them to change the way they write programs, said Microsoft product manager Ari Bixhorn.

In the second test version of Visual Studio.Net, Microsoft has found a way to make different languages compatible, despite the fact that three of the language alterations have been changed back, he said.

"They were ecstatic with (most of) the new enhancements but it came down to these three changes that we heard over and over again," Bixhorn said. “We were looking for interoperability and consistency between languages. But the developer community told us it's more important to have consistency across all versions of Visual Basic."

Bixhorn said the company had planned to change the value of the programming word, "true", to make it uniform with the C++ and Java languages, revamping how collections of items, known in software lingo as "arrays", were defined, and a syntax tweak to the way "and" and "or" were used.

All three proposed changes will be scrapped, Bixhorn said.

"What's more important to developers is how they've historically done things," he said.

Clark ClarkEMyers@msn.com


Hi Jerry,

I too lament the lack of a good MS Basic development tool for Windows. Those old Microsoft Basics were great for developing quick and dirty utilities. Object-oriented languages confuse me, but I was good in those old Basic languages and some of the utilities I wrote even got a bit of a following, years ago.

I found myself needing to quickly write a short and simple utility again recently, and I really wanted to give it a GUI, so I went looking. I found a free cross-platform Basic language, with GUI hooks and everything, at http://www.basicguru.com/abc/rapidq/ . I downloaded it and looked at it, and maybe, just maybe, I can indeed program in Windows after all. All the old familiar Basic commands are there, and it manages to add GUI elements without the syntax looking too weird. File handling's quite a bit different, but even MS Basic differed depending on what platform you were on, so that's easy enough to adjust to.

Python looks interesting to me, but it's nice to have the option to use something you already know, isn't it? -- David L. Farquhar Author, Optimizing Windows for Games, Graphics and Multimedia (O'Reilly) Mail: dfarq@NOSPAMswbell.net (remove NOSPAM to reply) Web: http://theSiliconUnderground.editthispage.com

 

 

 

 

 

 

 

 

 

Entire contents copyright © 1998 by Jerry E. Pournelle. All rights reserved.