Program in Visual Basic .NET (VB.NET)

This is only a starting point for programming in Visual Basic.

Steps

  1. Download Visual Basic .NET 2005 edition from http://www.microsoft.com/express/. Once downloaded and installed, you are ready to start programming. First, you should understand that a computer cannot think and reason and that absolutely everything it does comes from a detailed list of instructions. It has to be told, even the smallest steps in great detail.
  2. Open Visual basic. You will see a window where you can choose different program types. Choose Windows application--It will be the one you will use most of the time.
  3. Learn the basic object types. You see a window within a gray window with a grid of black spots. This is your program platform. This is where you add different objects. The basic objects in Visual Basic (VB) are the button, the textbox, the editbox, the checkbox, and the label.
  4. Learn to place an object. On the left side of your screen you will see a toolbox with a lot of objects. Click on the one that says button. Then click on the gray window. The spot you click will be where your button is placed.
  5. Start (debug) your program now. Congratulations, you've just made your first program! When you click your button see what happens; absolutely nothing. Let's do something about that.
  6. Close your program.
  7. Back at the program platform double click the button. Now there is a displayed window a bit like a notepad. This where you tell the program what to do.
  8. At the place of the cursor write msgbox("hello world")
  9. Debug your program. Click the button. Now what happens? A new window is popping up saying hello world, and you just finished the first program in VB... this is the program all begin with.
  10. Lets write another program go to your program platform.
  11. Add a label. This label will be called label1 (as long as you are working on smaller programs it is alright but when you move up to more complicated programs with multiple labels buttons editboxes it is very difficult to remember which button does what). Single click on your label. In the right side of the screen there is a property window, in this there is one called text, this is where you define the text of the label, clear this one. Find the property called name, change this to lab_output that way you know that it is a label and that it gives you an output of some kind or at least it will.
  12. Go back to your program platform add 2 editboxes rename them (edit_a), (edit_b) and clear the text field, the boxes are the input of your program. Rename the button too and the text as well. Change the button to add.
  13. You probably now know we are making a program that can add 2 numbers. Let's gets started with the coding part. Double click the button delete the msgbox("hello world") and nothing else.
  14. Write lab_output.text = ("edit_a.text + edit_b,text").
  15. This will make the program add whatever stands in the editboxes.
  16. If the program is debugged now and you click the add button you get an error.
  17. In order to avoid the error, make use of an if/then else sentence which is where the program is asked if a statement is true if it is then it does something if not then it does something else.
  18. In the Code for the button be fore you write the lab.... You write if edit_a.text=("") or edit_b.text=("") then \newline msgbox("write something to add")\newline else \newline lab_output.text = ("edit_a.text + edis_b,text"). \newline end
  19. You made a program that can add 2 numbers. You can do the same with other mathematical operations, add new buttons for each operation on the platform, and you can make yourself a basic calculator.
  20. Now there is a little something because the edit_a.text is annoying to write all the time. You can define what is called a variable. At the very top of the coding window you have a sentence starting with private sub or something like that. Under this you write dim a,b as decimal. Other variables is string integer boolean, all these are in the help manual, for now the decimal is all you need.
  21. Underneath your dim write a=edit_a.text b= edit_b.text
  22. Go back down to your button code change the edit_a.text and edit_b.text to your newly defined variables a and b.
  23. Debug your program.

Tips

  • If you are stuck not knowing how to make something happen then you can try putting an object name and adding a . then a box will show the possible things you might write next. Search them; you never know what you might find.
  • The best way to start is to use tutorials.
  • BASIC (and of course the VB variants) is a relatively easy language to learn and get used to. But with this simplicity comes a high-level language. This means you cannot gain access to the system core with your code. If you need this access, try C or Assembly.
  • Have a basic understanding of boolean operators, variables, if/then statements, loops, and exit/goto statements. It would also help if you had knowledge of programming in general and also how the computer works.
  • Unlike in some other languages, capitalization is not a real problem (but the built-in editor usually tries to clean up syntax).
  • Finding general simple code methods like if then else statements helps to keep you motivated.
  • Trying to make an advanced program is not a good first time program idea. Instead do simpler things like Hello World programs until you can handle more complicated VB elements.
  • Check your code for formatting errors and typos. Eventually, you will miss a typo in your code and spend a long time trying to find it.
  • Go slowly and take your time.

Warnings

  • Don't make too many errors that are so hard to find it takes forever to do so.
  • Visual Basic is not designed for graphic intensive games; use a language like Java or Flash if that is what you want to make.
  • Visual Basic .NET is almost nothing like its older VB6 and VB5 counterparts.

Things You'll Need

  • A computer
  • Internet (for help)
  • Visual Basic .NET (the program)

Related Articles