Example: tourism industry

Visual Basic Programming - Baylor University

Visual Basic ProgrammingAn IntroductionWhy Visual Basic ?HProgramming for the Windows UserInterface is extremely Graphical User Interfaces (GUI) areno Basic provides a convenient methodfor building user Basic can interface with code writtenin C, for Visual Basic is notHVisual Basic is not, a powerfulprogramming language that enables you todo anything you Basic is not, elegant or Basic is not, a replacement for Basic is not, anything like any otherprogramming language you have ever You Program in VB:HYou draw pictures of your user draw buttons, text boxes, and otheruser-interface add little snippets of code to handle theuser add initialization code, usually as thelast you like, you can code more complexfunctions. (But many do not.)

What Visual Basic is not H Visual Basic is not, a powerful programming language that enables you to do anything you want. H Visual Basic is not, elegant or fast. H Visual Basic is not, a replacement for C. H Visual Basic is not, anything like any other programming language you have ever used.

Tags:

  Basics, Visual, Visual basic

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of Visual Basic Programming - Baylor University

1 Visual Basic ProgrammingAn IntroductionWhy Visual Basic ?HProgramming for the Windows UserInterface is extremely Graphical User Interfaces (GUI) areno Basic provides a convenient methodfor building user Basic can interface with code writtenin C, for Visual Basic is notHVisual Basic is not, a powerfulprogramming language that enables you todo anything you Basic is not, elegant or Basic is not, a replacement for Basic is not, anything like any otherprogramming language you have ever You Program in VB:HYou draw pictures of your user draw buttons, text boxes, and otheruser-interface add little snippets of code to handle theuser add initialization code, usually as thelast you like, you can code more complexfunctions. (But many do not.)

2 The Visual Basic InterfaceDraw YourProgramHere!Drawing The ProgramSelect A Control From Here(Click on the appropriate button)Then Draw the control on the formTypes of ControlsStatic TextGroup BoxCheck BoxScroll BarTimerFolder HierarchyCircles and StuffPicturesPicturesEditable TextButtonRadio ButtonDrop-Down ListListDrive ListFile ListLinesData Base AccessScroll BarAnd the List Goes On and On ..A Simple ProgramDouble-Click toAdd CodeSingle-Click toSelect andChangePropertiesUsing controls:Static TextEditable TextButtonsThe Properties WindowList of PropertiesFor Currently SelectedControlClick on Property, andType In New Value, orSelect New Value CodeControlNameExternal EventNameWhat to Do When It HappensYou must WriteThe BodyYourselfMore Complex ControlsHComplex Controls Have: Action Properties to Execute Commands Active Properties that Cause Actions WhenValues Are Assigned to Them Many Types of Events for Program InteractionHExamples.

3 Spreadsheets Word Processors Web BrowsersUsing C CodeHWrite a DLL in CHUse the _export Property on AppropriateFunctionsHWrite Visual Basic Definitions for eachFunctionHAdd VB Definitions to The (general)section of the VB ProgramHUse Functions as if they were VB functionsC Definition vs. VB DefinitionDeclare Function HexToLong Lib (ByVal InString As String) As Long long FAR PASCAL _export HexToLong (char *Hex)C:VB:Function Name Must Be The Same in Both Lib keyword Must Give The Name of the Name in VB is (Very Annoying) ProblemHIt is sometimes difficult for VB to FIND this occurs, copy the .DLL file to theWINDOWS to Delete the file when you MethodsHSome Versions of VB do not allow DLLfunction definitions in the (general) sectionof a Get Around this Problem, Create a newModule (File Menu)HAdd the declarations to the (general) sectionof the moduleHYou can add your own VB functions to the(general) section of a form or a ConsiderationsHAll Functions are Global in VBHV ariables are declared using the syntax: Dim <Name> As <Type> Every variable must have a type Dim A,B,C As <Type> will work, but givesweird resultsHMost Common Types.

4 Integer, String, LongMore VB SyntaxHUse Integers for Booleans As in C, 0 = False, everything else = True Symbolic constants True and False may be used True = -1, False = 0 HAssignments are the same as in CHThe Val function converts strings to integersHThe Format$ function converts integers tostringsVB StatementsHAssignments are the Same as in CHCase is not significant Case will be adjusted for you on keywords For Variable Names, Case is ignoredHThe Usual Operators can be used AND is the same as both & and && dependingon context OR = | and || NOT = !VB IF StatementsIf <condition> Then <List of Statements>Else <List of Statements>EndIfIf <condition> Then <List of Statements>EndIfDON T FORGET THE ENDIF!Comparators: =,<, >, <=, >=, < > (not equal)Connectives: And, Or, NotVB While StatementsWhile <condition> do <List of Statements>WendThe VB Manual Recommends a different the alternative if you For StatementsFor <Variable> = <start> to <finish> <List of Statements>Next <Variable>For <Variable> = <start> to <finish> Step <increment> <List of Statements>Next <Variable>Example.

