➨ 2 ❶ Visual Basic 䛾ᇶᮏᩥἲ䕔䝇䝇䝔䞊䝖䝯䞁䝖Visual Basic 䛷䛿䚸ᨵ⾜䜎䛷䛾䠍⾜䜢䠍䛴䛾ព࿡䛾䛒䜛䝥䝻䜾䝷䝮䝁䞊䝗䛸䛧䛶ㄆ㆑䛧䚸䛣䜜䜢䝇䝔䞊䝖䝯䞁䝖䛸࿧䜃䜎䛩䚹䝇䝔䞊䝖䝯䞁䝖䛿䚸ᕥ䛛䜙ྑ䚸ୖ䛛䜙ୗ䜈ᐇ⾜䛥䜜䜎䛩䚹䕔」ᩘ⾜䛻䜎䛯䛜䜛䝇䝔䞊䝖䝯䞁䝖䝇䝔䞊䝖䝯䞁䝖䛜㛗䛟䛺䜚䛩䛞䜛ሙྜ䛺䛹䚸䝇䝔䞊䝖䝯䞁䝖䜢」ᩘ⾜䛻ศ๭䛧䛶グ㏙䛧䛯䛔ሙྜ䚸⾜㐃⤖䝇䝔䞊䝖䝯䞁䝖䜢౑⏝䛩䜛䛣䛸䛜䛷䛝䜎䛩䚹⾜㐃⤖䝇䝔䞊䝖䝯䞁䝖䛿༙ゅ䝇䝨䞊䝇䛸䜰䞁䝎䞊䝇䝁䜰(_)䜢౑䛳䛶⾲䛧䜎䛩䚹Visual Studio 2010 ௨㝆䛷䛿ḟ䛾䜘䛖䛺ሙྜ䛿⾜㐃⤖䝇䝔䞊䝖䝯䞁䝖䜢┬␎ྍ⬟䛷䛩䚹(ᬯ㯲䛾⾜⥅⥆)•䜹䞁䝬( , )䛾ᚋ•

ᕥ䛛䛳䛣(()䛾ᚋ䚸䜎䛯䛿ྑ䛛䛳䛣())䛾๓•㐃⤖₇⟬Ꮚ(&)䛾ᚋ•௦ධ₇⟬Ꮚ( = )䛾ᚋetc.......

