.


:




:

































 

 

 

 


4.2.2-2. , () .

1) VS.

2) , -2.2-2.

2.2-2.

2.2-2 (.4.2.2-4).

, . , , , .

, ListBox.

ListBox , . MultiColumn. , ColumnWidth .

 

 

. 4.2.2-4. 4.2.2-2

 

.

Items . OK, , ListBox .

3) (. 4.2.2-5).

 

Public Class Form1 Dim Birds AsShort Dim Insects AsInteger Dim WorldPop AsLong Dim Price As Single Dim Pi As Double Dim Debt As Decimal Dim RetKey AsByte Dim UnicodeChar As Char Dim Dog As String Dim Flag As Boolean Dim Birthday As Date Private Sub ListBox1_SelectedIndexChanged(ByVal sender As _ System.Object, ByVal e As System.EventArgs) _ Handles ListBox1.SelectedIndexChanged Select Case ListBox1.SelectedIndex Case 0 Birds = 12500 Label3.Text = Birds Case 1 Insects = 37500000 Label3.Text = Insects Case 2 WorldPop = 4800000004 Label3.Text = WorldPop Case 3 Price = 899.99 Label3.Text = Price Case 4 Pi = 3.1415926535 Label3.Text = Pi Case 5 Debt = 7600300.5 Label3.Text = Debt Case 6 RetKey = 13 Label3.Text = RetKey Case 7 UnicodeChar = " " Label3.Text = UnicodeChar Case 8 Dog = "pointer" Label3.Text = Dog Case 9 Flag = True Label3.Text = Flag Case 10 Birthday = #3/1/1963# Label3.Text = Birthday End Select End Sub     Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) HandlesMyBase.Load ListBox1.Items.Add("Short"): ListBox1.Items.Add("Integer") ListBox1.Items.Add("Long"): ListBox1.Items.Add("Single") ListBox1.Items.Add("Decimal"): ListBox1.Items.Add("Byte") ListBox1.Items.Add("Char"): ListBox1.Items.Add("String") ListBox1.Items.Add("Boolean"): ListBox1.Items.Add("Date") End Sub Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles Button1.Click End End Sub End Class

 

. 4.2.2-5. 2.2-2

 

, , , , .. . , , . , . , , .

,

PrivateSub ListBox 1_ SelectedIndexChanged () SelectCase, 4.4.

4) .

 

. 4.2.2-6. .2.2-2

 

, . 4.2.2-6.

11 . .

5) Integer.

37 500 000. , , Short, Integer Long .

6) Date.

3/1/1963.

7) , VB , .

8) ,

9) , ListBox1_Selected_IndexChanged().

10) Form1_Load() (.4.2.2-5).

ListBox .

11) ListBox1_SelectedIndexChanged() , . SelectCase. , SelectCase , Text Label3 .

, , . , , , . , VB , , . , , .

12) - , , .

 


. . , (, , π, ), , .

, . , . , . Const, :

 

Const _ AS =_

 

,

 

Const Pi As Double = 3.14159265 Label1.Text = CStr(Pi)

 

Pi, 3.14159265. , , .

, . .

 

Dim WdAs Single = 100 Dim FnAs String = "" Dim Eps As Double= 0.0001

 

, , Dim, Public Private:

 

Dim x, y, z AsDouble = 1 '

 


4.2.3. ,

 

, . , , , . . :

;

;

.

 

, , 4.4.

 

4.2.3-1

+
-
*
/
\ ( )
Mod
^

 

4.2.3-2

() 1
2
^ 3
+ 4  
*; / 5
\ 6
Mod 7
+; - 8

 

. + . - . , , , , ( ), , .

(, ), . . , , , .4.2.3-1.

, . . , , (. 4.2.3-2).

. M od , .

4.2.3-1. , +, -, * /.

1) t VS.

2) , 2.3-1. .

.

3) 2.3-1 (.4.2.3-1).

 

 

.4.2.3-1. 4.2.3-1

 

4) 2.3-1 , , , . , , .

5) 2.3-1 RadioButton (). , . ( Checked True) , False.

6) , , , GroupBox. , RadioButton.

7) . Sub Button1_Click(). , .4.2.3-3.

