Title: ?2? VB.NET????
1?2? VB.NET????
2- 2.1 ??????
- 2.2 ??????????
- 2.3 ???????
- 2.4 ??????
- 2.5 ??????
- 2.6 ???????
????
32.1.1 ??????
2.1 ??????
?????????????,???????????????????????
4- Public Class Form1
- Private Sub Button1_Click( ByVal sender As
System.Object, ByVal e As _ -
System.EventArgs) Handles Button1.Click - Dim a, b, c, maxside As Single
- Dim perimeter, area As Double
- a Val(TextBox1.Text)
- b Val(TextBox2.Text)
- c Val(TextBox3.Text)
- If a b gt c And b c gt a And a c gt b
Then '?????? - perimeter a b c
- Dim p As Double perimeter / 2
- area Math.Sqrt(p (p - a) (p -
b) (p - c)) - maxside Math.Max(a, Math.Max(b, c))
- Label2.Text "???????" a "?"
b "?" c vbCrLf - Label2.Text "???????"
Format(perimeter, "0.00") vbCrLf - Label2.Text "???????"
Math.Round(area, 4) vbCrLf - Label2.Text "????????" maxside
vbCrLf - Else
52.2 ??????????
62.2.1 ???????
- ????????????????
- ?????????????????????
- ??????
(1)????????,????????????????
???????????,????? (2) ????VB.NET????????Dim?If?For
?? (3)????????????????,????????? (4)?????????????,
XYZ,xyz,xYz??????????????????????,????????????,???
??????????????????
72.2.2 ????
???????????????? ??????????????
8????????
91. ???
- ????Integer(??Short ?Long)
- ?? n
- ??123?-123?123?123i?????
- 123.0?1,234?????
- ????Single (??Double )
- ?? n.n?nEm?n.nEm
- ??123.45?0.12345E3 (0.12345103 )
10- (1)??
- ???????????????
- ???????,???????
- ????n
- ? 123?123?123 ?????
- 123.0 ?1,230 ??
- ???? On
- ?????Hn
11- (2)??
- ??????????????
- ?????????,??????
- ????? Single?!, ???Double? ?
- ?? ?? E ??
- ?? E ??
- ?? E????????? ?????????
- ? 123.45? 123.45?0.12345E3?
- 12345E-2 ? 0.12345E3 ?? ????
122. ???
- ???(Char)????Unicode??
- ?????????????,?????.
- ?? "??"
- ?? " a"?" 2"?"?"??
- ???(String)?????????
- ?? "???"
- ??,"12345"?"abcde123"?"????"??
13- ??
- (1)???????????????????
- (2)""?????,?" "??????????
- (3) ?????????,??,??????123"abc,???????????,?
"123""abc"?
14??????????????
- 3xy ' ????
- y - z ' ??????????
- Wang Ping ' ???????
- Dim ' VB.NET????
- Cos ????????,? ???,??????
153. ????
- ?????(Boolean)
- ??????????
- ?(True)??(False)
- ??
- ????????????????,0 ???False,?0????True?
- ????????????????, False???0,True???-1?
16? 3-6-93 1320 12/18/1999
172.2.3 ??
- VB.NET??????
- ???? ????????????
- ???? ????,?????????
- Const ????? As ?? ???
- ? Const PI3.14
- ???? ?????????????
- ??vbCrLf ??/?????
- ?? ????????????
- ?????.???
- ? Color.Red
182.2.4 ??
1.????? ???????????????????? ?????????
???? ??????? ????? ???????????? ????
????????????
VB.NET????????,????????
191. Dim??
???????????,??????? ???? Dim ??? As
????? As???? ??????Object?? ????? ??????????
????Dim??????????? ????????,????As???,
?????,??????????? ??Dim m,n,j As Integer,x,y As
Single,k
202. Static??
?Static?????????? ??????????????.
????Static ??? AS ??
??Dim?Static??????
Sub Form_Click() Dim Count CountCount 1
Label1.Text "?????" _ Count "?" End Sub
Sub Form_Click() Static Count CountCount
1 Label1.Text "?????" _ Count "?" End
Sub
?Dim?????,????????????
212.2.5 ??????
????????,???????,?????????
- ??? ?????????,????????.
- ????? ???????Dim?Static???????,?????????
- ????? ???????????Dim?Private????,????????????
- ???? ?????Public????,????????????????
22??????
?????????????????????? Public Pa As integer
' ???? Private Mb As string 10 '
??/????? Sub F1( ) Dim Fa As
integer ????? End Sub Sub F2(
) Dim Fb As Single ????? For i1
to 10 Dim k ???
Next i End Sub
232.3 ???????
??????? ???? ???????????
?? ????????????? ???
??????????? ?? ???????????
??
241. ?????
???????????????????,??????????,??????????????? ??
30-True ???31,???True????-1,False????0 False
10 "4" ???14
?510 mod 10 \ 9 / 32 2 ??10
25- ? ?????????????,?????,??????????
262.????????
?????????,?????????? ????????????
1)??????????? 2)???????,??????,???????? ?????
????? 3)????????,???????,????? ??
?? ?? ?? "ab"
123 "ab123 " "ab" 12 ?? "12"
456 " 12456 " "12" 456 468 "12"
True "12True" "12" True 11 ??
??????????,??????????
27- ?????????????,?????????????,???????
28- Public Class Form1
- Private Sub Button1_Click(ByVal sender As
System.Object, _ - ByVal e As System.EventArgs)
Handles Button1.Click - Dim a, b As Double
- a TextBox1.Text
- b TextBox2.Text
- TextBox3.Text a b
- End Sub
- Private Sub Button2_Click(ByVal sender As
System.Object, _ - ByVal e As System.EventArgs)
Handles Button2.Click - TextBox4.Text TextBox1.Text
TextBox2.Text - End Sub
- End Class
293.?????
???????????????, ???True?False?
??? ? ??
" ABCDE " " ABR " False
gt " ABCDE " gt " ABR " False
gt " bc" gt "abcde " True
lt 23lt3 False
lt " 23 " lt " 3 " True
ltgt " abc" ltgt "abcde " True
Like "ABCDEFG" Like "DE" True
304.?????
??????Not???????,?????????,?????????????,??????Tru
e?False?
31? ?????60xlt70?VB.NET??????
????????,????????? ??(Age)??19?,?????(Total)??
285?, ??????100?,???????? Agelt19 And Totalgt285
And ( Mark1100 Or Mark2100 Or Mark3100
) ???????????
322.3.2???
- 1.?? ????????????????
- 2.????
- ??????? ?a -b????
- ?????? ?x ??y ???xy
- ????????(??????)
- ???????????????,??????
- 3 ???
- ?????gt?????gt?????gt????
33???????
abcd/e/f/g ? abcd/(efg)
sin(453.14/180)(exp(10)log(10))/sqr(xy1)
342.3.3 ????
?? ?????? ???. ??????
?????????,?????????????? ???????????VB??????????
. ?? x!0.1 ' x??????,??0.1 TextBo
x1.Text "" ' ???????? TextBox1.Text
"????VB.Net "
35??????
???????,?????????,??????????????? ???
??????? ??? ???????????,???????????????,????????
????????- ??\?/??
??a b4 ??? a a(b4)
36????????
- ?? sum x ??? sum sumx
- ?? n 1 ??? n n1
- ?????? ?? ???
????,TextBox1????? TextBox1.Text " VB.NET "
vbCrLf TextBox1.Text "??????"
372.3.4 ???????????
- 1. ??????
- ??????????????
- ???????????????????
- IntegerltLongltSingleltDoubleltCurrency
- 2. ??????
- ??????????
382.4 ???????
2.4.1 InputBox?? ???????,??????,???????????? ??
InputBox(??,??,???,x????,y????)
?????????? ??????,???? ???????vbCrLf?
39 2.4.2 MsgBox??
???????,???????????? MsgBox??????????, ??
MsgBox(??,??,??) MsgBox????????
MsgBox ??,??,??
????????????????(??)? ???????????? ?????????????
?,??????MsgBoxStyle ?MsgBoxResult
40MsgBox????
?? MsgBoxStyle
41(No Transcript)
42MsgBox???????
??? MsgBoxResult
?4.3 ??????????????,??????,?????????,??????,??????
,????
43? ????????????????,????????????????????,??
?????????????????
44- Private Sub Form1_FormClosing(.)Handles
Me.FormClosing -
- Dim result As Integer
- result MsgBox("??????", _
-
MsgBoxStyle.OkCancel _ -
MsgBoxStyle.Critical, "??????") - If result MsgBoxResult.Ok Then
- MsgBox("?????!") '????????
- Else
- e.Cancel True '????
- End If
- End Sub
452.4.3 Format??????
46 2.4.4 Debug.write??
- ??????????Write???????WriteLine??????????
- Debug. WriteLine(???)
- Debug. Write (???)
- ? ??????
- Debug.WriteLine("??????" x " ?????"
jbgz) - Debug.Write("???????" sfgz)
- ????????????????
472.5.1.????
2.5 ??????
. NET?????????Math?????????????? Imports
System.Math??
? ??Windows???.
48???????
- ? ???? ???????,????? ? ????,?????????????.
- ? ???? ?????????
- ? ??Math?????sqrt
- Label1.Text system.Math.sqrt(100)
- ? Imports???? ??
- Imports ????
- ?? ?Public Class Form1??
49?? ? ? ? ? ? ?
Abs(N) ?N???? Abs(-3.5) 3.5
Cos(N) ??N?????? Cos(0) 1
Exp(N) ???e????,?eN Exp(3) 20.086
Pow(N1,N2) ???N1??,N2??? Pow(-5,2) 25
Log(N) ?????? Log(10) 2.3
Max(N1,N2) ?????????? Max(3,5) 5
Min(N1,N2) ?????????? Min(3,5) 3
Sin(N) ??N?????? Sin(0) 0
Sign(N) ??N????? Sign(-3.5) -1
Sqrt(N) ?N???? Sqrt(9) 3
Tan(N) ??N????? Tan(0) 0
Round?Ceiling?Floor
502.5.2.????
Int?Fix?IsNumeric
51??????
- Chr?Asc????????Chr(Asc(r))
- Chr(66) ? B Asc (B") ? 66
- Asc(Chr(66)) ? 99 Chr(Asc(K)) ? K
- Ucase("abcdefg") ? ABCDEFG"
- (2) Str???????????????,?????????????????
- (3) Val?????????????,????????????????????,?????,??
?????????????????? - Val("-123.45ty3")???-123.45?
522.5.3. ?????
????? VB.NET?????????(?????)???,?????????????????,
??????????VB.NET??Unicode?????????? VB.NET????????
??? ? ??????VB6.0??????? ?
?????System.String????(??)
53??? ?? ?? ??
Len(s) ?s???????? Len("ab??") 4
Left(s,n) ?s??????n??? Microsoft.VisualBasic .Left("ABcde",2) "AB"
Right(s,n) ?s??????n??? Microsoft.VisualBasic .Right("ABcde",2) "de"
Mid(s,b,n) ?s??????b????????n???,??????????n,??????????????? Mid("ABcde",2,3) "Bcd"
LTrim(s) ??s????? LTrim(" ABC ") "ABC "
RTrim(s) ??s????? RTrim(" ABC ") " ABC"
Trim(s) ??s????? Trim(" ABC ") "ABC"
Instr(s1,s2) ??s2?s1?????????,?????????,??0 Instr("WBAC","B") 2
StrDup(n,c) ???n??????????? StrDup (3,"a") "aaa"
Space (n) ??n??? Space (3) "???"
Replace(s,s1,s2) ????s??s2??s1 Replace("ABCASA","A","8") "8BC8S8"
StrReverse (s) ?????? StrReverse ("abcd") "dcba"
54????????
StrDup(5,A)
???"AAAAA" InStr("EFABCDEFG","EF")
???1 Trim("???ABC???") ???"ABC" Left("ABCDE"
,2) ???"AB" Right("ABCDE",2)
???"DE" Mid("ABCDE",2,3)
???"BCD" Mid("ABCDE",2,6)
???"BCDE"
?? ??Right?Left??????????????
Microsoft.VisualBasic,?????????Right?Left???
55- ?????????????????????????????????ABCD??????,
????????,??????????
562.5.4.???????
Now ????????? WeekDay ??????
DateAdd(???????,???,????????)
DateDiff(???????,??1,??2) ???????????????(??2012?
6?30 ?)?????????? DateDiff("d", Now,
6/30/2012) ???? year month day hour
Minute
57 582.5.5 ????
- Rnd????
- ????
- Rnd()?Rnd(N)
- ?? ??0,1)???????
- Ngt0????,?????,
- N0????????????
?????????,??????? Int(Rnd(??-??1)??)
???1100 ?Int(Rnd1001)
59- ??
- ????,???????????
- ???????????,????? Randomize
? ????10?????
602.5.6. Shell??
Shell???????????? ???? Shell(?????,????) ?????
??????????(????) ????????,04,6,1?????? ??
Shell(c\windows\system32\calc.exe,1)
612.6 ???????
- ??????????,????????????
- ????,??????????,?????????,????????
- ?????,?????????????????,????????,????????????????
- VB??????????????????????
622.6.1 ????
?????????????????? 1.????
632.????
??????????????????,???????????????????????????,???
????????
643.????
?????,?????????,??????????????,???????????????????
???????????????,??????????????,???????,???????????
???,???????????
652.6.2 ????
VB.NET????? (1) ????(??) ???????????????????????
(2) ????(??) ?????????????????,????????,?????? (3
) ????(Break) ??????,?????????????????????????????
?
66?????-????
??????????