ABOUT VISUAL BASIC

Comparing Programming Languages

Friday December 2, 2011
Zach Hansen wrote into my blog about "VB versus Java". He said he had to write a paper for his high school programming class about the differences between computer languages.
To start with, "Thanks!!" -- For two things. Thanks for a great question and thanks for not trying to lie to me so I will do your homework. I get a lot of questions that seem to be clearly homework assignments. I'm much more likely to help if you're "up front" with your question ... like Zach!
First Question: Contrasting two programming languages.
You're really confronted with overchoice here! As early as 1969, Jean Sammet, who was then President of the Association for Computing Machinery (ACM), wrote a thick book that focused in on over 120 different programming languages. Since then, the situation has only become more complex. Wikipedia catalogs a list at:
List_of_programming_languages
And, "Yes!"  They are that different.
The differences really relate to bridging the gap between the human mind and a machine's total lack of any ability to actually reason. ("B" sci fi movies notwithstanding, computers can't reason!) Depending on the processor, machines can only do very elementary operations like shifting bits in a register one way or another or adding 1 to a register. (A "register" is a special part of memory that is wired by the manufacturer to do specific operations like that.) If you want to do something more complex, like say, "If A > B Then ... ", you need a "programming language" to turn this abstract thought into the primitive machine instructions computers are capable of.
The different programming languages attack this problem in different ways. Visual Basic's strength is it's all-purpose generality. It doesn't matter what kind of thought you have, it's possible to write code in Visual Basic to do it.
But many of the other languages are very strong in just one part of the problem. Take LaTeX, for example. This language is used pretty much exclusively for document markup and document preparation. In institutions of higher learning, like a university Computer Science department, LaTeX rules! This might be due in part to the fact that possibly the most brilliant mind in Computer Science in our time, Donald Knuth, wrote a book about LaTeX.
Second question: Game Programming Languages
When you think about the problem of writing the software for a game, it's primarily a question about how to deal with I/O devices and in particular, the monitor. If you can't paint images on a screen with crystal clear resolution and blinding speed, nobody will want to play your game.
VB.NET can be used for this (especially in combination with Microsoft's DirectX programming libraries), but it's far from being the best choice.
A really big production, like Call of Duty, will be supported by internally developed software tools. You won't be able to discover much information about these tools (which might be classified as programming languages themselves) because the companies that use them treat them as top-secret. These tools are a big reason why one game might be more 'kewl' than another.
These tools are sometimes coded directly in machine language. Machine language programming is probably the most labor intensive and expensive way possible to program a computer, but a big game maker has the money to do it. The programmers who can code in machine language are kept in locked dungeons and fed raw meat once a day. (Joke! Joke! - But there's still a grain of truth there. Most of the people I have met who can do this work well have ... ummmm .... "unique" personalities.) The rest of the system is often written in one of the continuing standards of the industry, C++.
Comparing C++ and VB might make a great paper for your class!
Hope this helps!

Fun and Games With Threading

Wednesday November 30, 2011
Threading is a technique that has an evil reputation because things can happen when you start using it that you just don't understand. But it really isn't all that hard.
A new article about Threading has just been added to the site that explains what it is and how to start using it. To illustrate the article, I used a program that I wrote to find all of the permutations of the elements in an array - mainly because I wanted something that involved a few more execution cycles than most example programs. But you might be interested in that too. The link is in the article.
Since I was investigating threading, I decided to poke into a few darker corners. For example:
  • What would happen if the same sub was executed directly and as a worker thread?
  • Can you adjust the priority of a worker thread to be higher than the thread that started it?
  • How do you pass multiple parameters to a worker thread?

Versions and Versions

Thursday November 24, 2011
When it was introduced, .NET provided an easy way to mark each version of your program with a "Major, Minor, Build, and Revision" number. But it seems that every good thing gets complicated and that has happened here too.
There are three things in .NET called version numbers now and they can all be different. And there are at least four places where you will see them. And there are different names for them, depending on where they appear.  This Quick Tip explains what they are and how they can effect your system.

The VB.NET Interface

Saturday November 12, 2011
... and I don't mean GUI!
Most articles you see about the important .NET Interface statement describe the syntax and architecture to get one to work. Few, however, tell you why you should use one. A new article is available that does tell you:
Interface Definitions and Why You Should Care
There's another little plus in the article about XML too. While I was writing this article, looked for good examples showing how to create a several levels of XML hierarchy in VB.NET. For example:
<Root>
  <Child1>
    <GC1>data</GC1>
    <GC2>data</GC2>
    <GC3>data</GC3>
  </Child1>
  <Child2>
    <GC1>data</GC1>
    <GC2>data</GC2>
    <GC3>data</GC3>
  </Child2>
</Root>
I found nothing at Microsoft showing exactly how to do this. (And nothing anywhere else too.) If you need an example of this type of code ... Here ya go!

Access VBA

Sunday November 6, 2011
Of all the Office applications, I find Access to be the most "unusual". It looks to me like a system that was put together by a negotiating committee. I would have liked to have been a fly on the wall listening to the designers argue about what would be in and what would be out.
On second thought, maybe not. I was in those rooms in my previous life and it wasn't fun.
There are two ways to do just about everything. For example, there are macros and there is VBA. And the word "macro" has a completely different meaning than it has in other Office applications like Word and Excel. In Word and Excel, a "macro" is a VBA program. In Access, it's a series of commands. (Much closer to the "computer science" definition of a macro.) There are even two types of macros - UI macros and data macros - which are entered in two different places in Access. I found macros to be totally confusing.
On the other hand, for the desktop at least (which is where Access seems to have the greatest value), Access macros can be translated into VBA using an Access utility. So you can get back to something that is more intelligible.
I wrote an article about VBA and Access years ago that has now become totally outdated. I have now updated that article! (Thanks to the prompting of Ralph, a student in an in-person class I was teaching.)
VBA - The Access Working Partner

Print Statement - This goes back to DOS!

Monday October 31, 2011
Did you know that there are two different Print statements you can use in VB.NET? The Print statement is something that was used a lot when Visual Basic and DOS were both being used, but today, not so much.
I actually didn't know much about them before I received an email asking about them. A new article on the page explains the two Print statements that you can use in VB.NET.
VB6 Compatible Printing

Testing Sender

Wednesday October 12, 2011
Pierre in Belgium wrote to me with an interesting question. "Sender does not seem to work as you can see with the small program I wrote especially for your guidance."
I have to say that it was really a pleasure to receive a clear, well documented question. Pierre's program was well done, easy to understand, and really told me exactly what his question was.
As it turns out, I wrote a Quick Tip about this a few years ago.
The SOOPercharged VB.NET sender and e Parameters
But my article didn't actually hit the precise point that was troubling Pierre. Thanks to Pierre, I'm going to revise it and make sure that it does.
Part of his program included this If-Then-Else structure:
Private Sub Bttn_IfThenElse_Click(
    ByVal sender As System.Object,
    ByVal e As System.EventArgs
    ) Handles Button1.Click, Button2.Click
    If sender Is Button1 Then
        TextBox1.Text = "greetings from Button1"
    ElseIf sender Is Button2 Then
        TextBox1.Text = "hello from Button2"
    End If
End Sub
The sender object and the Button1 object both exist so the Is operator is syntactically correct and there is no compile error. But let's check the documentation for Is to see why this doesn't work.
Visual Basic compares two object reference variables with the Is Operator. This operator determines if two reference variables refer to the same object instance.
Notice that sender is passed ByVal. That means that a copy of either Button1 or Button2 is passed, not the actual object itself. So when Pierre tests to see if sender and Button1 are the same instance, the result is False.
To test whether Button1 or Button2 has been clicked, you have to turn sender into an actual Button object and then test a property of that object. Text is usually used, but you could test a value in Tag or even the Location property.
This code works:
Dim myButton As Button
myButton = sender
If myButton.Text = "Button1" Then
    TextBox1.Text = "greetings from Button1"
ElseIf myButton.Text Is "Button2" Then
    TextBox1.Text = "hello from Button2"
End If
Thanks for the great question, Pierre!

TreeView Article Corrected

Monday October 10, 2011
In case anyone made their way completely through to page 3 of my recent article on programming the TreeView control in Windows forms, there was an error in it that has now been corrected. (So, if you didn't make it all the way through, you missed a golden opportunity to tell me how wrong and misinformed I am.)
The source of the error is interesting. Page 3 describes how to serialize and deserialize the contents of a TreeView to a binary file. I got the deserialize part right and the serialize part appeared to work too. (I do test my stuff. If it didn't get the right answer, I wouldn't have published it.) But the serialize part used unnecessary code.
In the serialize part, I included code that actually "walked the tree" to capture each node. That's unnecessary because the TreeNodeCollection itself is recursive. In effect, this tree "walks itself".
If that's totally confusing, read the article. If you're still confused, leave a reply to this blog and we'll work it out.

Programming a TreeView

Saturday October 8, 2011
An email from a reader asking a question about a bug in a program featuring TreeView started me thinking about it. So a completely new article is on the site showing how to use this interesting control. In the process, I learned a few more interesting things:
1 - > There are separate implementations of TreeView in all of Microsoft's technologies: Windows Forms, WPF, and ASP.NET. And they're quite different. (There's probably another one in Metro, but I'm not working with that yet.) Although this article focuses on Windows forms, I included code and illustrations of all of them in the article. Comparing them side by side fills in a few blanks for me about what Microsoft is doing to us!
2 - > It's amazing how complicated some sites on the web make this. Just wading through the misinformation and misunderstanding on the subject is a major effort.
3 - > The main thing that makes TreeView interesting is that recursion is part of the core implementation. If you want a great illustration of what recursion can do, this is it.
Programming a TreeView

If Then Else versus Select Case

Friday September 30, 2011
To VB.NET, it's all the same.
Beginners sometimes ask why there always seem to be several ways to do something in Visual Basic. "If Then Else" versus "Select Case" is a good example. I can't think of much of a reason to use one or the other except personal preference. (Can you?)
I promoted an old, outdated article that compared these to a Quick Tip article and while I was doing it, I decided to write a StopWatch comparison. Even at ten million random iterations of the coding example in the article, there only seemed to be a few hundred milliseconds of difference and it wasn't always in the same direction. I concluded that they were the same.
But just to be double sure, I checked ILDASM too. Sure enough, the code for both was almost identical.
The article has an illustration if you want to see it!
Is If Then Else or Select Case Better?
 

0 komentar:

Posting Komentar

ojo nulis sing aneh aneh yo cah xD

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Neora Chiaki SITE | Bloggerized by naokiakira.blogspot.com - Premium Blogger Themes | have been hacked by Neora Chiaki™