8) Sub Button2_Click() c End (. 4.2.3-3).

9) , .

. , , , , , .

10) 1 100,

11) <Tab > .

12) ( ).

13) 2 17.

 

 

. 4.2.3-2. 2.3-2

 

14) . , , .

117, 4.2.3-2.

10) , , . ( .)

. , . ( , .) Double, .

11) 1 100, 2 0, , .

12) , . VB Infinity (). VB.

13) .

.

14) , , , (.4.2.3-3). , . , , , Form 1.

15) , Double:

 

' FirstNum SecondNum Dim FirstNum, SecondNumAs Double

 

Double , , - , , , . . FirstNum SecondNum Double, , .

 

Public Class Form1 Dim FirstNum, SecondNum As Double Private Sub Button2_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles Button4.2.Click End End Sub Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click FirstNum = TextBox1.Text SecondNum = TextBox4.2.Text If RadioButton1.Checked = True Then TextBox3.Text = CStr(FirstNum + SecondNum) End If If RadioButton4.2.Checked = True Then TextBox3.Text = CStr(FirstNum - SecondNum) End If If RadioButton3.Checked = True Then TextBox3.Text = CStr(FirstNum * SecondNum) End If If RadioButton4.Checked = True Then TextBox3.Text = CStr(FirstNum / SecondNum) End If End Sub End Class

 

. 4.2.3-3. 2.3-1

 

, , FirstNum SecondNum.

 

' FirstNum = TextBox 1. Text SecondNum = TextBox4.2.Text

TextBox Text, , , .

, , , , . :

 

' If RadioButton1.Checked = True Then TextBox3.Text = CStr(FirstNum + SecondNum) End If

 

. , , Checked. True, . Checked False, .

 

. , , . (), . 4.2.3-3, . () MS.NETFramework , , .

, .NETFramework , Imports. , () System. Math.

 

. 4.2.3-3 System.Math. x , , . - , ImportsSystem.Math .

 


 

4.2.3-3

()
Abs (x) x (.. , Abs(-5)=5)
Acos(x)
Asin(x)
At a n(x) x.
Ceiling(x) ,
Cos(x) x
DivRem(x,y,r) (r)
E o 4.2.71828182845905
Exp(x) -
Fix(x) ( )
Floor(x) ,
Int (x) ( )
Log(x[,n]) n
Log10(x)
Max(x, y)
Min(x, y)
PI π 3.1415265358979
Pow(x, y) x y
Rnd() [0;1]
Round(x, n) n
Sign(x)
Sin(x) x
Sqrt(x)
Tan(x) x
Truncate(x)

 

.

Log(x[, n]) ( ) ( n):

 

Dim result As Double = Math.Log(10) ' = 4.2.30258509299405 result = Math.Log(1000,10) ' = 3 result = Math.Log10(1000) '=3

 

Min(x,y) Max(x,y) , , .

Floor(x) , , Ceiling(x) , . Truncate(x) , , Ceiling(x), :

 

result = Math.Ceiling(4.2.5) ' = 3 result = Math.Floor(-1.5) ' = -2 result = Math.Truncate(-1.5) ' = -1

 

DivRem (x, y, r) (r) :

 

Dim remainder As Long Dim result As Long= Math.DivRem(20, 3, r) ' = 2

 

, , Logab = Log (b)/ Log (a).

.

, , . () VB Microsoft.NETFramework, .

, . . . , ImportsSystem. Math, , , Math.Sin (x).

, .4.2.3-3 (E PI).

4.2.3-2. ,
System. Math .

1) .

.

2) 4.2.3-2 ( ).

.

3) Button .

4) TextBox .

5) Text .

6) .

7) , PublicClass Form 1, : ImportsSystem. Math

Imports , . - , , PublicClassForm 1, VB . , , System. Math, , , .NETFramework .

8)
Button 1_ Click () PrivateSub EndSub :

 

Dim rg As Double Dim Result As Double Arg = TextBox2.Text Result = Sqrt(Arg) TextBox1.Text = Result

 

Double Result, Sqrt () , TextBox 2. Text, Result Text TextBox 1 , .

9) , . ().

10) .

11) 625 TextBox 2. Text.

12) .

