Question? Leave a message!




Visual Basic Programming

Visual Basic Programming 32
An Introduction Visual Basic ProgrammingHProgramming for the Windows User Interface is extremely complicated. HOther Graphical User Interfaces (GUI) are no better. HVisual Basic provides a convenient method for building user interfaces. HVisual Basic can interface with code written in C, for efficiency. Why Visual BasicHVisual Basic is not, a powerful programming language that enables you to do anything you want. HVisual Basic is not, elegant or fast. HVisual Basic is not, a replacement for C. HVisual Basic is not, anything like any other programming language you have ever used. What Visual Basic is notHYou draw pictures of your user interface. HYou draw buttons, text boxes, and other userinterface items. HYou add little snippets of code to handle the user interaction. HYou add initialization code, usually as the last step. HIf you like, you can code more complex functions. (But many do not.) When You Program in VB:Here Program Draw Your The Visual Basic InterfaceSelect A Control From Here Then Draw the control on the form (Click on the appropriate button) Drawing The ProgramPictures Group Box Editable Text Check Box Button Scroll Bar DropDown List List Scroll Bar Drive List Pictures Lines And the List Goes On and On ... Data Base Access File List Circles and Stuff Folder Hierarchy Timer Radio Button Static Text Types of ControlsAdd Code Change Properties Using controls: Editable Text Buttons Static Text Select and SingleClick to DoubleClick to A Simple ProgramControl Menu. Select New Value From Type In New Value, or Click on Property, and For Currently Selected List of Properties The Properties WindowControl The Body Yourself What to Do When It Happens You must Write NameName External Event Adding CodeHComplex Controls Have: – Action – Active – H Examples: –Spreadsheets – – Web Browsers Word Processors Many Types of Events for Program Interaction Values Are Assigned to Them Properties that Cause Actions When Properties to Execute Commands More Complex ControlsHWrite a DLL in C HUse the export Property on Appropriate Functions HWrite Visual Basic Definitions for each Function HAdd VB Definitions to The (general) section of the VB Program HUse Functions as if they were VB functions Using C CodeC: long FAR PASCAL export HexToLong (char Hex) VB: Declare Function HexToLong Lib “ FIRSTONE.DLL” (ByVal InString As String) As Long Argument Name in VB is arbitrary. The Lib keyword Must Give The Name of the Library. Function Name Must Be The Same in Both Declarations. C Definition vs. VB DefinitionHIt is sometimes difficult for VB to FIND the .DLL file. HIf this occurs, copy the .DLL file to the WINDOWS directory. HRemember to Delete the file when you are done. A (Very Annoying) ProblemH Some Versions of VB do not allow DLL function definitions in the (general) section of a form. HTo Get Around this Problem, Create a new Module (File Menu) HAdd the declarations to the (general) section of the module HYou can add your own VB functions to the (general) section of a form or a module. Alternative MethodsHAll Functions are Global in VB HVariables are declared using the syntax: – – –Dim A,B,C As Type will work, but gives HMost Common Types: Integer, String, Long weird results Every variable must have a type Dim Name As Type Syntax ConsiderationsHUse Integers for Booleans –As in C, 0 = False, everything else = True – – HAssignments are the same as in C HThe Val function converts strings to integers HThe Format function converts integers to strings True = 1, False = 0 Symbolic constants True and False may be used More VB SyntaxHAssignments are the Same as in C HCase is not significant – – HThe Usual Operators can be used –AND is the same as both and depending – – NOT = OR = and on context For Variable Names, Case is ignored Case will be adjusted for you on keywords VB Statements List of Statements List of Statements Else List of Statements Comparators: =,, , =, =, (not equal) Connectives: And, Or, Not DON’T FORGET THE ENDIF EndIf EndIf If condition ThenIf condition Then VB IF StatementsWhile condition do List of Statements The VB Manual Recommends a different structure. Use the alternative if you wish. Wend VB While StatementsFor Variable = start to finish List of Statements Next Variable List of Statements Next Variable Example: AI = AI + 1 Next I For I = 1 to 10 do For Variable = start to finish Step increment VB For StatementsHIndices Always Start With Zero H Dim A10 As Integer Declares 11 elements, indexed from 0 through 10. HMultiDimensional Arrays are Permitted. HArrays can be resized at run time (See VB Help File for ReDim) VB ArraysHVariable Length HCompare using standard comparators HMaximum length is about 64Kb HMinimum length is zero HAllocated from VB “String Space”, so may run out of space even on systems with much memory. VB StringsGo Fun Have And in Conclusion ...An Introduction Visual Basic ProgrammingHProgramming for the Windows User Interface is extremely complicated. HOther Graphical User Interfaces (GUI) are no better. HVisual Basic provides a convenient method for building user interfaces. HVisual Basic can interface with code written in C, for efficiency. Why Visual BasicHVisual Basic is not, a powerful programming language that enables you to do anything you want. HVisual Basic is not, elegant or fast. HVisual Basic is not, a replacement for C. HVisual Basic is not, anything like any other programming language you have ever used. What Visual Basic is notHYou draw pictures of your user interface. HYou draw buttons, text boxes, and other userinterface items. HYou add little snippets of code to handle the user interaction. HYou add initialization code, usually as the last step. HIf you like, you can code more complex functions. (But many do not.) When You Program in VB:Draw Your Here Program The Visual Basic InterfaceThen Draw the control on the form (Click on the appropriate button) Select A Control From Here Drawing The ProgramEditable TextEditable Text DropDown List List Folder Hierarchy Circles and Stuff And the List Goes On and On ... Data Base Access Lines Pictures File List Drive List Scroll Bar Timer Radio Button Scroll Bar Button Check Box Group Box Pictures Static Text Types of ControlsSelect and Change Properties Using controls: Editable Text Buttons Static Text SingleClick to Add Code DoubleClick to A Simple ProgramFor Currently Selected Control Menu. Select New Value From Type In New Value, or Click on Property, and List of Properties The Properties WindowControl NameName Yourself What to Do When It Happens The Body You must Write External Event Adding CodeHComplex Controls Have: – Action – Active – HExamples: – – – Web Browsers Word Processors Spreadsheets Many Types of Events for Program Interaction Values Are Assigned to Them Properties that Cause Actions When Properties to Execute Commands More Complex ControlsHWrite a DLL in C HUse the export Property on Appropriate Functions HWrite Visual Basic Definitions for each Function HAdd VB Definitions to The (general) section of the VB Program HUse Functions as if they were VB functions Using C CodeC: long FAR PASCAL export HexToLong (char Hex) VB: Declare Function HexToLong Lib “ FIRSTONE.DLL” (ByVal InString As String) As Long The Lib keyword Must Give The Name of the Library. Argument Name in VB is arbitrary. Function Name Must Be The Same in Both Declarations. C Definition vs. VB DefinitionHIt is sometimes difficult for VB to FIND the .DLL file. HIf this occurs, copy the .DLL file to the WINDOWS directory. HRemember to Delete the file when you are done. A (Very Annoying) ProblemHSome Versions of VB do not allow DLL function definitions in the (general) section of a form. HTo Get Around this Problem, Create a new Module (File Menu) HAdd the declarations to the (general) section of the module HYou can add your own VB functions to the (general) section of a form or a module. Alternative MethodsHAll Functions are Global in VB HVariables are declared using the syntax: – – – HMost Common Types: Integer, String, Long weird results Dim A,B,C As Type will work, but gives Every variable must have a type Dim Name As Type Syntax ConsiderationsHUse Integers for Booleans – – – HAssignments are the same as in C HThe Val function converts strings to integers HThe Format function converts integers to strings True = 1, False = 0 Symbolic constants True and False may be used As in C, 0 = False, everything else = True More VB SyntaxHAssignments are the Same as in C HCase is not significant – – HThe Usual Operators can be used – – – NOT = OR = and on context AND is the same as both and depending For Variable Names, Case is ignored Case will be adjusted for you on keywords VB Statements List of Statements List of Statements EndIf List of Statements EndIf Comparators: =,, , =, =, (not equal) Connectives: And, Or, Not DON’T FORGET THE ENDIF Else If condition ThenIf condition Then VB IF StatementsWhile condition do List of Statements Wend Use the alternative if you wish. The VB Manual Recommends a different structure. VB While StatementsFor Variable = start to finish List of Statements Next Variable List of Statements Next Variable AI = AI + 1 Next I For I = 1 to 10 do Example: For Variable = start to finish Step increment VB For StatementsHIndices Always Start With Zero H Dim A10 As Integer Declares 11 elements, indexed from 0 through 10. HMultiDimensional Arrays are Permitted. HArrays can be resized at run time (See VB Help File for ReDim) VB ArraysHVariable Length HCompare using standard comparators HMaximum length is about 64Kb HMinimum length is zero HAllocated from VB “String Space”, so may run out of space even on systems with much memory. VB StringsGo Have Fun And in Conclusion ...
sharer
Presentations
Free
Document Information
Category:
Presentations
User Name:
EdenKelly
User Type:
Professional
Country:
United States
Uploaded Date:
12-07-2017