Free Games Forum
Free Games Games Forums Music Forums TV Forums

  Free Games Forum Home FORUM
HOME
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN
Rules & FAQ RULES / FAQ
REPORT SPAM

Free Games Forum: Game Technology: Visual Basic / VB:
Getting Started [Tutorial] [UPDATE: Working with controls] VB 5

 

 


Lotus Lecetoy
Veteran


Aug 3, 2006, 4:10 PM

Post #1 of 5 (621 views)
Shortcut
Getting Started [Tutorial] [UPDATE: Working with controls] VB 5 Can't Post

(pics comming soon I hope to make this easier)
  • Getting Started

    First open up your Visual Basic (Duh) and start Default Form 1. Double Click form 1 and the source will be revealed. The top dropdown window consists of objects and their associated procedures. Opening the objects dropdown window will provide a list of objects that are on your program. (i.e. Command1, Label1, etc) This allows you to make each object to certain tasks that you have scripted. The same is with the procedures - a list of procedures will be shown. You don't have to mess around with the Private Sub Form_Load() or End Sub just work in between them. If you now run the program nothing will/should show up because there is no script. The print command does not actually mean to print with a printer, it just means to show up on the screen.

  • First source


  • Code
    Private Sub Form_Load ( )        

    Form1.show 'not needed

    Print "Lotus owns"

    End Sub

    Should come up as just a simple box with Lotus Owns in it.

    You can also do math in VB.


    Code
    Private Sub Form_Activate ( )        

    Print 5 * 9
    Print 20 - 3
    Print 8 * 10
    Print 64 / 8

    End Sub


    If you do not want them verticle you can type them horizontally.

  • Variables

  • You can use variables in VB too.


    Code
    Private Sub Form_Activate ( )        

    x = 12
    y = 6
    Print x + y
    Print x - y
    Print x * y
    Print x / y

    End Sub


    Variables don't have to be used as numbers. You can also use them for words.


    Code
    Private Sub Form_Active ()        

    A = Lotus

    B = Owns

    C = Your

    D = Mother

    Print A + B + C + D + E

    End Sub


  • Steps in making a program[/lb]

  • Design what it looks like
    Set the objects
    Write the procedures.
  • Your first program


  • Quote

    This program is a simple program that calculates the volume of a cylinder. Let design the interface:

    Figure 2.8 A program to calculate the Volume of a Cylinder



    First of all, go to the properties window and change the form caption to Volume of Cylinder, then drag and insert three labels into the form and change their captions to Base Radius, height and volume respectively. After that, insert three Text Boxes and clear its text contents so that you get three empty boxes. Named the text boxes as radius, hght (we cannot use height as it is the built-in control name of VB) and volume respectively. Lastly, insert a command button and change its caption to O.K and its name to OK. Now save the project as cylinder.vbp and the form as cylinder.vbp as well. We shall leave out the codes at the moment which you shall learn it in lesson3.


    From: http://www.vbtutor.net/lesson2.html


  • Controls

  • Before you can make responses for the user's input you must first set properties for the control.


    This is what your properties frame should look like. In the caption box you can name whatever you want the box to say. "Yes" "No" "Cancel" "STFU" "I'm gay" anything you want it to say. (Just don't rename it) The left is the property and the right is state. Highlighting the statement will allow you to change it. (i.e. the caption) You can also change the color, font, etc.

    Not only can you change the properties at your computer, you can also change them while running the program: The shape, color, etc to give special effects. (such as a win or lose at a game) Using the following script:


    Code
    Private Sub Form_Load()   
    Form1.BackColor = &H000000FF&
    End Sub

    Will change the background color to red of your form upon loading.

    If you want it to change to a circle:


    Code
    Private Sub Form_Load()   
    Shape1.Shape = 3
    End Sub


    (Mind you, VB can allow you to do much more than making it turn red and changing it to a circle)

    It is always wise to label your captions so that the user knows what the command does. (In otherwords, don't be stupid and switch "yes" and "no" around...Unless you want to Smile)
    Always make sure that the enabled is set to true if you wish to allow the users to be able to use it.

    That's about all it is, untill you get into more advanced (Try to leech some source codes but never take credit)

  • The Text Box


  • Quote

    In this program, two text boxes are inserted into the form together with a few labels. The two text boxes are used to accept inputs from the user and one of the labels will be used to display the sum of two numbers that are entered into the two text boxes. Besides, a command button is also programmed to calculate the sum of the two numbers using the plus operator. The program use creates a variable sum to accept the summation of values from text box 1 and text box 2.The procedure to calculate and to display the output on the label is shown below. The output is shown in Figure 3.1.
    Private Sub Command1_Click()
    ‘To add the values in text box 1 and text box 2
    Sum = Val(Text1.Text) + Val(Text2.Text)
    ‘To display the answer on label 1
    Label1.Caption = Sum
    End Sub
    Figure 3.1


    3.2.2 The Label
    The label is a very useful control for Visual Basic, as it is not only used to provide instructions and guides to the users, it can also be used to display outputs. One of its most important properties is Caption. Using the syntax label.Caption, it can display text and numeric data . You can change its caption in the properties window and also at runtime. Please refer to Example 3.1 and Figure 3.1 for the usage of label.
    3.2.3 The Command Button
    The command button is a very important control as it is used to execute commands. It displays an illusion that the button is pressed when the user click on it. The most common event associated with the command button is the Click event, and the syntax for the procedure is
    Private Sub Command1_Click ()
    Statements
    End Sub
    3.2.4 The Picture Box
    The Picture Box is one of the controls that used to handle graphics. You can load a picture at design phase by clicking on the picture item in the properties window and select the picture from the selected folder. You can also load the picture at runtime using the LoadPicture method. For example, the statement will load the picture grape.gif into the picture box.
    Picture1.Picture=LoadPicture ("C:\VB program\Images\grape.gif")
    You will learn more about the picture box in future lessons. The image in the picture box is not resizable.

    3.2.5 The Image Box
    The Image Box is another control that handles images and pictures. It functions almost identically to the picture box. However, there is one major difference, the image in an Image Box is stretchable, which means it can be resized. This feature is not available in the Picture Box. Similar to the Picture Box, it can also use the LoadPicture method to load the picture. For example, the statement loads the picture grape.gif into the image box.
    Image1.Picture=LoadPicture ("C:\VB program\Images\grape.gif")

    3.2.6 The List Box
    The function of the List Box is to present a list of items where the user can click and select the items from the list. In order to add items to the list, we can use the AddItem method. For example, if you wish to add a number of items to list box 1, you can key in the following statements
    Example 3.2
    Private Sub Form_Load ( )
    List1.AddItem “Lesson1”
    List1.AddItem “Lesson2”
    List1.AddItem “Lesson3”
    List1.AddItem “Lesson4”
    End Sub
    The items in the list box can be identified by the ListIndex property, the value of the ListIndex for the first item is 0, the second item has a ListIndex 1, and the second item has a ListIndex 2 and so on
    3.2.7 The Combo Box
    The function of the Combo Box is also to present a list of items where the user can click and select the items from the list. However, the user needs to click on the small arrowhead on the right of the combo box to see the items which are presented in a drop-down list. In order to add items to the list, you can also use the AddItem method. For example, if you wish to add a number of items to Combo box 1, you can key in the following statements
    Example 3.3
    Private Sub Form_Load ( )
    Combo1.AddItem “Item1”
    Combo1.AddItem “Item2”
    Combo1.AddItem “Item3”
    Combo1.AddItem “Item4”
    End Sub

    3.2.8 The Check Box
    The Check Box control lets the user to select or unselect an option. When the Check Box is checked, its value is set to 1 and when it is unchecked, the value is set to 0. You can include the statements Check1.Value=1 to mark the Check Box and Check1.Value=0 unmark the Check Box, and use them to initiate certain actions. For example, the program will change the background color of the form to red when the check box is unchecked and it will change to blue when the check box is checked. You will learn about the conditional statement If….Then….Elesif in later lesson. VbRed and vbBlue are color constants and BackColor is the background color property of the form.

    Example 3.4
    Private Sub Check1_Click ()
    If Check1.Value = 0 Then
    Form1.BackColor = vbRed
    ElseIf Check1.Value = 1 Then
    Form1.BackColor = vbBlue
    End If
    End Sub

    3.2.9 The Option Box

    The Option Box control also lets the user selects one of the choices. However, two or more Option Boxes must work together because as one of the Option Boxes is selected, the other Option Boxes will be unselected. In fact, only one Option Box can be selected at one time. When an option box is selected, its value is set to “True” and when it is unselected; its value is set to “False”. In the following example, the shape control is placed in the form together with six Option Boxes. When the user clicks on different option boxes, different shapes will appear. The values of the shape control are 0, 1, and 2,3,4,5 which will make it appear as a rectangle, a square, an oval shape, a rounded rectangle and a rounded square respectively.
    Example 3.5
    Private Sub Option1_Click ( )
    Shape1.Shape = 0
    End Sub
    Private Sub Option2_Click()
    Shape1.Shape = 1
    End Sub
    Private Sub Option3_Click()
    Shape1.Shape = 2
    End Sub
    Private Sub Option4_Click()
    Shape1.Shape = 3
    End Sub
    Private Sub Option5_Click()
    Shape1.Shape = 4
    End Sub
    Private Sub Option6_Click()
    Shape1.Shape = 5
    End Sub
    3.2.9 The Drive List Box
    The Drive ListBox is used to display a list of drives available in your computer. When you place this control into the form and run the program, you will be able to select different drives from your computer as shown in Figure 3.2
    Figure 3.2 The Drive List Box

    3.2.10 The Directory List Box
    The Directory List Box is used to display the list of directories or folders in a selected drive. When you place this control into the form and run the program, you will be able to select different directories from a selected drive in your computer as shown in Figure 3.3
    Figure 3.3 The Directory List Box


    3.2.11 The File List Box
    The File List Box is used to display the list of files in a selected directory or folder. When you place this control into the form and run the program, you will be able to a list of files in a selected directory as shown in Figure 3.4
    Figure 3.4

    You can coordinate the Drive List Box, the Directory List Box and the File List Box to search for the files you want. The procedure will be discussed in later lessons.


    From http://www.vbtutor.net/lesson3.html


    Hope you liked it!

    Resources: http://www.vbtutor.net/lesson2.html
    (This is my guide, but I used some examples from that site BTW)


    ______
    http://freewebs.com/matthewlecetoy

    "The only rules that really matter are these: what a man can do and what a man can't do."

    (This post was edited by Peach Pit on Jan 5, 2007, 5:00 AM)



    Demosthenes
    Veteran


    Aug 4, 2006, 5:28 AM

    Post #2 of 5 (606 views)
    Shortcut
    Re: [Lotus Lecetoy] Getting Started [Tutorial] [In reply to] Can't Post

    Quality. A concise, to-the-point tutorial on a program many find mystefying (although it really isn't.)

    Nice job.


    "Great news Pedos!"

    -Jindrak


    -Pwnt-
    Veteran


    Aug 4, 2006, 1:21 PM

    Post #3 of 5 (594 views)
    Shortcut
    Re: [Lotus Lecetoy] Getting Started [Tutorial] [UPDATE: Working with controls] [In reply to] Can't Post

    All looks good except for an unclosed tag. Ctrl + F [/lb].

    I found it a good read, with your sense of humor guiding me through the painful process.


    brb eating spaghetti


    darkdemon
    Enthusiast


    Aug 4, 2006, 2:46 PM

    Post #4 of 5 (591 views)
    Shortcut
    Re: [Lotus Lecetoy] Getting Started [Tutorial] [UPDATE: Working with controls] [In reply to] Can't Post

    You forgot the most common application for beginners working with developer studios.
    Hello World.

    Make a new .exe project, add a button then double click it.

    Add :

    Code
      
    MsgBox("Hello World, darkdemon is cool")


    Compile it, the run it, press the button and magic happens.


    U r reading a signature.
    Free game hacks!


    Soupfinder
    Newbie


    Nov 5, 2006, 2:13 PM

    Post #5 of 5 (492 views)
    Shortcut
    Re: [Lotus Lecetoy] Getting Started [Tutorial] [UPDATE: Working with controls] [In reply to] Can't Post

    Unsure My brain hurts...


    There is a cheatcode for life. It's called 'Money'.

    "98% of the teenage population will try, does, or has tried smoking pot. If you're one of the 2% who hasn't, copy & paste this into your signatur

     
     
     


    Search for (options) Web Design by Web Ideas - Page loaded in: 0.14 s on (CGI/1.1)