VB 625

(. 4.2.3-8).

 

 

 

. 4.2.3-4. 2.3-2

 

, , (), .

VB
(. 4.2.2-1) MinValue MaxValue. , :

 

' , ' Double. TextBox1.Text= Double.MaxValue ' = 1.79769313486232 +308

 

, , , Single Double, , .

Epsilon ( ) , :

 

TextBox1.Text= Single.Epsilon '= 1.401298E-45 TextBox4.2.Text= Double.Epsilon '= 4.94065645841247E-324

 

Single Double, , , , , IsNegativelnfinity (), IsPositivelnfinity () IsNaN ().

Microsoft. VisualBasic. Interaction , Beep (),
InputBox (), MsgBox ()
. , .

, . 4.9, System. String System. StringBuilder. NET. , .

& (+):

 

Dim s As String = "ABC" s = s &" D " ' - ABCD

 

, , Nothing , , - . , :

 

Dim s AsString ="" ' 0 Dim t AsString ' , ' = Nothing

 

, VB , , . , vbCrLf, vbTab , Microsoft.VisualBasic.Constants. , .


Microsoft.VisualBasic.ControlChars. , ( Imports ). ,
Microsoft. VisualBasic. Constants , vb.

ControlChars Back, Cr, CrLf, FormFeed, NewLine, NullChar, Quote, Tab VerticalTab. .4.2.3-4.

 

 


 

4.2.3-4

Constants ControlChars
vbCrLF CrLF Chr(13)+Chr(10)
vbCr Cr Chr(13)
vbLf Lf Chr(10)
vbNewLine NewLine Chr(13)+Chr(10)

, . ,

 

Dim s As String = ""&ControlChars.NewLine s = s &"" &" " &vbCrLF

Microsoft. VisualBasic. Strings VB, Asc, Chr, ChrW, Filter, Format, FormatCurrency, FormatDateTime, FormatNumber, FormatPercent, InStr, InStrRev, Join, LCase, Left, Len, LTrim, Mid, Replace, Right, RTrim, Space, Split, StrComp, StrReverse, Trim UCase. , , . 4.9.

 

 

4.2.4.

 

VB , , .

.

. VB VS .

-, , , , ,

Integer → Long, Decimal, Single, Double.

-, ( ) , , ,

Single → Integer;

Double → Integer.

, , ,

Option Strict On

Option Explicit On.

, (OptionStrictOn) , , .. . (OptionExplicitOn) .

, .

VB, , , :

CBool (x) - . x .

CByte (x) - Byte. x .

CChar (x) - . x , 0 65 535.

CDate (x) - Date. x .

CDbl (x) - x Double.

CDec (x) - x Decimal.

CInt (x) - x Integer. x , .

CLn g (x) - Long. x CInt (x).

CShort (x) - x Short.

CSng (x) - x Single.

CStr (x) - String.

 

VB VB, .NET.

Microsoft. VisualBasic. Conversion , :

Int () Fix () . , Double . Double. Double Integer Long. , . Int () Fix () . , Int () , Fix () . , Int(4.5) Fix (4.5) 4, Int (-4.5) 5, Fix (-5) -4.

Val (x) x Strin g Double.

Str (x) , .

 

Dim Number As Single Number = Int(99.8) ' -99 Number = Fix(99.8) ' -99 Number = Int(-99.8) ' -100 Number = Fix(-99.8) ' -99 Number = Int(-99.2) ' -100 Number = Fix (-99.2) ' -99

Long Integer . . , CInt (1.5) CLng (1.5) 4.2. 1.4, 1. , -1.5 -2, -1.4 -1.

, , , . , ., , (, CDbl () CSng () , Int () Fix ()).

Val (), CDbl () CSng (). . CDbl () CSng () CLng () CInt ().
CDbl ()
Double,
CSng () Single. , . CDbl () CSng () ,, Val () .. Val () , - Double. , , . , , .

, Val () .4.2.4-1.

, Val (x) Str (x) Val (x) , Dbl (x) , .

 

:

