1 / 20

Visual Basic 6 Programming.

Visual Basic 6 Programming. Lecture 2 : January 2005 Dr. Andrew Paul Myers. Logical Variables. To define use : Dim blnTest as Boolean Assignments : blnTest = True blnTest = False Numerically 0 is False, 1 is True. Logical Expressions. A logical expression is made up of : Variables.

kathlene
Télécharger la présentation

Visual Basic 6 Programming.

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 6 Programming. Lecture 2 : January 2005 Dr. Andrew Paul Myers

  2. Logical Variables. To define use : Dim blnTest as Boolean Assignments : blnTest = True blnTest = False Numerically 0 is False, 1 is True.

  3. Logical Expressions. A logical expression is made up of : • Variables. • Constants. • Logical operators. e.g. some simple test conditions: intRadius = 24 intRadius < > intOld_Radius

  4. Logical Operators I. Test conditions : < less than. > greater then. < = less than or equal to. > = greater than or equal to. = equal to. < > not equal to.

  5. Logical Operators II. Logical Test Operators : And Not Or e.g. (intA <= 3) Or (intB >= 5)

  6. Conditional Statements. Conditions use logical expressions. A simple If statement : If sngX = 1.5 Then sngY = 20.5 If strText < > “Again” Then End

  7. Block If-Then-Else. If sngZ >= 3.2 Then TextBox1.Text = “3.2 or more” intI = intI + 1 blnTest = True End If If intX = 1 And intY = 2 Then intZ=3 Else intZ=2 End If

  8. General Form. If <condition(s)> Then <statement(s)> ElseIf <condition(s)> <statement(s)> Else <Statement(s)> End If

  9. Error Trapping. If sngRadius < 0.0 Then TextBox2.Text “Error –ve Radius!” RadiusBox.Text = “” Else sngArea = sngPi * sngRadius^2 Label1.Caption = “Area cm^2 “ TextBox1.Text = sngArea End If

  10. Case Statement. Select Case intMark Case Is >= 70 TextBox1.Text = “First!” intFirsts = intFirsts + 1 Case Is >= 60 TextBox1.Text = “2.1” intTwoOnes = intTwoOnes + 1 Case Else TextBox1.Text = “2.2 or less.” End Select

  11. Case : General Form. Select Case <variable> Case Is <condition(s)> <statement(s)> Case Is <condition(s)> <statement(s)> . . . Case Else <statement(s)> End Select

  12. Intrinsic Functions. • Functions return a value of certain data type. • Parameters are passed to functions. • Parameters can be variables, constants or expressions. • Intrinsic means “built in”. dblY=Tan(1#) sngY=Abs(-3.5) sngY=Abs(-3.5*sngX) dblZ=dblX+3.0*Log(dblY) dblY=Val(strRadius) dblY=Log(dblX) strAnswer=Str(sngX) dblY=Sin((dblPi*degrees)/180#)

  13. More examples… Sin(x) Cos(x) Tan(x) Atn(x) Sqr(x) Abs(x) Is there a Asn(x) Function? NO! Arcsin(X) = Atn(X / Sqr(-X * X + 1)) See Derived Maths Functions Sheet!

  14. Non maths functions. e.g. Convert string to number. If (IsNumeric(strText_string)) Then sngValue = Val(strText_String) End If e.g. Convert number to string. strText_String = Str(intData1) TextBox1.Text = Str(dblVolume)

  15. Aids to Program Development. • Pseudo Code : “English” like version of program. • Flowcharts : Graphical representation of the programs structure. • Debugger : Inbuilt tool in VB, allowing users to stop and monitor the program at specified “break points”.

  16. Pseudo Code I. How to approach writing a program to solve the quadratic equation of the form : The general solution is :

  17. Pseudo Code II. Start program. Declare and initialise variables. Display a program window with titles and instructions. Do Until program finished. Enter values for a,b,c. If root is complex Then. Calculate complex roots. Else Calculate real roots. End If Display answers. Program finished? Loop. End program.

  18. Flowcharts I. Symbols : • Start or end program : • Process for function : • Decision : • Connector : Start Print Titles End? A

  19. VB Debugger. Select options from the “Debug” menu. • Set “Breakpoints” to halt the program. • Then able to examine variable values, highlight or position cursor over variable to get value. • Use “Watch points” to monitor a list of variables as the program runs. • Use step options to proceed line by line or enter subroutines.

More Related