• Welcome to Valhalla Legends Archive.
 

Paying to be teached VB

Started by Vaughn, March 27, 2005, 07:13 PM

Previous topic - Next topic

Yegg


Psycho

Thanks, Grok.

Vaughn, do you have Visual Basic 6 on your computer? If you don't I can get a you a copy of it.

Psycho

Vaughn, I've looked a few places and I've found a few good links to help you learn VB.

http://www.vbtutor.net/vbtutor.html
http://www.freeprogrammingresources.com/vbtutor.html

If I see anymore I'll let you know.

Yegg

I don't think he'll have trouble finding a copy of Visual Basic 6 [Enterprise]. Nevermind the file sharing softwares but many of the Battle.net related sites also have it in their downloads section.

MyndFyre

Quote from: Yegg on April 28, 2005, 02:34 PM
I don't think he'll have trouble finding a copy of Visual Basic 6 [Enterprise]. Nevermind the file sharing softwares but many of the Battle.net related sites also have it in their downloads section.

Not that that technique is legal or anything...
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Mangix

IMHO, VB is easy if you know All the Objects and Properties, and syntax. i know most of the syntax(from VBScript) and about 1/100 from the objects.

btw, nice place to get very l33t and pirated .pdf eBooks is from our very own hdx :P. ftp://hdx.no-ip.org/myEbooks/

Psycho

Author:
Psycho

Description:
Tutorial

Requirments:
Visual Basic 6

Below is a few simple methods of the basics to using Visual Basic 6. Please note that the information may be wrong, or different to your methods. But this tutorial shows the basics, and gives the user an understanding to using Visual Basic.

Getting Started

The most important thing with any program, especially programs with more features is to familiarise yourself with its interface. You should look around the program at all its options it has to offer you, and customise it to suit your needs and preferences. Spending time to get to know your program is essential, and will pay off in the future

Naming things to remember them easily

When you drag controls on your form, they are instantly named based on its control, followed by a number representing the current amount of its control kind on the current form. For example adding a command button will be named Command1, yet adding another will be named Command2. This is not good practice, as you will find when adding multiple controls. The way to do it is by using name conventions (or suffixes). Here is a small list example:

    * Command Button = cmd
    * Form = frm
    * Label = lbl
    * Picture Box = pic
    * Textbox = txt


Normally if i have only say one Textbox on a form, i would name it txtMain. But with command buttons etc i would name them based on their caption, or action. For example a command button called Exit would be named cmdExit. Why is this better you ask? Because identifying a control named say cmdEnter is better and easier to find then say Command57!

Important Notes

Always use Option Explicit at the top of your code windows, this is to ensure you are using the correctly named variables and that non are mixed up.
You can also make Visual Basic add this automatically to every new code window. Just go to:
Tools > Options > Check "Require Variable Decleration"

Never use END to close your program. Although you can no longer see your program, the memory it has used is stored into the computer's RAM still, which will make the users computer very sluggish The work around is to use Unload Me (you can replace the Me with the form name too). Alternatively you can use Set Me = Nothing (Personally i use Unload Me).
Of course you dont want to repeat code over and over, so from your Main Form, you could add this code, to Unload All Forms From Memory:

Always use the Tab key to space between statements, such as If, Else and Then. It makes it easier to read, thus easier to change later on.

Always use comments, dont worry when you compile your program, the comments are removed and are not added to your final program size

visual basic code:Option Explicit

Private Sub Form_Unload()
Dim frm As Form
    For Each frm In Form
        Unload frm
    Next frm
End Sub




Message Box

To create a simple message you could do the following:

visual basic code:MsgBox ("This is my message")



Then you can simply add a comma (,) at the end of the closed bracket to be introduced with inital message box options, such as icons etc.

Message Box - [Advanced]

This example shows how to store a response in a variable, so you can answer to a question.

visual basic code:Private Sub Form_Load()
Dim Response As Integer

Response = MsgBox("Exit Program?", vbInformation + vbYesNo, "Title")
   
    If Response = vbYes Then
        Unload Me
    ElseIf Response = vbNo Then
        Me.Refresh
    End If
    End Sub




It also shows how to add Yes and No to the message box, as well as an icon and Message title.

Menus
If you dont know what a menu is, then dont learn programming
From VB you can easily create menus, however they can only be set at design time. To create them, you must first open the Menu Editor, you can do so by clicking the Menu Editor button from the toolbar or by pressing Ctrl+E. Now, click on the Caption field, and type your Menu bar caption. This example, will show how to create a Edit menu, like the one seen in Notepad. So in the Caption field type &Edit The & means Ampersand, and underlines the following character. Now from the list below, you will see &Edit, before adding a sub item we must name the Menu Item. We will use mnuEdit. Now from the list below, click Insert, and use the arrows if necassary to position the sub item. To let VB know this is a sub item use the Right arrow once.(IE this item goes directly underneath our main menu). Now we add the Undo sub item. So for the caption we add &Undo, and name it mnuEditUndo. Now create a new sub item in the same way. Now we will make a seperator (this is the line that appears in the menu). we use a - (hyphon) for the caption, and i would name it mnuEditSeperator1. Now finish the menu off as you wish, the layout should look like this:

Code:

&Edit ---&Undo ---- ---&Cut ---&Copy ---&Paste ---&Delete ---- ---Select &All



Close the Menu Editor and look on your form, is the menu there?

Menus - Creating a Popup Menu

To create a popup menu, create a menu like before from the Menu Editor, but make the first Item Visible = False. (you should name it mnuPopup too).

This code will create a popup when the form is right clicked:

visual basic code:Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbRightButton Then
        Popup mnuPopup
    End If
End Sub




Its as simple as that

Modules?

What is a module you ask? A module is used to store all your functions and public routines seperately. Apart from it keeping your code editors window clean, it removes the need for repetitive typing. For example, it is better to add code to a module and use 1 line to call it when needed, then to repeat the same code over and over. This code from the module Exits the program when needed:

visual basic code:Public Sub ExitProgram()
Unload frmMain
End Sub




It has to be named Public so VB knows it is available to all forms. Now, from the form, this code is called when you click either the File > Exit menu item or the Exit Command button, like so (This code goes in your form's code window):

visual basic code:Private Sub mnuFileExit_Click()
Call ExitProgram
End Sub

Private Sub cmdExit_Click()
Call ExitProgram
End Sub




Although there is no significant size difference in using the code form the module, as there is using it in your form's code, it saves time and space later on when dealing with larger code!

Components and Libraries

A component (ActiveX *.ocx) is a control used in your VB IDE environment. The basic components consist of labels, frames, textboxes etc. You can add new components by going to the Project > Components menu.

Q) When i download a ActiveX component from a third-party web site it doesnt show in the components menu. How do i fix this?

A) ActiveX controls need to be registered to your system. To do this, first its reccomended copying the *.ocx file into the C:\WINDOWS\SYSTEM directory. Then goto (from Windows)
Start > Run > regsvr32 "C:\WINDOWS\SYSTEM\MyControl.ocx"
Then you may need to restart VB for the changes to take affect.

This applies the same for DLL's (Dynamic Link Libraries).

To unregister the control or Dll goto:
Start > Run > regsvr32 /u "C:\WINDOWS\SYSTEM\MyControl.ocx"

|