Visual Basic 6'0 - PowerPoint PPT Presentation

1 / 29
About This Presentation
Title:

Visual Basic 6'0

Description:

When it finishes loading, click 'Open' to launch a new Standard ... A Simple Chat Client. Double-Click on the winsock object on the canvas to bring up the code. ... – PowerPoint PPT presentation

Number of Views:87
Avg rating:3.0/5.0
Slides: 30
Provided by: smith184
Category:
Tags: basic | click | client | to | visual

less

Transcript and Presenter's Notes

Title: Visual Basic 6'0


1
Visual Basic 6.0
  • Presented by
  • Daniel Smith

2
When to Use Visual Basic
  • Developing Graphical User Interfaces
  • Similar to webpages in appearance, but without
    the sacrifice of computing power
  • Textboxes, images, and other objects
  • Using High-Level Protocols
  • TCP UDP connections
  • SQL databases

3
Limitations
  • Compiled executables require local copy of Visual
    Basic 5.0 Runtime Module
  • Requires expensive software for development
  • Not portable between operating systems

4
Lets Get Started
  • Start ? Programs ? CS Apps ? Visual Studio ?
    Visual Basic 6.0
  • When it finishes loading, click Open to launch
    a new Standard EXE project

5
What are you looking at?
  • Canvas
  • By double-clicking on anything on this form, you
    launch a window for writing related code.

6
What are you looking at?
  • Properties Sheet
  • Use this to modify design-time attributes of
    any object you place on the canvas.
  • Most of these properties can also be changed at
    runtime
  • More on this in a minute

7
What are you looking at?
  • Toolbox
  • Here are your brush tips for your canvas.
  • Just select the type of object you want and drag
    it out on the canvas.
  • Can add more types from built-in libraries.

8
Most Common Objects
Label (lbl) To write on the canvas.
Textbox (txt) User input field. Also good for
displaying data.
Button (cmd) Need I explain?
Image (img) and Picture (pic) Can display
pictures on your canvas.
Shapes (shp) To make works of artistic
inspiration.
9
First Script
  • Double-click on the canvas.
  • Type the following code
  • msgbox Hello World!
  • Run your program by pressing the Blue Arrow near
    the top center of the screen.

10
Your Reference Source
  • For basic syntax functions
  • oregonstate.edu/smithd6/vb/vb.hlp
  • Use msdn.com for complex usage
  • Visual Tools and Languages ? Visual Studio 6.0 ?
    Visual Basic 6.0 ? Reference ? Language Reference

11
Second Script
  • Create a Textbox on your form by
  • Clicking on the textbox button on the toolbox
    (second row, second column)
  • Dragging out a rectangle on your canvas
  • Notice that you now have options for modifying
    the Textboxs properties in your Properties
    window.

12
Second Script (cont)
  • Change some properties of your Textbox.
  • Backcolor, Forecolor, Font, etc
  • The (Name) property is the name by which you
    will access the textbox from your script.
  • Add a button in the same manner

13
Naming
  • To increase readability of your code, name
    objects with a 3-letter prefix to identify what
    type of object it is.
  • txt Textbox lbl Label
  • cmd Button (Command) pic Picture
  • ex txtInput, cmdSubmit
  • Use what seems logical to you.

14
Second Script (cont)
  • Double-click on the button you added
  • You will automatically be taken to where to type
    the code for the event of button press
  • Type the following
  • msgbox Text1
  • (if you renamed Text1, use the new name)

15
Second Script (cont)
  • As long as youre in the code, delete the msgbox
    Hello World! command.
  • Delete just the one line, or
  • Delete the whole 3-line function
  • Click the Blue Arrow to start the program
  • Enter some text into your Textbox
  • Click the button

16
Lets make our owninstant messenger!
  • On your canvas make at least the following
  • A Textbox to display the conversation
  • Set the (Name) property to txtIn
  • Set the Multiline property to true
  • A Textbox in which to type messages to send
  • Set the (Name) property to txtOut
  • A Button to send the message
  • Set the (Name) property to cmdSend