5 For I = 1 to 10 do A[I] = A[I] + 1 Next IVB ArraysHIndices Always Start With ZeroHDim A[10] As Integer Declares 11 elements,indexed from 0 through Arrays are can be resized at run time (See VBHelp File for ReDim)VB StringsHVariable LengthHCompare using standard comparatorsHMaximum length is about 64 KbHMinimum length is zeroHAllocated from VB String Space , so mayrun out of space even on systems with in Conclusion ..GoHaveFun! Visual Basic ProgrammingAn IntroductionWhy Visual Basic ?HProgramming for the Windows UserInterface is extremely Graphical User Interfaces (GUI) areno Basic provides a convenient methodfor building user Basic can interface with code writtenin C, for Visual Basic is notHVisual Basic is not, a powerfulprogramming language that enables you todo anything you Basic is not, elegant or Basic is not, a replacement for Basic is not, anything like any otherprogramming language you have ever You Program in VB:HYou draw pictures of your user draw buttons, text boxes, and otheruser-interface add little snippets of code to handle theuser add initialization code, usually as thelast you like, you can code more complexfunctions.

6 (But many do not.)The Visual Basic InterfaceDraw YourProgramHere!Drawing The ProgramSelect A Control From Here(Click on the appropriate button)Then Draw the control on the formTypes of ControlsStatic TextGroup BoxCheck BoxScroll BarTimerFolder HierarchyCircles and StuffPicturesPicturesEditable TextEditable TextButtonRadio ButtonDrop-Down ListListDrive ListFile ListLinesData Base AccessScroll BarAnd the List Goes On and On ..A Simple ProgramDouble-Click toAdd CodeSingle-Click toSelect andChangePropertiesUsing controls:Static TextEditable TextButtonsThe Properties WindowList of PropertiesFor Currently SelectedControlClick on Property, andType In New Value, orSelect New Value CodeControlNameExternal EventNameWhat to Do When It HappensYou must WriteThe BodyYourselfMore Complex ControlsHComplex Controls Have: Action Properties to Execute Commands Active Properties that Cause Actions WhenValues Are Assigned to Them Many Types of Events for Program InteractionHExamples.

7 Spreadsheets Word Processors Web BrowsersUsing C CodeHWrite a DLL in CHUse the _export Property on AppropriateFunctionsHWrite Visual Basic Definitions for eachFunctionHAdd VB Definitions to The (general)section of the VB ProgramHUse Functions as if they were VB functionsC Definition vs. VB DefinitionDeclare Function HexToLong Lib (ByVal InString As String) As Long long FAR PASCAL _export HexToLong (char *Hex)C:VB:Function Name Must Be The Same in Both Lib keyword Must Give The Name of the Name in VB is (Very Annoying) ProblemHIt is sometimes difficult for VB to FIND this occurs, copy the .DLL file to theWINDOWS to Delete the file when you MethodsHSome Versions of VB do not allow DLLfunction definitions in the (general) sectionof a Get Around this Problem, Create a newModule (File Menu)HAdd the declarations to the (general) sectionof the moduleHYou can add your own VB functions to the(general) section of a form or a ConsiderationsHAll Functions are Global in VBHV ariables are declared using the syntax: Dim <Name> As <Type> Every variable must have a type Dim A,B,C As <Type> will work, but givesweird resultsHMost Common Types.

8 Integer, String, LongMore VB SyntaxHUse Integers for Booleans As in C, 0 = False, everything else = True Symbolic constants True and False may be used True = -1, False = 0 HAssignments are the same as in CHThe Val function converts strings to integersHThe Format$ function converts integers tostringsVB StatementsHAssignments are the Same as in CHCase is not significant Case will be adjusted for you on keywords For Variable Names, Case is ignoredHThe Usual Operators can be used AND is the same as both & and && dependingon context OR = | and || NOT = !VB IF StatementsIf <condition> Then <List of Statements>Else <List of Statements>EndIfIf <condition> Then <List of Statements>EndIfDON T FORGET THE ENDIF!Comparators: =,<, >, <=, >=, < > (not equal)Connectives: And, Or, NotVB While StatementsWhile <condition> do <List of Statements>WendThe VB Manual Recommends a different the alternative if you For StatementsFor <Variable> = <start> to <finish> <List of Statements>Next <Variable>For <Variable> = <start> to <finish> Step <increment> <List of Statements>Next <Variable>Example.

9 For I = 1 to 10 do A[I] = A[I] + 1 Next IVB ArraysHIndices Always Start With ZeroHDim A[10] As Integer Declares 11 elements,indexed from 0 through Arrays are can be resized at run time (See VBHelp File for ReDim)VB StringsHVariable LengthHCompare using standard comparatorsHMaximum length is about 64 KbHMinimum length is zeroHAllocated from VB String Space , so mayrun out of space even on systems with in Conclusion ..GoHaveFun!


Related search queries