1. MessageBox.Show("࣓ࢵࢭ࣮ࢪ",2. "ࢱ࢖ࢺࣝ")3. MessageBox.Show(
4. GetUserName(ID)5. )6. cmd.CommandText = "SELECT * FROM employees"&
7. "WHERE emp_type = 'S'"
8. Button1.Text =9. "OK"32➨ 2 ❶ Visual Basic 䛾ᇶᮏᩥἲ䕔」」ᩘ䝇䝔䞊䝖䝯䞁䝖䜢 1 ⾜䛷グ㏙」ᩘ䝇䝔䞊䝖䝯䞁䝖䜢䠍⾜䛻グ㏙䛩䜛ሙྜ䝁䝻䞁(䠖)䛷䝇䝔䞊䝖䝯䞁䝖䜢㐃⤖䛧䜎䛩䚹䕔䝁䝯䞁䝖䝅䞁䜾䝹䜽䜷䞊䝔䞊䝅䝵䞁(')䛛䜙䛭䛾⾜䛾⾜ᮎ䜎䛷䛿䚸䝁䝯䞁䝖䛸䛧䛶䛒䛴䛛䜟䜜䜎䛩䚹䝁䝯䞁䝖䛿䝡䝹䝗ᑐ㇟እ䛾䝁䞊䝗䛷䛩䚹」ᩘ⾜䛾䝥䝻䜾䝷䝮䝁䞊䝗䜢୍ᗘ䛻䝁䝯䞁䝖䜰䜴䝖䛩䜛ሙྜ䚸䝥䝻䜾䝷䝮䝁䞊䝗䜢㑅ᢥ䛧䛯ᚋ䚸䝪䝍䞁䜢䜽䝸䝑䜽䛧䜎䛩䚹䝁䝯䞁䝖䜰䜴䝖䛥䜜䛯䝥䝻䜾䝷䝮䝁䞊䝗䜢㑅ᢥ䛧䛯ᚋ䚸䝪䝍䞁䜢䜽䝸䝑䜽䛩䜛䛸䚸䝁䝯䞁䝖䜢ゎ㝖䛩䜛䛣䛸䛜䛷䛝䜎䛩䚹䕔⮬ື䝇䝨䝹䝏䜵䝑䜽
Visual Basic 䛾䝥䝻䜾䝷䝮䝁䞊䝗䛷䛿䚸኱ᩥᏐ䞉ᑠᩥᏐ䜢༊ู䛧䜎䛫䜣䚹䛧䛛䛧䚸Visual Studio 䛷䛿䚸ධຊ䛧䛯ᩥᏐ䛜䚸䜸䝤䝆䜵䜽䝖ྡ䜔䜻䞊䝽䞊䝗䛻୍⮴䛧䛯ሙྜ䚸ᨵ⾜䛾䝍䜲䝭䞁䜾䛷䚸኱ᩥᏐ䞉ᑠᩥᏐ䛾ኚ᥮ฎ⌮䛜䛚䛣䛺䜟䜜䜎䛩䚹䛣䛾ᶵ⬟䜢฼⏝䛧䛶䚸䝥䝻䜾䝷䝮䝁䞊䝗䜢䛩䜉䛶ᑠᩥᏐ䛷ධຊ䛩䜛䜘䛖䛻䛩䜜䜀䚸ᨵ⾜䛾䝍䜲䝭䞁䜾䛷ධຊ䝭䝇䜢ぢ䛴䛡䜔䛩䛟䛺䜚䜎䛩䚹䛆䜲䞁䝔䝸䝉䞁䝇䛇Visual Studio 䛷䛿䚸䜲䞁䝔䝸䝉䞁䝇ᶵ⬟䛻䜘䛳䛶䝁䞊䝗ධຊ᫬䚸ධຊྍ⬟䛺䜻䞊䝽䞊䝗䛜䝥䝹䝎䜴䞁䝯䝙䝳䞊䛸䛧䛶⾲♧䛥䜜䜎䛩䚹䝬䜴䝇䛾䜹䞊䝋䝹䚸䜎䛯䛿▮༳䜻䞊䛷ධຊ䛧䛯䛔䜻䞊䝽䞊䝗䜢㑅ᢥ䛧䚸Tab 䜻䞊䜢ᢲ䛩䛣䛸䛷ධຊ䛷䛝䜎䛩䚹䝯䝙䝳䞊䜢༙㏱᫂䛻䛧䛯䛔ሙྜ䛿 Ctrl 䜻䞊䜢䚸ᾘ䛧䛯䛔ሙྜ䛿 Esc 䜻䞊䜢ᢲ䛧䜎䛩䚹෌ᗘ⾲♧䛧䛯䛔ሙྜ䛿Ctrl 䜻䞊䛸 J 䜻䞊䜢ᢲ䛧䜎䛩䚹㻌

33

➨ 2 ❶ Visual Basic 䛾ᇶᮏᩥἲ䕔Visual Basic 䛾䝥䝻䜾䝷䝮䛿ᆺ䛾㞟ྜ
Visual Basic 䛷సᡂ䛥䜜䜛䝥䝻䜾䝷䝮䛿䛩䜉䛶ᆺ䛾㞟ྜయ(䝁䝺䜽䝅䝵䞁)䛸䛧䛶సᡂ䛥䜜䜎䛩䚹ฎ⌮䛾䜏䜢༢⊂䛷グ㏙䛫䛪䛻䚸ఱ䜙䛛䛾ᆺ䛻ྵ䜑䜎䛩䚹䕔ᆺᆺ䛻ศ㢮ศ䛡䛥䜜䜛䝁䞊䝗䝤䝻䝑䜽䛻䛿䜽䝷䝇䚸ᵓ㐀య䚸䜲䞁䝍䞊䝣䜵䜲䝇䛺䛹䛜䛒䜚䜎䛩䚹䕔ฎ⌮ฎ⌮䛻ศ㢮ศ䛡䛥䜜䜛䝁䞊䝗䝤䝻䝑䜽䛻䛿䜲䝧䞁䝖䝝䞁䝗䝷䞊䚸䝥䝻䝅䞊䝆䝱䛺䛹䛜䛒䜚䜎䛩䚹ḟ䛾䝃䞁䝥䝹䝁䞊䝗䛷䛿䚸Form1 䛸䛔䛖ྡ๓䛷ᆺ(䜽䝷䝇)䜢ᐃ⩏䛧䚸䛭䛾୰䛻 Button1_Click 䛸䛔䛖ྡ๓䛷ฎ⌮(䜲䝧䞁䝖䝝䞁䝗䝷䞊)䜢ᐃ⩏䛧䛶䛔䜎䛩䚹

1. Public Class Form12.
3.

Private Sub Button1_Click(ByVal sender As System.Object, _4.

ByVal e As System.EventArgs) Handles Button1.Click5.
6.

MessageBox.Show("Hello Visual Basic !!")

7.
8.

End Sub

9.
10. End Class34

➨ 2 ❶ Visual Basic 䛾ᇶᮏᩥἲ㻌㻌35

➨ 2 ❶ Visual Basic 䛾ᇶᮏᩥἲ䕔ኚኚᩘ䛸䛿ኚᩘ䛿䚸䝥䝻䜾䝷䝮䛾୰䛷౑⏝䛩䜛䝕䞊䝍䜢ಖᏑ䛩䜛䛯䜑䛻䚸䝯䝰䝸䛻☜ಖ䛥䜜䛯㡿ᇦ䛷䛩䚹ኚᩘ䛻᱁⣡䛥䜜䛯䝕䞊䝍䛿䚸䜰䝥䝸䜿䞊䝅䝵䞁䛾ᐇ⾜୰䛻ኚ᭦䛩䜛䛣䛸䛜䛷䛝䜎䛩䚹䝥䝻䜾䝷䝮䛷䛿䚸ḟ䛾䜘䛖䛺⏝㏵䛻ኚᩘ䜢౑⏝䛧䜎䛩䚹•䜸䝤䝆䜵䜽䝖䛾䝥䝻䝟䝔䜱್䛾ಖᏑ•䝥䝻䝅䞊䝆䝱䛾ᡠ䜚್䛾ಖᏑ•䝴䞊䝄䞊䛜ධຊ䛧䛯䝕䞊䝍䛾ಖᏑ•ᚋ⥆ฎ⌮䛾䛯䜑䚸୰㏵ẁ㝵䛷䛾ฎ⌮⤖ᯝ䛾୍᫬ⓗ䛺ಖᏑ•ྠ䛨ฎ⌮䜢」ᩘᅇ⧞䜚㏉䛩ሙྜ䛻䚸⌧ᅾ䛾ᅇᩘ䛾ಖᏑ•䝥䝻䝅䞊䝆䝱䛾䝟䝷䝯䞊䝍䞊etc.......

1. SelectionName = ListBox1.SelectedItem
2. AnswerResult = String.Equals(TextBox1.Text, TextBox2.Text)
3. UserName = InputBox("ྡ๓ࢆධຊࡋ࡚ࡃࡔࡉ࠸")4. UserName = TextBox1.Text
5. NewMessage = "᪂ࡋ࠸࣓࣮ࣝࡀᒆ࠸࡚࠸ࡲࡍࠋ"6. Average = TotalScore / NumberStudent36➨ 2 ❶ Visual Basic 䛾ᇶᮏᩥἲ䕔ኚኚᩘྡኚᩘྡ䛿䚸䝕䞊䝍ಖᏑ㡿ᇦ䛻䛴䛡䜛ྡ๓䛷䛩䚹䝥䝻䜾䝷䝮䝁䞊䝗䛷䛿䚸ኚᩘྡ䜢౑䛳䛶䚸䝕䞊䝍ಖᏑ㡿ᇦ䛻䝕䞊䝍䜢᱁⣡䛧䛯䜚䚸᱁⣡䛥䜜䛶䛔䜛䝕䞊䝍䜢ཧ↷䛧䛯䜚䛧䜎䛩䚹ኚᩘྡ䛿䚸ḟ䛾つ๎ෆ䛷⮬⏤䛻௜䛡䜛䛣䛸䛜䛷䛝䜎䛩䚹•᭱ึ䛾ᩥᏐ䛿䚸ⱥᏐ䚸䜰䞁䝎䞊䝇䝁䜰(_)䛾䛔䛪䜜䛛•䝢䝸䜸䝗(.)䚸✵ⓑ䚸ᆺᐉゝᩥᏐ(%䚸&䚸!䚸#䚸@䚸$)䛿䚸౑⏝䛷䛝䛺䛔•ண⣙䜻䞊䝽䞊䝗(䝇䝔䞊䝖䝯䞁䝖ྡ䚸㛵ᩘྡ䚸₇⟬Ꮚ䛺䛹)䛿䚸౑⏝䛷䛝䛺䛔•ྠ䛨䝇䝁䞊䝥(㐺⏝⠊ᅖ)ෆ䛷䚸ྠ䛨ኚᩘྡ䜢」ᩘ౑⏝䛩䜛䛣䛸䛿䛷䛝䛺䛔䕔䝕䞊䝍ᆺAs 䜻䞊䝽䞊䝗䛾ᚋ䜝䛻䛿䝕䞊䝍ᆺ䜢ᣦᐃ䛧䜎䛩䚹䝕䞊䝍ᆺ䛿䛭䛾ኚᩘ䛻䛹䛾䜘䛖䛺್䜢᱁⣡䛩䜛䛾䛛䜢⾲䛧䛶䛔䜎䛩䚹౛䛘䜀䚸ኚᩘ䛾୰䛻ᩚᩘ䛾್䜢᱁⣡䛩䜛ሙྜ䛿 Integer 䛸䛔䛖䝕䞊䝍ᆺ䜢ᣦᐃ䛧䜎䛩䚹ᩥᏐิ䜢᱁⣡䛩䜛ሙྜ䛿䚸String 䛸䛔䛖䝕䞊䝍ᆺ䜢ᣦᐃ䛧䜎䛩䚹䝯䝰䝸䛻☜ಖ䛥䜜䜛㡿ᇦ䛾኱䛝䛥䛿䚸ኚᩘᐉゝ䛾㝿䛻ᣦᐃ䛩䜛䝕䞊䝍ᆺ䛻䜘䛳䛶Ỵ䜎䜚䜎䛩䚹37

➨ 2 ❶ Visual Basic 䛾ᇶᮏᩥἲ䕔ඹ
ඹ㏻ᆺ䝅䝇䝔䝮(CTS䠖Common Type System).NET Framework 䛷䛿䚸䝥䝻䜾䝷䝭䞁䜾ゝㄒ䛻౫Ꮡ䛧䛺䛔ᐇ⾜⎔ቃ䜢ᐇ⌧䛩䜛䛯䜑䚸ඹ㏻ᆺ䝅䝇䝔䝮䜢ᐃ⩏䛧䛶䛔䜎䛩䚹䛭䛾䛯䜑䚸Visual Basic 䛷䜒 Visual C#䛷䜒䚸ྠ䛨䝕䞊䝍ᆺ䜢ᣦᐃ䛧䛶䚸ኚᩘ䜢ᐉゝ䛩䜛䛣䛸䛜䛷䛝䜎䛩䚹䜎䛯䚸ྛ䝥䝻䜾䝷䝭䞁䜾ゝㄒ䛷.NET Framework 䛷ᐃ⩏䛥䜜䛯䝕䞊䝍ᆺ䛾ูྡ䛜ᐃ⩏䛥䜜䛶䛔䜛䛯䜑䚸ྛ䝥䝻䜾䝷䝭䞁䜾ゝㄒ䛾䝕䞊䝍ᆺ䜢౑⏝䛩䜛䛣䛸䜒䛷䛝䜎䛩䚹䖃Visual Basic
1. Dim x AS Integer'Visual Basic ࡢࢹ࣮ࢱᆺ
2. Dim x As System.Int32'CTS ࡢࢹ࣮ࢱᆺ䖃Visual C#
1. int x;//Visual C#ࡢࢹ࣮ࢱᆺ

2. System.Int32 x;//CTS ࡢࢹ࣮ࢱᆺ䕔್ᆺ䛸ཧ↷ᆺ䝕䞊䝍ᆺ䛿䚸䝯䝰䝸ෆ䛻䝕䞊䝍䜢☜ಖ䛩䜛௙⤌䜏䛾㐪䛔䛛䜙䚸್ᆺ䛸ཧ↷ᆺ䛾 2 䛴䛻ศ㢮䛩䜛䛣䛸䛜䛷䛝䜎䛩䚹್ᆺ䛾䝕䞊䝍ᆺ䛷ᐉゝ䛧䛯ኚᩘ䛻䛿䚸䛭䛾ኚᩘ䛻ᐇ㝿䛾䝕䞊䝍䛜᱁⣡䛥䜜䜎䛩䚹ཧ↷ᆺ䛾䝕䞊䝍ᆺ䛷ᐉゝ䛧䛯ኚᩘ䛻䛿䚸ᐇ㝿䛾䝕䞊䝍䛷䛿䛺䛟䚸ᐇ㝿䛾䝕䞊䝍䜢ཧ↷䛩䜛䛯䜑䛾ཧ↷᝟ሗ䛜᱁⣡䛥䜜䜎䛩䚹

㻌

㻌

38

➨ 2 ❶ Visual Basic 䛾ᇶᮏᩥἲ୺䛺䝕䞊䝍ᆺ䜢ḟ䛻♧䛧䜎䛩䚹ศ㢮

Visual Basic(䜹䝔䝂䝸)䛾䝕䞊䝍ᆺCTS 䛾䝕䞊䝍ᆺ

䝃䜲䝈

್䛾⠊ᅖ

(byte)

Byte

System.Byte

10䡚255

SByte

System.SByte

1-128 䡚 127

Short

System.Int16

2-32,768 䡚 32,767

UShortSystem.UInt1620䡚65535

Integer

System.Int32

4-2,147,483,648 䡚 2,147,483,647

UInteger

System.UInt32

40 䡚 4,294,967,295

Long

System.Int648

್ᆺ
(ᩚᩘ)

-9,223,372,036,854,775,808䡚
9,223,372,036,854,775,807
ULong

System.UInt648Single

System.Single

40 䡚 18,446,744,073,709,551,615-3.4028235E+38 䡚 -1.401298E-45 (㈇䛾್)
1.401298E-45 䡚 3.4028235E+38 (ṇ䛾್)್ᆺ-1.79769313486231570E+308 䡚(ᾋືᑠᩘⅬᩘ)-4.94065645841246544E-324 (㈇䛾್)DoubleSystem.Double

8
4.94065645841246544E-324 䡚
1.79769313486231570E+308 (ṇ䛾್)BooleanSystem.Boolean

2

True 䜎䛯䛿 False

Char

System.Char

2

Unicode ᩥᏐ

Date

System.DateTime

8すᬺ 1 ᖺ 1 ᭶ 1 ᪥䡚9999 ᖺ 12 ᭶ 31 ᪥-79,228,162,514,264,337,593,543,950,335 䡚79,228,162,514,264,337,593,543,950,335್ᆺ(ᑠᩘ㒊ศ䜢ᣢ䛯䛺䛔ᩘ್䛾ሙྜ)(䛭䛾௚)-7.9228162514264337593543950335 䡚
DecimalSystem.Decimal

16
7.9228162514264337593543950335(ᑠᩘⅬ௨ୗ 28 ᱆䛾ᩘ್䛾ሙྜ)
0.0000000000000000000000000001 (1E-28)(0 䜢㝖䛔䛯ሙྜ䛾⤯ᑐ್䛾᭱ᑠ್)

ObjectSystem.ObjectString

System.String

4

௵ព䛾ᆺ

ཧ↷ᆺ
Unicode ᩥᏐ䛾୙ኚᅛᐃ㛗ᩥᏐิ

39

➨ 2 ❶ Visual Basic 䛾ᇶᮏᩥἲ䕔䝸䝸䝔䝷䝹⾲グ䛸䛿䝸䝔䝷䝹䛸䛿䝥䝻䜾䝷䝮䝁䞊䝗୰䛾ᐃᩘ್䛾䛣䛸䛷䛩䚹䝃䝣䜱䝑䜽䝇䜢฼⏝䛩䜛䛣䛸䛷䝸䝔䝷䝹䛾䝕䞊䝍ᆺ䜢ᣦᐃ䛩䜛䛣䛸䛜䛷䛝䜎䛩䚹䝃䝣䜱䝑䜽䝇䜢┬␎䛧䛯ሙྜ䚸ᩚᩘ್䛿䚸Integer ᆺ䛾⠊ᅖ䛷䛿Integer ᆺ䛻䚸䛭䜜䜘䜚኱䛝䛺್䛻䛺䜛䛸 Long ᆺ䛸䛧䛶ゎ㔘䛥䜜䜎䛩䚹䜎䛯ᐇᩘ್䛿䚸Double ᆺ䛷ゎ㔘䛥䜜䜎䛩䚹䕔ኚᩘ䛾ึᮇ໬ኚᩘ䛻್䜢௦ධ䛩䜛䛻䛿䚸௦ධ₇⟬Ꮚ(=)䜢฼⏝䛧䜎䛩䚹ኚᩘ䛻᭱ึ䛻௦ධ䛥䜜䜛್䛾䛣䛸䜢ึᮇ್䛸࿧䜃䚸ኚᩘ䛻ึᮇ್䜢௦ධ䛩䜛䛣䛸䜢ึᮇ໬䛸࿧䜃䜎䛩䚹㻌㻌40➨ 2 ❶ Visual Basic 䛾ᇶᮏᩥἲ䕔ኚኚᩘᐉゝ䛸ඹ䛻ึᮇ್䛾௦ධኚᩘ䛾ᐉゝ䛸ึᮇ್䛾௦ධ䜢䜂䛸䛴䛾䝇䝔䞊䝖䝯䞁䝖䛷䛚䛣䛺䛖䛣䛸䛜䛷䛝䜎䛩䚹䕔䝕䞊䝍ᆺ䛾┬␎䝕䞊䝍ᆺ䜢┬␎䛧䛯ሙྜ䚸ኚᩘ䛾䝕䞊䝍ᆺ䛿 Object ᆺ䛸䛧䛶ྲྀ䜚ᢅ䜟䜜䜎䛩䚹䕔䝻䞊䜹䝹ᆺ䛾᥎ㄽ䝻䞊䜹䝹ኚᩘ䜢ᐉゝ䛩䜛ሙྜ䚸䝕䞊䝍ᆺ䜢┬␎䛧䚸䛛䛴ึᮇ್䜢௦ධ䛩䜛䛸(౛䠖Dim x = 100)௦
ධ䛥䜜䛯್䛻䜘䛳䛶㐺ษ䛺䝕䞊䝍ᆺ䛜᥎ㄽ䛥䜜䜎䛩䚹䝻䞊䜹䝹ኚᩘ䛸䛿䚸䝥䝻䝅䞊䝆䝱ෆ䛷ᐉゝ䛥䜜䛯ኚᩘ䛾䛣䛸䛷䛩䚹(䝥䝻䝅䞊䝆䝱䛻㛵䛧䛶䛿ᚋ㏙)䛣䛾ᶵ⬟䛿䝻䞊䜹䝹ᆺ䛾᥎ㄽ䛸࿧䜀䜜䛶䛔䜎䛩䚹䝻䞊䜹䝹ᆺ䛾᥎ㄽ䛿 Visual Studio 2008 䛛䜙䛾ᶵ⬟䛷䛩䚹䕔」ᩘ䛾ኚᩘ䜢䜎䛸䜑䛶ᐉゝኚᩘᐉゝ䜢䜹䞁䝬 (,) 䛷༊ษ䜛䛣䛸䛷」ᩘ䛾ኚᩘ䜢ᐃ⩏䛩䜛䛣䛸䛜䛷䛝䜎䛩䚹䕔䛥䜎䛦䜎䛺ኚᩘᐉゝ౛䛸䝕䞊䝍ᆺ
1. Dim x As Integer’x ࡣ Integer ᆺ

2. Dim x As Integer = 100’x ࡣ Integer ᆺ(ึᮇ್㸸100)

3. Dim x

’x ࡣ Object ᆺ

4. Dim x = 100’x ࡣᆺ᥎ㄽࡉࢀ࡚ Integer ᆺ(ึᮇ್㸸100)

5. Dim x, y, z As Integer

’x,y,z ࡣ Integer ᆺ41