Introduction to Visual Basic tutorials
|
|---|
Basic Calculator
In this tutorial we will learn to create a basic calculator in Visual Basic.
| | Hits:1102 Rate: 4.0(out of 5) Vote:3 Submit Date :2006-03-27 Rate It | Error | Review |
|
| | | |
|---|
Managing INI files
How to create, read and write an INI file from Visual Basic 6
Hello y'all. It's a long time that in the italian VB newsgroups periodically appears a thread asking how we can write and read the INI files. I always post the same solution: two little functions of mine, that belong from a code I found somewhere in andreavb.com.
My answer is always the same - and often they give me the same grateful reply - but threads expire after some time in newsgroups, so I'm afraid one of these days I can't post anymore the bare tinyurl link to the thread I spoke into, and I have to write another explanation of the whole stuff.
So I decided to post this article here: to put my functions and explanations in a not-expiring place. If one day my previous threads will be lost, I will tinyurl the link to this page (and then, my italian friends would be better start speaking english, ehehehe).
So, in order to create, read and write an INI file, copy the two routines below in a module.
Things to know:
- INI files are made of sections, which names are enclosed in square brackets into the file (you could open one by the Notepad.exe to see how it is made), and several keys for each sections. Take note that there is no space before equal sign of the key, nor after it: the format is KeyName=Value. In the routines below you have to specify the section, and the name of the key to read/edit in that section.
| | Hits:921 Rate: 1.0(out of 5) Vote:1 Submit Date :2006-03-27 Rate It | Error | Review |
|
| | | |
|---|
Pad Program: Beginners Guide
Create a well functioning pad program in Visual Basic, a beginners guide.
Pad Program
Although we are going to create a pad program, its only going to have basic functions and not go to advanced. This is aimed towards beginners who still haven't grasped many concepts of what visual basic is all about, so lets get started.
First open visual basic (i'm using visual basic 6.0, some things might vary). If the 'New Project' Window doesn't open automatically, click File - New Project. We are going to create a Standard EXE. Most of the time that is the project you want to create.
Here we get to work on our window (obviously). Windows are called forms when working with VB.
If you look to the right of the program, you see different panels. The project panel is where we can view/add/delete all our different forms, or modules or anything of the sort (dont bother with this yet).
Below that panel you see the properties panel. This is what we are about to edit in a moment.The drop down list shows you all the forms or objects you can work with. And everything inside the scrollable area are properties you can edit.
Right now you need to change the form name to "frmScudpad". Then look a little lower and change caption to "Scudpad"
If you noticed the name, it had a prefix of 'frm'. It's just commmon practice to give names their respectable object type prefix. But you'll learn more of that as you proceed.
Moving on, you can stretch your form outwards by clicking the small 'boxes' on the sides of the form and dragging outwards. Go ahead, make the form you're working on right now a bit bigger.
We're going to add a Menu bar. To do this, right click anywhere on your form (even the whitespace counts) and choose 'Menu Editor'
First Menu We are going to create is going to be File. So add 'File' to the caption. The prefix for a menu is mnu, so in the name field add 'mnuFile'.
When you do that, click the Next button. This time, we want to add a menu item to the main menu: file. So after pressing the next button, click the arrow pointing right. You should notice three dots appear. This means that the item will be a sub of whater is on top of it.
First item we are going to put in here will be an Exit option. So for the caption, type Exit. For the name, type mnuFileitemExit (mnuFile because it's under the menu file, and item Exit because its a menu item named exit).
We need to create another item under the file menu. So you should still have your 'exit' item seleted. If not, just click on it. Then press the insert button. This creates another item with the same parent of the item below it.
Now create another item with the caption 'New' and the name 'mnuFileitemNew'. But this time also insert a hotkey (from the drop down list. Common sense is you should use ctrl + n with the New item.
Don't worry if you didn't get the hang of it, you get a lot of opportunity for remembrance right now. You need to create a menu that has the following items. Remember though, menu's have names of mnu*menucaption* and menu items have names of mnu*menucaption*item*itemcaption*. You can also use the up/down arrows to arrange the positions (don't forget hotkeys).
Once you got all that done press OK. Then you would probably want to preview it. To do this, just look at the toolbar and press the play button, or you could also press F5. It should look similair to mine:
If you click any item in the menu, nothing happens. Well thats because we haven't defined any code to tell our program what to do on a click. More on that later on. Right now we need to get an area where text can be shown. Close the preview by closing the form or pressing the stop button.
Look to the left of the program, you see our tools box. These are all objects you can insert into your form.
For now, the only one we are going to add is the textbox (the white field with 'ab' in it). To add it, just double-click the button. A text field should be added to the form.
Now you should expand the textfield to fit the form (although it doesn't matter because we will change how it sizes itself later). You should change it right now so it will look more or less like the final product (you might need to slightly resize the form as well).
Once you do that, click on the text field to modify its properties. We need to name this text field txtPad (txt is the prefix for textfields). When you change the name scroll down and find the 'Text' property, empty that property so no text is displayed.
To make the text field resize itself to fit the window, right click on the form (an empty area) and choose 'View Code'. This is where we can edit the BASIC code. But first we need to declare WHEN to take an action. So when you open the code window, you see two comboboxes. The first lets you choose an object in our project to edit. The 2nd combobox gives you options on WHEN to take an action. So Choose
| | Hits:685 Rate: 2.0(out of 5) Vote:2 Submit Date :2006-03-27 Rate It | Error | Review |
|
| | | |
|---|
Creating a Clock
Dispay the current time in your VB app.
in this tutorial we will together code a application that shows the current time
| | Hits:684 Rate: 5.0(out of 5) Vote:1 Submit Date :2006-03-27 Rate It | Error | Review |
|
| | | |
|---|
Key trapping
How do you tell what keys your users are pressing? This tutorial teaches you a rock solid method that you can build in games and advanced applications.
This is extremely easy. Firstly open a new form, or the form that you would like to catch the key presses on.
We can then declare a new procedure:
Code
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'space for your code
End Sub
Now this is the only tricky bit, (if you have no understanding of computers what-so-ever). When you press the letter "d" on the keyboard, you are not sending "d" to the comptuer, you are sending a number. Every key on your keyboard has it own, unique, number.
So if I wanted to find out what the key of anything is, I made a form that would tell me. Whenever I pressed a key, it would set the .text property of a disabled input field to the keycode value.
| | Hits:576 Rate: 4.0(out of 5) Vote:1 Submit Date :2006-03-27 Rate It | Error | Review |
|
| | | |
|---|
URL linked Label
Create a hyperlinked label in your Visual Basic application that will open up in a new browser window.
| | Hits:496 Rate: 0.0(out of 5) Vote:0 Submit Date :2006-03-27 Rate It | Error | Review |
|
| | | |
|---|
The Basics of Visual Basic
A great tutorial for people that are starting out with visual basic and need to get a rock solid start. Described are loops, conditionals and variables.
Okay, Visual Basic.. what an application. Its so simple to get programs up and running (usually a point, click, drag, type and run =D).
Variables
Variables in VB are declared with the dimension keyword..
Code
Dim variable_name as string
..also you will notice that after the "Dim", then the name there is an "as string" statement. This means that the variable that I declared is of variable type string. This is basically some text. Some other variable types include integer, double, currency, boolean, etc.
Conditionals
The IF statement can help you tell if the a value is equal to something, or not.
| | Hits:421 Rate: 0.0(out of 5) Vote:0 Submit Date :2006-03-27 Rate It | Error | Review |
|
| | | |
|---|
[Part 2] Working WIth Textboxes & Strings
This is the 2nd part of the tutorial that will teach you how to use textboxes and strings to make your applications more interactive.
OK now that we have created the first form and the module we just have to code it too make the text in the textbox that the user enters appear on a new form when the command button is pressed.
Now go to the code view ( click on View and then Code ) and then enter this code
| | Hits:386 Rate: 0.0(out of 5) Vote:0 Submit Date :2006-03-27 Rate It | Error | Review |
|
| | | |
|---|
Display input in a Label
In this tutorial we will code a application to display anything you type into a textbox on to a label.
In this tutorial we will thogether code a application to display anything you type into a textbox on to a label
| | Hits:363 Rate: 0.0(out of 5) Vote:0 Submit Date :2006-03-27 Rate It | Error | Review |
|
| | | |
|---|
A Programmer's Guide to Visual Basic.NET
This free ebook is meant to give you a head start on the changes from Visual Basic to Visual Basic.NET (VB.NET). Most of the book assumes that you are comfortable with Visual Basic 6.0 (VB6), so the book endeavors to be a quick introduction to the major differences between VB6 and the new VB.NET.
Summary: This book is meant to give you a head start on the changes from Visual Basic to Visual Basic.NET (VB.NET). Most of the book assumes that you are comfortable with Visual Basic 6.0 (VB6), so the book endeavors to be a quick introduction to the major differences between VB6 and the new VB.NET.
Submit Date: 1/7/2004
| | Hits:201 Rate: 0.0(out of 5) Vote:0 Submit Date :2006-03-27 Rate It | Error | Review |
|
| | | |
|
|---|
Pad Program: Beginners Guide
Create a well functioning pad program in Visual Basic, a beginners guide.
Pad Program
Although we are going to create a pad program, its only going to have basic functions and not go to advanced. This is aimed towards beginners who still haven't grasped many concepts of what visual basic is all about, so lets get started.
First open visual basic (i'm using visual basic 6.0, some things might vary). If the 'New Project' Window doesn't open automatically, click File - New Project. We are going to create a Standard EXE. Most of the time that is the project you want to create.
Here we get to work on our window (obviously). Windows are called forms when working with VB.
If you look to the right of the program, you see different panels. The project panel is where we can view/add/delete all our different forms, or modules or anything of the sort (dont bother with this yet).
Below that panel you see the properties panel. This is what we are about to edit in a moment.The drop down list shows you all the forms or objects you can work with. And everything inside the scrollable area are properties you can edit.
Right now you need to change the form name to "frmScudpad". Then look a little lower and change caption to "Scudpad"
If you noticed the name, it had a prefix of 'frm'. It's just commmon practice to give names their respectable object type prefix. But you'll learn more of that as you proceed.
Moving on, you can stretch your form outwards by clicking the small 'boxes' on the sides of the form and dragging outwards. Go ahead, make the form you're working on right now a bit bigger.
We're going to add a Menu bar. To do this, right click anywhere on your form (even the whitespace counts) and choose 'Menu Editor'
First Menu We are going to create is going to be File. So add 'File' to the caption. The prefix for a menu is mnu, so in the name field add 'mnuFile'.
When you do that, click the Next button. This time, we want to add a menu item to the main menu: file. So after pressing the next button, click the arrow pointing right. You should notice three dots appear. This means that the item will be a sub of whater is on top of it.
First item we are going to put in here will be an Exit option. So for the caption, type Exit. For the name, type mnuFileitemExit (mnuFile because it's under the menu file, and item Exit because its a menu item named exit).
We need to create another item under the file menu. So you should still have your 'exit' item seleted. If not, just click on it. Then press the insert button. This creates another item with the same parent of the item below it.
Now create another item with the caption 'New' and the name 'mnuFileitemNew'. But this time also insert a hotkey (from the drop down list. Common sense is you should use ctrl + n with the New item.
Don't worry if you didn't get the hang of it, you get a lot of opportunity for remembrance right now. You need to create a menu that has the following items. Remember though, menu's have names of mnu*menucaption* and menu items have names of mnu*menucaption*item*itemcaption*. You can also use the up/down arrows to arrange the positions (don't forget hotkeys).
Once you got all that done press OK. Then you would probably want to preview it. To do this, just look at the toolbar and press the play button, or you could also press F5. It should look similair to mine:
If you click any item in the menu, nothing happens. Well thats because we haven't defined any code to tell our program what to do on a click. More on that later on. Right now we need to get an area where text can be shown. Close the preview by closing the form or pressing the stop button.
Look to the left of the program, you see our tools box. These are all objects you can insert into your form.
For now, the only one we are going to add is the textbox (the white field with 'ab' in it). To add it, just double-click the button. A text field should be added to the form.
Now you should expand the textfield to fit the form (although it doesn't matter because we will change how it sizes itself later). You should change it right now so it will look more or less like the final product (you might need to slightly resize the form as well).
Once you do that, click on the text field to modify its properties. We need to name this text field txtPad (txt is the prefix for textfields). When you change the name scroll down and find the 'Text' property, empty that property so no text is displayed.
To make the text field resize itself to fit the window, right click on the form (an empty area) and choose 'View Code'. This is where we can edit the BASIC code. But first we need to declare WHEN to take an action. So when you open the code window, you see two comboboxes. The first lets you choose an object in our project to edit. The 2nd combobox gives you options on WHEN to take an action. So Choose
| | Hits:685 Rate: 2.0(out of 5) Vote:2 Submit Date :2006-03-27 Rate It | Error | Review |
|
|
|---|
Key trapping
How do you tell what keys your users are pressing? This tutorial teaches you a rock solid method that you can build in games and advanced applications.
This is extremely easy. Firstly open a new form, or the form that you would like to catch the key presses on.
We can then declare a new procedure:
Code
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'space for your code
End Sub
Now this is the only tricky bit, (if you have no understanding of computers what-so-ever). When you press the letter "d" on the keyboard, you are not sending "d" to the comptuer, you are sending a number. Every key on your keyboard has it own, unique, number.
So if I wanted to find out what the key of anything is, I made a form that would tell me. Whenever I pressed a key, it would set the .text property of a disabled input field to the keycode value.
| | Hits:576 Rate: 4.0(out of 5) Vote:1 Submit Date :2006-03-27 Rate It | Error | Review |
|
|
|---|
The Basics of Visual Basic
A great tutorial for people that are starting out with visual basic and need to get a rock solid start. Described are loops, conditionals and variables.
Okay, Visual Basic.. what an application. Its so simple to get programs up and running (usually a point, click, drag, type and run =D).
Variables
Variables in VB are declared with the dimension keyword..
Code
Dim variable_name as string
..also you will notice that after the "Dim", then the name there is an "as string" statement. This means that the variable that I declared is of variable type string. This is basically some text. Some other variable types include integer, double, currency, boolean, etc.
Conditionals
The IF statement can help you tell if the a value is equal to something, or not.
| | Hits:421 Rate: 0.0(out of 5) Vote:0 Submit Date :2006-03-27 Rate It | Error | Review |
|
|
|---|
Managing INI files
How to create, read and write an INI file from Visual Basic 6
Hello y'all. It's a long time that in the italian VB newsgroups periodically appears a thread asking how we can write and read the INI files. I always post the same solution: two little functions of mine, that belong from a code I found somewhere in andreavb.com.
My answer is always the same - and often they give me the same grateful reply - but threads expire after some time in newsgroups, so I'm afraid one of these days I can't post anymore the bare tinyurl link to the thread I spoke into, and I have to write another explanation of the whole stuff.
So I decided to post this article here: to put my functions and explanations in a not-expiring place. If one day my previous threads will be lost, I will tinyurl the link to this page (and then, my italian friends would be better start speaking english, ehehehe).
So, in order to create, read and write an INI file, copy the two routines below in a module.
Things to know:
- INI files are made of sections, which names are enclosed in square brackets into the file (you could open one by the Notepad.exe to see how it is made), and several keys for each sections. Take note that there is no space before equal sign of the key, nor after it: the format is KeyName=Value. In the routines below you have to specify the section, and the name of the key to read/edit in that section.
| | Hits:921 Rate: 1.0(out of 5) Vote:1 Submit Date :2006-03-27 Rate It | Error | Review |
|
|
|---|
Creating a Clock
Dispay the current time in your VB app.
in this tutorial we will together code a application that shows the current time
| | Hits:684 Rate: 5.0(out of 5) Vote:1 Submit Date :2006-03-27 Rate It | Error | Review |
|
|
|---|
URL linked Label
Create a hyperlinked label in your Visual Basic application that will open up in a new browser window.
| | Hits:496 Rate: 0.0(out of 5) Vote:0 Submit Date :2006-03-27 Rate It | Error | Review |
|
|
|---|
Basic Calculator
In this tutorial we will learn to create a basic calculator in Visual Basic.
| | Hits:1102 Rate: 4.0(out of 5) Vote:3 Submit Date :2006-03-27 Rate It | Error | Review |
|
|
|---|
Display input in a Label
In this tutorial we will code a application to display anything you type into a textbox on to a label.
In this tutorial we will thogether code a application to display anything you type into a textbox on to a label
| | Hits:363 Rate: 0.0(out of 5) Vote:0 Submit Date :2006-03-27 Rate It | Error | Review |
|
|
|---|
[Part 2] Working WIth Textboxes & Strings
This is the 2nd part of the tutorial that will teach you how to use textboxes and strings to make your applications more interactive.
OK now that we have created the first form and the module we just have to code it too make the text in the textbox that the user enters appear on a new form when the command button is pressed.
Now go to the code view ( click on View and then Code ) and then enter this code
| | Hits:386 Rate: 0.0(out of 5) Vote:0 Submit Date :2006-03-27 Rate It | Error | Review |
|
|
|---|
A Programmer's Guide to Visual Basic.NET
This free ebook is meant to give you a head start on the changes from Visual Basic to Visual Basic.NET (VB.NET). Most of the book assumes that you are comfortable with Visual Basic 6.0 (VB6), so the book endeavors to be a quick introduction to the major differences between VB6 and the new VB.NET.
Summary: This book is meant to give you a head start on the changes from Visual Basic to Visual Basic.NET (VB.NET). Most of the book assumes that you are comfortable with Visual Basic 6.0 (VB6), so the book endeavors to be a quick introduction to the major differences between VB6 and the new VB.NET.
Submit Date: 1/7/2004
| | Hits:201 Rate: 0.0(out of 5) Vote:0 Submit Date :2006-03-27 Rate It | Error | Review |
|
|
WebmastersHome.com Discussion about programming, SEO, WebHosting and more! |
|