حتى الإحتراف فيجوال بيسك 2008 (الفصل 1 إلى 6)
TRANSCRIPT
-
8/14/2019 ( 2008 ( 1 6
1/108
2008
: 2008 2008 software applications .
2008 , , ( ,) .
. 2008 2008 , C++ 2008 ,C# 2008 Web Developer 2008 .....
2008 ( ) ,standard edition ,Professional Edition Team Suite (Express Edition
) 2005
, 2008 . 2008
: 2 2003 1
(2008 ,Standard Edition Professional Edition TeamSuite(
: GHz 1.6 MB RAM 384, 7681024, , 5400RPM / .,
2.2: 1024 (10241280 : 2.4 GHz768 MB RAM) ) .
2008 professional edition standard edition
21 ,24 ,VB6
, windows applications web application classes and customcontrols console visual tools . :
-1 integrated development environment of Visual Studio-2 windows applications
Development Environmentthe IntegratedExploring ,2008 Integrated(2008
Development Environment(IDE)( , 2008 IDE) , ... ...
, Microsoft Visual Studio Integrated Development Environment IDE . ,
C++ ,#C :2008 -1 Start / Windows taskbar /All Programs 2008folder )Visual Studio
) /2008 )Microsoft Visual Studio 2008(2008 2008 ,
-2 2008 , , Visual Basic development
, , ( ) tool windows Start Page , )MSDN)Microsoft development net
.
.
)integrated development environment)IDE IDE)( . IDE
/
. The Start Page
Multiple Documents Tabbed Documents view : Tools menu Options Options
General Window Layout
-
8/14/2019 ( 2008 ( 1 6
2/108
Tabbed Documents OK .
, vb2008
, ,
)1.1( Recent Projects
Recent Projects link ,Open Project
( Open Project )CTRL+O .
-
8/14/2019 ( 2008 ( 1 6
3/108
)10(
: )help( )about( . 2008 2005 .
2008 2005 ...2003 : ( ) projects or solutions
, , 2008 VBPROJproject file.)( (solution file (.SLN , Windows Explorer 9 :
. cala )sln.( )cala( )vbproj.( )visual basic project( .
2008 ).VB 9( project file , ,projects , project group files (vbg.)
,6 single project ,solution project file(.vbproj) (solution file (.sln ( ) a
project solution-multi , 2008 .,
( )Always Show Solution solutions ,IDE Tools Options
General) ) /Projects and Solutions solution ,
solutions ,IDE File Solution Explorer ,
MSDN: Visual Studio )MSDN)the Microsoft Developer Network , , , .
Getting Started ( )
-
8/14/2019 ( 2008 ( 1 6
4/108
al Studio HeadlinesVisu announcements
, Tools menu Import And Export Settings location ,
next , , 2008 , :
General Development Settings, Visual Basic Development Settings, and Web Development Settings Visual Basic Development Settings
Finish .
starting anew project
, , ( ) File menu New Project CreateProject/Solution )in the Start Page(
, Windows Forms Applications forms((windows, Console ,text window Windows Forms
Control Libraries , .
)1.2( Visual Basic 2008 Express Edition
Create Directory For Solution ( ) Location
( ) . Save All MenuFile , discard Visual Studio ,
Windows Forms Application template WindowsApplication1 , Create Directory For Solution ok ( 2008
) .
)1.3( 2008 , Form1 Solution Explorer IDE
Form Designer design mode ( ) ,
, View menu
-
8/14/2019 ( 2008 ( 1 6
5/108
Toolbars( submenu 28 ( )toggles toolbars ( ) ,
)Layout and Standard) toolbars . Toolbars submenu Customize
, , , , .
Using the Windows Form Designer Display the Designer
( form ) (user interface ) :
Solution Explorer , )view( Solution Explorer
:MusicTrivia.vb
( , , , ) ( ) )control( your form)(
, )Common Controls tab( . ,
, ,
., Properties window ( ( )) IDE ) Solution Explorer( , , View Properties
Window ,F4 , PropertiesBrowser , their role Appearance header Behavior , AZ button
, alphabetical order .
-
8/14/2019 ( 2008 ( 1 6
6/108
)1,4(
retracts to the left edge of the Designer
( )Toolbox window )is docked( )floating(
)fixed, docked, floating( . ( ) Thinking About Properties:
each user interface element ( ) , ,Properties window (
). , , :
inherent characteristics brand name ( , ) terminology ( characteristics) properties ,
, ( , , ) ., intangible ( ) , , , , ( ).
Text (Textbox control )Located My Textbox(Control( , Text ( )the controls caption
Text property )( BackColor , ,
three tabs ( Custom Web )System ( ) , yellow .
-
8/14/2019 ( 2008 ( 1 6
7/108
)15(
font ( )+ , ellipsis button ,
ok , Textbox )Verdana, 14 points, bold
controls Text property , handles perimeter
. (Label ) button CheckBox
, TextBox AutoSize accommodate , , TextBox
MultiLine ( )True vertically : )forms(
bold style ,excess inherits
, , consistent look
)bold or italics( verdana segoe ui
segoe handwritten graphical application color creative
, new discipline Microsofts Expression Studio interface ,
Expression m/expressionwww.microsoft.co , function Multiline
False (,True ) toggles ( / ) TextBox . Multiline TextBox
( )FalseMultiline =( (if Multiline = True) True Text , Enter . WORDWRAP true False .
Scroll Bar , Scrollbars arrow None, Vertical, Horizontal, and(
Both( ( , , ) . ,Vertical , ( ,) ,
)multiline TextBox( Dock Properties window Fill
. F5 ,
)16(
-
8/14/2019 ( 2008 ( 1 6
8/108
Creating Your First VB Application ,
, VB good ,VB new project Windows Application1 TextBox Button )form(
)17( Font (Segoe UI, 9 pt 9, )
Text ) your favorite programming languageEnter( AUTOSIZE
,)True( aligned snap lines , , event handlers ,click of a button ,the selection of a menu command ,the click of a check box . , .
, , , underscore , ,
Word Wrap (on ) .edit>advance>word wrap
)18( editor :
Private Sub Button1 Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click
End Sub [Form1.vb [Design the Form1.vb
( ) ( ) , (
) . ( ) ( ) Button1 Objects list Events list
button Click Button control _Button1
Click subroutine . click Button1 Button1_ Click , ,
, 24 Button control , .events , signature ( arguments )
VB 2008 two arguments : sender argument , e argument
-
8/14/2019 ( 2008 ( 1 6
9/108
, ( )EvaluateLanguage , Handles . Handles
Button1.Click, ,Button1 , Button2 Button2.Click, , ( ,)
. , TextBox keystrokes , (CheckBox
( )) ( ) , ScrollBar , ( ,)
, , Button1 bttnEvaluate :
Private Sub Button1_ Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles bttnEvaluate.ClickEnd Sub , , ,
, , ( )txt, lbl, bttn , bttnEvaluatetxtLanguage
, Button1, Button2, Button3 promote , .
Click Button1 , Visual Basic (End SubPrivate Sub
)Private Sub EvaluateLanguage(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.ClickDim language As Stringlanguage = TextBox1.Text
If language = Visual Basic ThenMsgBox(We have a winner!)ElseMsgBox(language & is not a bad language.)End If End Sub
TextBox language variable )named location( . ( ) , dim ,
language Dim language = TextBox1.Text: ( ,) language variable
Visual Basic OK ( )8 OK ,
2008 , , . .very robust
VISUAL BASIC ToUpper method String class language
variable uppercase language .ToUpper VB ,VB 2008 , ( ) . ComboBox
revise .Making the Application More User-Friendly
)WindowsApplication2( , Create Directory For Solution IDE , File menu Save All Browse
, ComboBox Button )1,9( Evaluate My Choice . text
)1,9( ComboBox , ComboBox Items
Collection Items ( )
-
8/14/2019 ( 2008 ( 1 6
10/108
)110( items ComboBox
text box ComboBox , :
C++C#Visual BasicJavaCobol
ok , , , , text )select your favorite programming language(: . , F5 ,
, tab ( spacebar ) , , ( toolbar ) debug>stop debugging .
, , end subPrivate SubPrivate Sub Button1 Click(ByVal sender As System. Object, _
ByVal e As System.EventArgs) Handles Button1.ClickDim language As Stringlanguage = ComboBox1.TextIf language = Visual Basic ThenMsgBox(We have a winner!)
ElseMsgBox(language & is not a bad language.)End If End Sub
ComboBox , .
Private Sub Form1 Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load
End Sub Visual Basic .
Private Sub Form1 Load(ByVal sender As System. Object, _ ByVal e As System.EventArgs) Handles MyBase.Load
ComboBox1.SelectedIndex = 2End Sub
SelectedIndex ComboBox , , SelectedIndex Visual Basic :
If ComboBox1.SelectedIndex = 2 ThenMsgBox(We have a winner!)
ElseMsgBox(ComboBox1.Text & is not a bad language.)
End If text ComboBox , , ,ComboBox interpreted ,
ComboBox , , DisplayStyle DROPDOWN DROPDOWNLIST ,
bulletproof robust .Understanding the IDE Components
IDE Visual Studio 2008 , ,
The IDE Menu , toolbars
( )disabled edit menu
-
8/14/2019 ( 2008 ( 1 6
11/108
, data menu altogether , XML xml
File Menu
save all ) .
Edit Menu
advanced IntelliSense
> ( Advanced Submenu>Edit) Advanced
View White Space ( )Space characters ) periods Word Wrap .
/ Comment Selection/Uncomment Selection , , .
( ,) ( ). ( )
> ( IntelliSense Submenu>Edit) Edit > IntelliSense , ( ) ( ) , ( )
, , , ( its arguments( : List Members
)on( ( , , , ) . , TextBox1
.TextBox1) ( )1,11( ToolTip text (=)
"TextBox1.Text = "Your User Name: , ( )1,12
TextBox1.TextAlign =
. ( ) ( esc end( enter
)1,11(
-
8/14/2019 ( 2008 ( 1 6
12/108
)1,12(
Parameter Info
Go To Definition InfoQuick
IntelliSense ( ( ) (ToolTip box ) bold
, . Complete Word
Ctrl+ spacebar TEXTB Ctrl+ spacebar )TextBox, TextBox1(
Insert Snippet Insert Snippet , 2008
. > ( Outlining Submenu>Edit)
( ) outlining , Click , reduce
(+) , (+) . -( ) collapse . outlining outlining
, ) off( outlining . substantial amount :
Outlining ExpansionToggle ( ) procedures definition ( ) .
Toggle All Outlining ,
. Stop Outlining
( / ) Start Automatic Outlining .
Collapse To Definitions .
View Menu IDE Toolbars menu " "
, WindowsOutput and Command console ,Output window , VB
Project Menu
( form ,file component )another project Project Properties , Add Reference and Add WebReference NET web )NET components and web components.( Build Menu
-
8/14/2019 ( 2008 ( 1 6
13/108
( ) , Build ,Rebuild All ( executable ( , The Rebuild All ( )the solution . Debug Menu
Data Menu
, 2322 . Format Menu
( ) . .
Tools Menu (Macros ) macros
, IDE options , Choose Toolbox Items
Toolbox Window Menu
Hide devoted , retracted .
.corresponding tab MenuHelp
MSDN Toolbox Window
applications interface retracted
( , )& Toolbars tabsCommon Controls and Menus)(
Solution Explorer Window solution , hierarchical list ,
, , , ( ) Set As Startup Project Add Item
Exclude From Project , , delete .
Properties Window ( Properties Browser)
, , . relatively few , Color
properties Color dialog box , , Collection Editor Dialog box
ComboBox , , >View ,Properties Window properties F4 ,
overlap ComboBox , , . Output Window
, , , >View > Output
. ( and Immediate WindowsCommand)
, .breakpoint ,suspended Immediate Immediate ,
result interrupted ? Math.Log (35)
? The answer is & result.ToString Debug. Write .Debug.WriteLine
. ,
Immediate (a time-honored practice ) VB WriteLine immediate DateDiff() function :Debug.WriteLine(DateDiff(DateInterval.Day, #3/9/2007#, #5/15/2008#))
433 Immediate ( )DateDiff() function . Immediate , ( )
functionality Immediate window Stop End If handler Click event , , , ,
Immediate IDE Debug menu Windows
-
8/14/2019 ( 2008 ( 1 6
14/108
Margin , Debug. Start AddProj . hardly in designing or debugging applications
Error List Window . IDE
, MsgBox() function ()MssgBox . wiggly red line
Name MssgBox is not declared Setting Environment Options
Setting Environment Options . , Tools menu (Options
) Options )113( , , , , , )114( , Created
check box . Temp folder run the Disk Cleanup utility(to claim more space( . VS F5
(Before Building ) (Build And Run page ) Project And Solutions branch >File )Save All(
.
)113(
)114(
console
Using Code Snippets
-
8/14/2019 ( 2008 ( 1 6
15/108
2008 , , , ( )
edit IntelliSense
-
8/14/2019 ( 2008 ( 1 6
16/108
, , My , , : Play method WAV file :
)CountDown.wav\Sounds\C:.Computer.Audio.Play(My :
.Computer.Audio.PlaySystemSound(System.Media.SystemSounds.Exclamation)My plays back Play method WriteAllText method
My object , , My object My :
.ApplicationMy CommandLineArgs property My. Application
command-line arguments
( ) . Info property (DirectoryPath ,) Product Name, Version .Computer My , , Computer.AudioMy.
My.Computer.Clipboard , ,ContainsTextContainsImage,ContainsData, and ContainsAudio, GetText, GetImage, GetData, and GetAudioStream
. PictureBox :
If My.Computer.Clipboard.ContainsImage ThenPictureBox1.Image = My.Computer.Clipboard.GetImage
End If If My.Computer.Clipboard.ContainsText Then
TextBox2.Text = My.Computer.Clipboard.GetTextIf End
My . With :
With My.Computer.ClipboardIf .ContainsImage Then
PictureBox1.Image = .GetImageEnd If If .ContainsText Then
TextBox2.Text = .GetTextEnd If
End With With With
, With , End With Computer My. FileSystem . :
My.Computer.FileSystem FileSystem DeleteDirectory ,DeleteFileRenameFileRenameDirectoryWriteAllText, ReadAllText, ToolTip
CopyFile :My.Computer.FileSystem.CopyFile(sourceFileName As String , destinationFileName As _ String ,overwrite As Boolean )
overwrite argument , usual copy animation ,as the file is being copied /
, ( )overloaded forms , , .
Forms )forms( , , .
Settings , ( an XML configuration file) xml
Settings .User
, )User component( CurrentPrincipal property
( credentials) Web Services . .
, .Framework My , My substitute Framework , Framework ,
, . (, )15 :My
Dim files As ReadOnlyCollection( Of String )files = My.Computer.FileSystem.GetFiles( "D:\Data" , True , "*.txt")
etFilesG files collection pathnames :Data\D , , GetFiles ( )oussynchron
)block( , 15 . my , , (
productivity( My , . My ( ) , penalty My ( )
Framework
-
8/14/2019 ( 2008 ( 1 6
17/108
)2(
Variables and Data Types ( )
, , ( ) )scope( )lifetime( ,
( )
: ( )
native
arrays :
immediate window Debug.WriteLine MsgBox
Variables Username ( ) Discount 0.35 DiscountUsername
(( )0.35) ( ) ( ( )alphanumeric) 0.35 , (" ") , , ,
, , 2008 , CommonLanguage Runtime (CLR) , .
, , Dim As .Dim Amount As Decimal
Decimal integer noninteger $24,500 button
:Private Sub Button1_Click( ByVal sender As System.Object, ByVal e As System.EventArgs)_ Handles Button1.Click
Dim Amount As DecimalDim Discount As DecimalDim DiscountedAmount As DecimalAmount = 24500Discount = 0.35DiscountedAmount = Amount * (1 - Discount)MsgBox( "Your price is $" & DiscountedAmount.ToString)
End Sub 0.35 Discount
, )option strict is on( ,) off( treats )Double value( ( ) Double .Decimal
Decimal type nt = 0.35DDiscou
D , )type characters( )financial calculations(
Discount Discount . 0.35 :
0.35)-DiscountedAmount = 24500 * (1 Discount )program is up-to-date.Entirethe(
( ) Declaring Variables ,
. , Discount
, Discount . BASIC )intensely criticized( , , , in advance ,
, Date . VB 2008 ,
VB 2008 . , VB ( )
. Dim As , :
Dim meters As Integer StringAsgreetingsDim
meters 3 1002 greetings , , :
StringAs, CardNumDecimalAs, AmountInteger AsQtyDim commas
DoubleAs, Volume, AreaInteger AsLength, Width, HeightDim Integer .Double fractional
)floating-point values( greater accuracy . , Private, Public, and Static access modifiers
,
-
8/14/2019 ( 2008 ( 1 6
18/108
Dim )module( Count (subroutine , ) , Count
. Naming Conventions-Variable
( ) : letter digits punctuation symbols underscore character 255 characters scope
. VB 2008 case-insensitive myAge, myage, and MYAGE
. Variable Initialization
2008 . Integer ( ) 3,045= 3045Integer AsdistanceDim
:
Dim distance As Integer distance = 3045
, Dim quantity As Integer = 1, discount As Single = 0.25
( Type Inference) )trademark features of BASIC(
, , , . 2008 ,
, Integer : Dim count = 2999 , GetType method . TOSTRING
property System.Int32 :Immediate windowDebug.WriteLine(count.GetType.ToString)
count Integer type Value of type Date cannot be converted to Integer .
subsequent inference )module(Option Infer Off
) off( ,)option strict( ) off( Object variable , . )option strict on( , :
As clause Option Strict On requires all variable declarations to have an .
Types of Variables :
Numeric String
Boolean Date ( Object)
( ) , disadvantages
Integer variables integers . .necessary conversions
. , . ,
( ) . Numeric Variables
:o (Integers )o Decimalso ( ) Single, or floating-point numbers with limited precisiono Double ( ) floating-point numbers with extreme precision
( ) accurately exclusively .scientific calculations
.whole numbers . ( ) ) trade-off( precision execution(
). less-precise data types are manipulated faster
Variablesinteger , .
, )anticipate( ,
Long Short . MINVALUE MAXVALUE minimum maximum
respectively represented corresponding (Short (Int16 (Integer (Int32 (Long (Int64 )reverse( . Integer
offending wiggly .
-
8/14/2019 ( 2008 ( 1 6
19/108
Dim shortInt As Int16Dim Int As Int32Dim longInt As Int64
Debug.WriteLine(Int16.MinValue)Debug.WriteLine(Int16.MaxValue)Debug.WriteLine(Int32.MinValue)Debug.WriteLine(Int32.MaxValue)Debug.WriteLine(Int64.MinValue)Debug.WriteLine(Int64.MaxValue)shortInt = Int16.MaxValue + 1
' ERROR, exceeds the maximum value of the Short data type( , (Int = Int16.MaxValue + 1' OK, is within the range of the Integer data type( 32 ( ( Int = Int32.MaxValue + 1
' ERROR, exceeds the maximum value of the Integer data type( integer , (Int = Int32.MinValue - 1
' ERROR, exceeds the minimum value of the Integer data type( integer , ( longInt = Int32.MaxValue + 1' OK, is within the range of the Long data type( 64) (longInt = Int64.MaxValue + 1
' ERROR, exceeds the range of all Integer data types ( , ( WriteLine ,
, :in type Short Constant expression not representable) ,))short( .
data type ( ) Byte (Byte)) byte 1 ) 0 255Signed Byte (sbyte))
byte 1 ) 128- 127
Short (Int16)) 16 byte 2 ) 32768- 32767Integer (Int32)) 32 byte 4 ) 2,147,483,648 2,147,483,647
Long (Int64)) 64 byte 8 ) 9,223,372,036,854,755,808 9,223,372,036,854,755,807 )Unsigned Short (UShort)
16 byte 2 ) 0 65,535
Unsigned Integer (UInteger)) 32 bytes 4 ) 0 4,294,967,295
Unsigned Long (ULong)) 64 bytes 8 ) 0 18,446,744,073,709,551,615
Single Precision (Single)( ( bytes 4 ))
3.402823E38 1.401298E-45 1.401298E-45 3.402823E38
0 ( )
Double Precision (Double) ( ( bytes 8 )
( ) 1.79769313486232E308 4.94065645841247E-324 4.94065645841247E-324 1.79769313486232E308
Decimal (Decimal) ( ( bytes 16) ( 0 )28
1: byte= (8( )bit( 8 ( )
: -1 1 31 -2 32 127 -3 127 .
)charactersUnicode( 2 Precision Numbers-and Double-Single
Single Double single-precision double-precision . . .
3 / 1 (. . .0.333333 )3 256 256MB RAM 3 ( truncated( ( ) :truncation :
Dim a As Single , b As Double :
a = 1 / 3Debug.WriteLine(a)
:immediat.3333333
,decimal point Ctrl+ Break :a = a * 100000Debug.WriteLine(a)
:immediat33333.34
rounded a 100,000 0.3333334:
-
8/14/2019 ( 2008 ( 1 6
20/108
.(0.3333333) multiplied it by 100,000 Singlevariable , (error propagation ) . errors propagate
)tolerate( Single )cumulative errors( ( ) .significant )double-precision numbers( .b
:b = 1 / 3Debug.WriteLine(b)b = b * 100000Debug.WriteLine(b)
immediat:0.333333333333333,33333.3333333333
.
: 0 .1 ( )convenient , ,)(on and off ,As a matter of fact (bits )zeros and ones .
)binary numbering system( decimal system , , , whole or fractional )( ( ,
) decimal numbering system , ..binary system
.illuminating example a single-precision variable b double-precisionvariable :
Dim a As Single , b As Doublea = 0.03007b = 0.03007
(Debug.WriteLine(a - b : 6.03199004634014E-10-
0.000000000603199004634014 , .
Eventually mathematical notation , . 1/3 3 ) .1(
1/3 ,3 1/3 , 3 (1/3) ., ba Single Double , (: )
a = 3b = 1 / aDebug.WriteLine(a * b)
as Decimal ( )0.999999999999999999999999999 28 .
The Decimal Data Type (integers ) 16 )bytes 16( ( ( ) ,) of 10 is scaled by a power(10
( scaling power) , 0 28 0 )1( (0^10 ( ) ) . ( ( )10 28 28^10
28 ( ) 28 . (integer 79,228,162,514,264,337,593,543,950,335)
, ( ) )0( ,)0^10( 28 (7.9228162514264337593543950335 ). (
)8 .extreme accuracy ((factor ) ,28) )(01. . .0.00( 27
)1 . ,)you have at your disposal( .
, ( ) integers 235.85 23585 )scale down( (100 )2^10 . ( )100 )102( ( ,) )100(
100 , 12.4051 * 328.558: integers , . , 124051 * 328558: , ( Scientific
view( 40,757,948,458 4,075.7948458 .,Decimal data type :
Dim a As Decimal = 328.558DDim b As Decimal = 12.4051DDim c As Decimalc = a * bDebug.WriteLine(c.ToString)
D converted , )fractional part( Double. ( )Strict option is on
Decimal type D ( .).type character (truncated ) 4,075.795
. , , ideal .financial applications .Doubles ( )
)Type Characters(
C char "A"c=StringAschDim
-
8/14/2019 ( 2008 ( 1 6
21/108
D or @ Decimal type = 12.99DDecimalAspriceDimR or # Double type = 3.14 RDoubleAspiDimI or % Integer type Dim count As Integer = 99IL or & Long type Dim distance As Long = 1999L
S Short type Dim age As Short = 1SF or ! Single type = 74.99FSingleAsvelocityDim
Infinity and Other Oddities Framework (NAN: ) )Infinity(, NAN , ( )confirm , . ,
NAN , (Not a Number (NAN.((NAN). , (NAN). ,
.. . Log() function ,
, . , annoying , ,(throwing an exception ) ,
. , : ,
, 2008 ( ) (: .) TOSTRING method .Infinity: , Double variable :
Dim dblVar As Double = 999Dim infVar As DoubleinfVar = dblVar / 0MsgBox(infVar)
Infinity , ( ) , . make sense .
yield non-number , :
Dim largeVar As Double = 1.0E+299Dim smallVar As Double = 1.0E-299Dim result As Doubleresult = largeVar / smallVar MsgBox(result)
1E299 10 299 1E-299 10 -299 10 1E299.
, . ( ) . 0 / 0 . :
Dim var1, var2 As DoubleDim result As Doublevar1 = 0var2 = 0result = var1 / var2MsgBox(result)
( ).NAN :
Dim result As Doubleresult = result + resultresult = 10 / resultresult = result + 1.0E+299MsgBox(result)
Testing for Infinity and NAN . NaN IsNaN IsInfinity . Integer
.. TrueIsInfinity IsNegativeInfinity and IsPositiveInfinity. , ,
.Dim var1, var2 As Double
Dim result As Doublevar1 = 0var2 = 0
result = var1 / var2If Double .IsInfinity(result) ThenIf Double .IsPositiveInfinity(result) Then
MsgBox( "Encountered a very large number. Cant continue" )Else
MsgBox( "Encountered a very small number. Cant continue" )
-
8/14/2019 ( 2008 ( 1 6
22/108
End If Else
If Double .IsNaN(result) ThenMsgBox( "Unexpected error in calculations" )
ElseMsgBox( "The result is : " & result.ToString)
End If End If
Byte Variables . ( ,)
0 .255 image .,sound files , )charactersUnicode( 2 . :
Dim n As Byte n , .,
:Dim A As Byte , B As ByteA = 233B = 50
overflow exceptionDebug.WriteLine(A + B)
immediat windowA first chance exception of type 'System.OverflowException' occurred in WindowsApplication1.exe
B = A + B: 283 .
with BytesBoolean Operations overflows ,AND, OR, NOT, and XOR .
)True or False( ( ,AND, OR, NOTand XOR( . 200199 AND 192 1100100011000111
( sebitwi )0=01,1=10,1=00 AND 11000000 .192 Byte data type VB 2008 (Signed Byte data type SByte)
128 .127 bit 1 0 ( )0
sBoolean Variable
( / )True/False in essence (integers ) (1 )True 0( )False , Dim failure As:
Boolean False , Dim failure As Boolean = False :
ments ... other state
If failure Then MsgBox(Couldnt complete the operation) And, Or, Not, and Xor Not (toggles / ) .
toggle(running = Not running( running True False . :Dim running As BooleanIf running = True Thenrunning = FalseElserunning = True
If End , ( ) ReadOnly and
Hidden ) (True( ( presumably) )If ReadOnly Or Hidden Then
MsgBox( "Couldnt open the file" )Else{ statements to open and process file}
If End if OR ( )parenthesized( negated Not operator If clause negation ,True
ReadOnly )True( (Hidden )is False ( ( eFalsOr True(NotIf() ( )= :
TrueNotIf ( )= )False(
String Variables , StringAssomeTextDim: someText
2 ( 2 ) :Dim aString As String
aString = "Now is the time for all good men to come " & " to the aid of their country"aString = ""aString = "There are approximately 25,000 words in this chapter"aString = "25,000"
, .,
-
8/14/2019 ( 2008 ( 1 6
23/108
Dim aNumber As Integer = 25000Dim aString As String = "25,000"
aString ,2,5 00,0, aNumber ( ,) aString aNumber , necessary conversions Strict option ) off(
.
Character Variables 2 ,)2bytes( ,)(Unsigned Short integers (UInt16(
CChar() function CInt() function , Char .Char Aschar1, char2Dim , Aa
Dim : char1 As Char = "a", char2 As Char = "ABC"Debug.WriteLine(char1)Debug.WriteLine(char2)
Strict option , char1 and char2 Dim Ac=Char As, char2ac=Char Aschar1Dim:
, ANSI) ))Americam Ntional Standard Institute( , :65
Debug.WriteLine(Convert.ToInt32( "A"c)) 945 Unicode value ,960
. , , . Char data type ., password
, Dim password As String , ch As Char
Dim i As Integer Dim valid As Boolean = FalseWhile Not valid
password = InputBox( "Please enter your password" )For i = 0 To password.Length - 1
ch = password.Chars(i)If Not Char .IsLetterOrDigit(ch) Then
valid = TrueExit For
End If NextIf valid Then
MsgBox( "You new password will be activated immediately!" )Else
MsgBox( "Your password must contain at least one special symbol!" )End If
End While