17
A Simple Chat Client
  • Load the winsock object by
  • Right-click on the toolbox, select Components
  • Check the box for Microsoft Winsock Control
  • Press Apply
  • Notice it is now on your Toolbox.
  • Put a winsock object onto your canvas the same
    way you placed Textboxes and Buttons.
  • At runtime the image will not be rendered.

18
A Simple Chat Client
  • Click on the winsock object on your canvas and
    change the following properties on the Properties
    window
  • (Name)
  • Change it to tcp1 or anything you like.
  • Remotehost
  • This is the servers IP
  • Remoteport
  • The server will operate on this port 3600

19
A Simple Chat Client
  • Double-Click on the winsock object on the canvas
    to bring up the code.
  • At the top-right of the code window, see what
    events this object has.
  • By selecting an event from this list, the
    appropriate function is brought up.

20
A Simple Chat Client
  • Select tcp1_DataArrival and enter the following
    code
  • Dim strData as String
  • tcp1.GetData strData
  • txtIn strData Chr(13) Chr(10) txtIn
  • Now when the tcp connection recieves data, it
    will pre-pend it into the Textbox.

21
A Simple Chat Client
  • Select cmdSend and then cmdSend_Click from the
    top of the code window.
  • Enter the following code
  • tcp1.SendData txtOut
  • txtOut.Text
  • When the button is pressed, the text in txtOut
    will be sent out on tcp1.

22
A Simple Chat Client
  • Select Form1 and then Form1_Load from the top of
    the code window.
  • Enter the following code
  • tcp1.Connect
  • When the program loads, the winsock object (tcp1)
    will connect using the properties you previously
    gave it.

23
A Simple Chat Client
  • Select Form1 and then Form1_Unload from the top
    of the code window.
  • Enter the following code
  • tcp1.Close
  • This helps to clean up socket connections
    gracefully when you kill the program.

24
A Simple Chat Client - Overview
  • Private Sub Form1_Load()
  • tcp1.Connect
  • End Sub
  • Private Sub cmdSend_Click()
  • tcp1.SendData txtOut
  • txtOut.Text ""
  • End Sub
  • Private Sub tcp1_DataArrival(ByVal bytesTotal As
    Long)
  • Dim strData as String
  • tcp1.GetData strData
  • txtIn strData Chr(13) Chr(10) txtIn
  • End Sub
  • Private Sub Form1_Unload(Cancel As Integer)
  • tcp1.Close
  • End Sub

25
Give it a Try
  • When you SendData, the server running on my
    computer echoes it to everyone connected.
  • To run peer-to-peer connections, you must also
    program a server. The code for that looks like

26
A Server for One Connection
  • Private Sub Form_Load()
  • tcp1.Listen
  • End Sub
  • Private Sub tcp_ConnectionRequest(ByVal requestID
    As Long)
  • tcp1.Accept requestID
  • End Sub
  • Private Sub cmdSend_Click()
  • tcp1.SendData txtOut.Text
  • txtIn.Text txtOut.Text Chr(13) Chr(10)
    txtIn.Text
  • txtOut.Text ""
  • End Sub
  • Private Sub tcp_DataArrival(ByVal bytesTotal As
    Long)
  • tcp1.GetData strData
  • txtIn.Text strData Chr(13) Chr(10)
    txtIn.Text
  • End Sub

27
Menubar Items
  • To add items to the drop-down menus at the top of
    your program
  • Click on the canvas
  • Go to Tools ? Menu Editor

28
Compile Your Program
  • In order to run your program outside of the
    Visual Basic IDE, goto
  • File ? Make Project1.exe
  • To change the process name of your program, go
    to
  • Project ? Project1 Properties
  • Change the Project Name

29
Appendix
  • The Visual Basic files for the client application
    are available at http//oregonstate.edu/smithd6/v
    b/client/
  • The Visual Basic files for the server application
    are available at http//oregonstate.edu/smithd6/v
    b/server/
  • Download all files to the same directory
Write a Comment
User Comments (0)
About PowerShow.com