1 / 12

Visual Basic : Core 1

Visual Basic : Core 1. Projects Data types Variables and constants Comments, hex constants and line continuation Forms and controls A calculator program. What's in a Project. Project = code for an application Form = window – several in a project

remedy
Download Presentation

Visual Basic : Core 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Visual Basic : Core 1 • Projects • Data types • Variables and constants • Comments, hex constants and line continuation • Forms and controls • A calculator program

  2. What's in a Project • Project = code for an application • Form = window – several in a project • .frm has data eg form width height, and event-driven subroutines • Module = VB code (general) • Class = defining your own classes • Can make into .exe

  3. Project files

  4. VERSION 5.00 Begin VB.Form Form1 Caption = "Form1" ClientHeight = 2445 ClientLeft = 5145 ClientTop = 4110 ClientWidth = 5070 LinkTopic = "Form1" ScaleHeight = 2445 ScaleWidth = 5070 Begin VB.CommandButton Command1 Caption = "Command1" Height = 615 Left = 1200 TabIndex = 0 Top = 600 Width = 1815 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Private Sub Command1_Click() MsgBox ("Hello world") End Sub Inside a .frm file

  5. Variables • Dim x as Integer • Dim x,y as Integer NO! • Is case sensitive (kind of) • Variable naming conventions • Microsoft Simonyi Hungarian Reddick • House rules • Assignment statement – x = 4 • Option Explicit YES! • Constants – Private Const MyInt As Integer = 5

  6. Comments, line continuation and hex • Comments start with an apostrophe • 'and run to the end of the line • A very long statement can use a_ to continue onto the next line • Hex constants written like &HFF0012

  7. Data types • Integer Long • Single Double • Currency • Byte unsigned 0 - 255 • String • Boolean • Date • Object • Variant - do not use except explicit reason

  8. VarType to determine type 0 Empty (uninitialized) 1 Null (no valid data) 2 Integer 3 Long integer 4 Single-precision floating-point number 5 Double-precision floating-point number 6 Currency value 7 Date value 8 String 9 Object 10 Error value 11 Boolean value 12 Variant (used only with arrays of variants) 13 A data access object 14 Decimal value 17 Byte value 36 Variants that contain user-defined types 8192 Array Dim x As Variant x = 1 MsgBox (VarType(x))

  9. Data type conversion DIM x as integer x = Cint("10")

  10. Form properties

  11. Controls and properties

  12. Example - calculator Private Sub Command1_Click() Dim num1 As Integer Dim num2 As Integer Dim result As Integer num1 = Text1.Text num2 = Text2.Text result = num1 + num2 Label1.Caption = result End Sub Exercise – try this out. Then add and program subtract, multiply and divide buttons. Ignore invalid numbers and divide by zero – done later

More Related