Dim aDblAs Double Dim anIntAs Integer aDbl = 2345.5678 anInt = CInt (aDbl) ' anInt 2346. Dim aDbl1, aDbl2 As Double Dim aLng1, aLng2 As Long aDbl1 = 25427.45: aDbl2 = 25427.55 aLng 1 = CLng (aDbl 1) ' aLng 1 25427. aLng 2 = CLng (aDbl 2) ' aLng 2 25428. Dim aDouble1, aDouble2 As Double Dim aSingle1, aSingle2 As Single aDouble1 = 75.3421105: aDouble2 = 75.3421567 aSingle1 = CSng(aDouble1) ' aSingle1 5.34211. aSingle2 = CSng(aDouble2) ' aSingle 2 75.34216. Dim aDoubleAs Double Dim aStringAs String aDouble = 437.324 aString = CStr(aDouble) ' aString 437.324. aDouble = CDbl("437,324") ' aDouble 437,324. aDouble = Val ("437.324") ' aDouble 437.324.

4.2.4-1

" 1 2 34569" 1234569 1234569.
" 1 2 345,69" 12345 ,, 12345.
" 1 2 345.69" 12345.69 , . , 12345.69.
" 12 34569number" 1234569 n, , , 1234569.

. Round (). . . Round() ( ). , Round(1.15,1) 1.4.2. , , 1.15 1.1. : Fix(10*n)/10.

10 10, . : Fix(10^*n)/10^.

, Fix(), Int(), .

Microsoft.VisualBasic.String , Format(x, ) - x , . .

 

. 4.2.4-2

#
0
#.### . 3 ,
0.000 . 3 ,
E

Format () . 4.2.4-2.

 

Format () , , Str () . , , , . Str (), . ,

 

Format(2, "000000") ' 000002 Format(10, "0.00") ' 10.00

 

VB .NET ToString(x), . , , ,

 

Dim myValueAs Double = 123.45 Dim res As String = "The final value is"&myVaIue.ToString()

 

ToString(x) , . , , .

 

' PI 5 ( 6 ) Dm d As Double = Math.PI TextBox1.Text= d.ToString("G6") ' - 3.14159 - 6

 

ToString (), :

 

Dim intValueAs Integer = 12345 TextBox1.Text = intValue.ToString("##,##0.00") '= 12 345.00 Dim sngValueAs Single = 12345.5 TextBox4.2.Text = sngValue.ToString("##,##0.00") '= 12 345.50

, .

, Str () CStr (), ToString () Convert:

Dim As Double = 3.14 Dim As String = Convert.ToString()

 

, Val(), CDbl (), CInt (), Convert ToDouble (),
ToInt 32()
. IntelliSense Convert.

 

 

4.2.5.

 

1) :

.

2) 4.2.5:

:

VB 4.2.5, :

: , , .

: ,

S .

:

>0, >0, C>0, +>, +C>, +C> .

4.2. 5 :

;

, ;

, .

 

3) :

:

= + + ; S = ( ),


 

, :


4.2.5. ;

;


;

( );

;

;

.

 

,

.4.2.5-1.

 

 

. 4.2.5-1. 4.2.5

 

4) ():

4.1) :

VS;

, .. .

:

WindowsForms .

 


4.2.6.

.

VS 4.2.6 ,

Form1. .

4.2) :

, , , , . , . VS, . , , . 4.2.5-1.

, , .

Button1, Button. VS Button1. , .

. VB , , .

Button2, ( ) Button, Form1. . , , , .

. , Button2 .

, , , , .

, <Del> .

. , . 4.2.5-2.

, Label.

VS Label1.

Label1 .

 

 

. 4.2.5-2.

 

, Label.

VS Label4.2.

Label3, Label, Label3.

 

 

. 4.2.5-3.

 

Label4, Label .

, .

,
. 4.2.5-3.

Label, Label5.

Label6.

, .

, ,

TextBox. VS TextBox1.

TextBox1 , Label2.

TextBox2 TextBox3, Label3 Label 4.

TextBox4 TextBox5, Label5 Label6 .

,
. 4.2.5-4.

 

 

 

. 4.2.5-4.

 



<== | ==>
4.2.2-1. , . |
:


: 2018-10-18; !; : 163 |


:

:

, .
==> ...

1551 - | 1323 -


© 2015-2024 lektsii.org - -

: 0.324 .