➨ 2 ❶㻌 ₇⩦

⦎⩦1.ኚᩘ䛾฼⏝෇㗹䛾య✚䜢ィ⟬䛩䜛䜰䝥䝸䜿䞊䝅䝵䞁䜢సᡂ䛧䜎䛩䚹ᗏ㠃䛾༙ᚄ䛸㧗䛥䜢ධຊ䛧䛶䚸䠷ィ⟬䠹䝪䝍䞁䜢䜽䝸䝑䜽䛩䜛䛸䚸෇㗹䛾య✚䛜⾲♧䛥䜜䜛䜰䝥䝸䜿䞊䝅䝵䞁䜢సᡂ䛧䛶䜏䜎䛧䜗䛖䚹䝇䝔䝑䝥1. 䝥䝻䝆䜵䜽䝖䛾సᡂ
1.

Visual Studio 2012 䜢㉳ື䛧䜎䛩䚹

2.

௨ୗ䛾᝟ሗ䜢䜒䛸䛻䚸䝇䝍䞊䝖䝨䞊䝆䜎䛯䛿䚸[䝣䜯䜲䝹]-[᪂つసᡂ]-[䝥䝻䝆䜵䜽䝖]䛛䜙᪂䛧䛔䝥䝻䝆䜵䜽䝖䜢సᡂ䛧䜎䛩䚹䝥䝻䝆䜵䜽䝖䛾ゝㄒ

VisualBasic䝔䞁䝥䝺䞊䝖

Windows 䝣䜷䞊䝮䜰䝥䝸䜿䞊䝅䝵䞁䝥䝻䝆䜵䜽䝖ྡ

MyCalc225

➨ 2 ❶㻌 ₇⩦

䝇䝔䝑䝥2. 䝴䞊䝄䞊䜲䞁䝍䞊䝣䜵䜲䝇䛾సᡂ1.

௨ୗ䛾⏬㠃䜲䝯䞊䝆䜢ཧ⪃䛻䚸䜹䝔䝂䝸[䝁䝰䞁䝁䞁䝖䝻䞊䝹]䛾䝁䞁䝖䝻䞊䝹䜢㓄⨨䛧䜎䛩䚹䖃 Label 䜢䝣䜷䞊䝮䛻 7 䛴㓄⨨䛧䜎䛩䚹䖃 TextBox 䜢䝣䜷䞊䝮䛻 2 䛴㓄⨨䛧䜎䛩䚹䖃 Button 䜢䝣䜷䞊䝮䛻 1 䛴㓄⨨䛧䜎䛩䚹
TextBox1
TextBox22.

䝥䝻䝟䝔䜱䜴䜱䞁䝗䜴䛷䚸ྛ䝁䞁䝖䝻䞊䝹䛾䝥䝻䝟䝔䜱䜢ኚ᭦䛧䛶䚸௨ୗ䛾䜘䛖䛺䝴䞊䝄䞊䜲䞁䝍䞊䝣䜵䜲䝇䛻ኚ᭦䛧䜎䛩䚹226

➨ 2 ❶㻌 ₇⩦䝁䞁䝖䝻䞊䝹ྡ䝥䝻䝟䝔䜱ྡ್(Name)

RadiusTextBox

TextAlign

Right(Name)

HeightTextBox

TextAlign

Right

Label1

Textᗏ㠃䛾༙ᚄ䠖

Label2Text

㧗䛥䠖Label3

Text෇㗹䛾య✚䠖(Name)

VolumeLabel

Text(✵ⓑ)

AutoSize

False

BorderStyle

Fixed3D

TextAlign

MiddleRight

Label5

Text(m)Label6

Text(m)

Label7Text(ੑ)(Name)

CalcButton

Textィ⟬Text෇㗹䛾య✚䛾ィ⟬

TextBox1

TextBox2

Label4

Button1Form1

䝇䝔䝑䝥3. 䝥䝻䜾䝷䝮䝁䞊䝗䛾グ㏙
1.

CalcButton 䝪䝍䞁䛾 CalcButton_Click 䜲䝧䞁䝖䝝䞁䝗䝷䞊䜢⾲♧䛧䚸௨ୗ䛾䝁䞊䝗䜢䚸䝠䞁䝖䜢ཧ⪃䛻᏶ᡂ䛥䛫䜎䛩䚹䖃 䝁䞊䝗
Dim radius As 䐟
Single = 0Dim height As 䐠
Single = 0Dim volume As Single = 0
䐡radius = RadiusTextBox.Text
height = HeightTextBox.Text
䐢 * 3.14 * height / 3
volume = radius * radius
䐣 = volumeVolumeLabel.Text227

➨ 2 ❶㻌 ₇⩦䖃 䝠䞁䝖䐟௨ୗ䛾ኚᩘ䜢ᐃ⩏䛧䜎䛩䚹ྡ๓radiusᆺSingleึᮇ್0䐠௨ୗ䛾ኚᩘ䜢ᐃ⩏䛧䜎䛩䚹ྡ๓heightᆺSingleึᮇ್0䐡ኚᩘ radius 䛻 RadiusTextBox.Text 䛾್䜢௦ධ䛧䜎䛩䚹䐢ኚᩘ volume 䛻෇㗹䛾య✚䜢ィ⟬䛧䛶௦ධ䛧䜎䛩䚹ィ⟬ᘧ䛿௨ୗ䛷䛩䚹[ᗏ㠃䛾༙ᚄ]2㽢3.14㽢[㧗䛥]㾂3
䐣VolumeLabel.Text 䛻ኚᩘ volume 䛾್䜢௦ධ䛧䜎䛩䚹2.

䜰䝥䝸䜿䞊䝅䝵䞁䜢ᐇ⾜䛧䜎䛩䚹3.

ᗏ㠃䛾༙ᚄ䛸㧗䛥䜢ධຊ䛧䛶ィ⟬䝪䝍䞁䜢䜽䝸䝑䜽䛧䜎䛩䚹㻌4.

෇㗹䛾య✚䛜ィ⟬䛥䜜䚸ṇ䛧䛔⤖ᯝ䛜ฟຊ䛥䜜䜛䛣䛸䜢☜ㄆ䛧䜎䛩䚹㻌5.

䜰䝥䝸䜿䞊䝅䝵䞁䛾ᐇ⾜䜢⤊஢䛧䜎䛩䚹㻌228➨ 2 ❶㻌 ₇⩦⦎⩦2.ᐃᩘ䛾฼⏝⦎⩦䠍䛷సᡂ䛧䛯䜰䝥䝸䜿䞊䝅䝵䞁䜢䚸ᐃᩘ䜢฼⏝䛧䛯ฎ⌮䛻ಟṇ䛧䜎䛩䚹䝇䝔䝑䝥1. 䝥䝻䜾䝷䝮䝁䞊䝗䛾ኚ᭦䛸䜰䝥䝸䜿䞊䝅䝵䞁䛾䝔䝇䝖
1.

CalcButton 䝪䝍䞁䛾 CalcButton_Click 䜲䝧䞁䝖䝝䞁䝗䝷䞊䜢⾲♧䛧䚸௨ୗ䛾䝁䞊䝗䜢䚸䝠䞁䝖䜢ཧ⪃䛻᏶ᡂ䛥䛫䜎䛩䚹䖃 䝁䞊䝗
Dim radius As Single = 0
Dim height As Single = 0
Dim volume As Single = 0
Const pai As Single= 3.14
䐟Const coefficient䐠 As Integer = 3
radius = RadiusTextBox.Text
height = HeightTextBox.Text
volume = radius * radius *䐡pai * height / coefficient
VolumeLabel.Text = volume䖃 䝠䞁䝖䐟௨ୗ䛾ᐃᩘ䜢ᐃ⩏䛧䜎䛩䚹ྡ๓paiᆺSingleึᮇ್3.14

䐠௨ୗ䛾ᐃᩘ䜢ᐃ⩏䛧䜎䛩䚹ྡ๓ᆺcoefficientIntegerึᮇ್3䐡య✚䛾ィ⟬ᘧෆ䛾䝸䝔䝷䝹䜢ᐃᩘ䛻⨨䛝᥮䛘䜎䛩䚹

2.

䜰䝥䝸䜿䞊䝅䝵䞁䜢ᐇ⾜䛧䜎䛩䚹229

➨ 2 ❶㻌 ₇⩦3.

ືస☜ㄆ䜢䛚䛣䛺䛔䚸䜰䝥䝸䜿䞊䝅䝵䞁䛾ᐇ⾜䜢⤊஢䛧䜎䛩䚹ཧ⪃䠖ᐃᩘ䜢฼⏝䛩䜛฼Ⅼ䝥䝻䜾䝷䝮䝁䞊䝗䛻┤᥋䝕䞊䝍䜢グ㏙䛩䜛䛾䛷䛿䛺䛟䚸ᐃᩘ䜢฼⏝䛧䛶䛔䜛䛾䛷䚸䝥䝻䜾䝷䝮䝁䞊䝗䛜⌮ゎ䛧䜔䛩䛟䛺䜚䜎䛧䛯䚹䜎䛯䚸ᚋ䛛䜙䝕䞊䝍䛜ኚ᭦䛻䛺䛳䛯䛸䛧䛶䜒䚸ಟṇ⟠ᡤ䛿ᐃᩘ䛻䝕䞊䝍䜢௦ධ䛩䜛㒊ศ䛰䛡䛷῭䜏䜎䛩䚹230➨ 2 ❶㻌 ₇⩦

⦎⩦3.䠄䜸䝥䝅䝵䞁䠅Option Strict 䛸ᆺኚ᥮
⦎⩦ 2 䛷సᡂ䛧䛯䜰䝥䝸䜿䞊䝅䝵䞁䛾䝥䝻䜾䝷䝮䝁䞊䝗䜢ኚ᭦䛧䚸Option Strict 䝇䝔䞊䝖䝯䞁䝖䛾タᐃ䛸䝕䞊䝍ᆺ䛾ኚ᥮䜢☜ㄆ䛧䜎䛩䚹䝇䝔䝑䝥1. Option 䝇䝔䞊䝖䝯䞁䝖䛾ᤄධ
1.

MyCalc 䝥䝻䝆䜵䜽䝖䛾 Form1.vb 䝣䜯䜲䝹䜢䝁䞊䝗䜶䝕䜱䝍䛷㛤䛝䚸௨ୗ䛾䝁䞊䝗䜢䚸䝠䞁䝖䜢ཧ⪃䛻᏶ᡂ䛥䛫䜎䛩䚹䖃 䝁䞊䝗
Option Strict On 䐟
Public Class Form1
Private Sub CalcButton_Click(sender As Object, e As EventArgs) Handles CalcButton.Click
Dim radius As Single = 0䖃 䝠䞁䝖䐟䝣䜯䜲䝹䝺䝧䝹䛷ᬯ㯲ⓗ䛺ᆺኚ᥮䜢䛚䛣䛺䜟䛺䛔タᐃ䜢グ㏙䛧䜎䛩䚹2.

䜰䝥䝸䜿䞊䝅䝵䞁䜢ᐇ⾜䛧䜎䛩䚹Q㻌 䝕䝞䝑䜾ᐇ⾜䜢䛚䛣䛺䛖䛣䛸䛜䛷䛝䜎䛩䛛䠛䛭䜜䛿䛺䛬䛷䛩䛛䠛䝇䝔䝑䝥2. 䝕䞊䝍ᆺ䛾᫂♧ⓗ䛺ኚ᥮1.

䜶䝷䞊䛜ᾘ䛘䜛䜘䛖䛻ᆺኚ᥮䜢ᐇ⿦䛧䜎䛩䚹䈜⮬⏤䛻䝁䞊䝕䜱䞁䜾䛧䛶䛟䛰䛥䛔ゎ⟅౛䛿ḟ䛾䝨䞊䝆䛻㍕䛫䛶䛒䜚䜎䛩231

➨ 2 ❶㻌 ₇⩦䖃 䝁䞊䝗Private Sub CalcButton_Click(sender As Object, e As EventArgs) Handles CalcButton.Click
Dim radius As Single = 0
Dim height As Single = 0
Dim volume As Single = 0
Const pai As Single = 3.14
Const coefficient As Integer = 3
radius = CSng(RadiusTextBox.Text)
height = CSng(HeightTextBox.Text)
volume = radius * radius * pai * height / coefficient
VolumeLabel.Text = volume.ToString("#.#")End Sub2.

䜰䝥䝸䜿䞊䝅䝵䞁䜢ᐇ⾜䛧䛶䚸ືస䜢☜ㄆ䛧䜎䛩䚹Q㻌㻌 䝕䝞䝑䜾ᐇ⾜䛷䛝䜎䛩䛛䠛ཧ⪃䠖ᩘ್᭩ᘧᣦᐃᩥᏐิ
ToString 䝯䝋䝑䝗䛿䠄䠅ෆ䛻䚸String ᆺ䜈ᆺኚ᥮䛩䜛㝿䛾᭩ᘧ䛾ᣦᐃ䛜ྍ⬟䛷䛩䚹䛣䛾᭩ᘧᣦᐃ䛾グ㏙䛾䛣䛸䜢ᩘ್᭩ᘧᣦᐃᩥᏐิ䛸࿧䜃䚸ᶆ‽ᩘ್᭩ᘧᣦᐃᩥᏐิ䛸䜹䝇䝍䝮ᩘ್᭩ᘧᣦᐃᩥ
Ꮠิ䛾 2 ✀㢮䛜Ꮡᅾ䛧䜎䛩䚹౛䛘䜀#䛿䜹䝇䝍䝮ᩘ್᭩ᘧᣦᐃᩥᏐิ䛾 1 ✀䛷䚸᱆䛾ᣦᐃ䜢䛚䛣䛺䛔䜎䛩䚹䛭䛾௚䛾䝟䝍䞊䞁䛿䝦䝹䝥䜢ཧ↷䛧䛶䛟䛰䛥䛔䚹

3.

䜰䝥䝸䜿䞊䝅䝵䞁䛾ᐇ⾜䜢⤊஢䛧䜎䛩䚹

232

➨ 2 ❶㻌 ₇⩦

⦎⩦4.཯᚟ᵓ㐀䛚䜘䜃㓄ิ䛾฼⏝
For…Next 䝇䝔䞊䝖䝯䞁䝖䛚䜘䜃㓄ิ䜢฼⏝䛧䛶ᖹᆒⅬ䜢ィ⟬䛩䜛䜰䝥䝸䜿䞊䝅䝵䞁䜢సᡂ䛧䜎䛩䚹䐟ཷ㦂⪅ᩘ䜢ධຊ䛧䚸Ⓩ㘓䝪䝍䞁䜢ᢲ䛧䜎䛩䚹䐡ྜィⅬ䛸ᖹᆒⅬ䛜⾲♧䛥䜜䜎䛩䚹䐠ྡ๓䛸Ⅼᩘ䜢ධຊ䛩䜛䝪䝑䜽䝇䛜䚸ཷ㦂⪅ᩘศ⧞䜚㏉䛧⾲♧䛥䜜䜎䛩䚹䝇䝔䝑䝥1. 䝋䝸䝳䞊䝅䝵䞁䜢㛤䛟
1.

Visual Studio 䛷௨ୗ䛾䝋䝸䝳䞊䝅䝵䞁䝣䜯䜲䝹䜢㛤䛝䜎䛩䚹₇⩦⏝䝕䞊䝍¥Starter¥➨ 2 ❶¥⦎⩦ 4¥MyScore¥MyScore.sln233

➨ 2 ❶㻌 ₇⩦

䝇䝔䝑䝥2. 䝴䞊䝄䞊䜲䞁䝍䞊䝣䜵䜲䝇䛾☜ㄆ1.

MainForm 䛻㓄⨨䛥䜜䛶䛔䜛䝁䞁䝖䝻䞊䝹䜢☜ㄆ䛧䜎䛩䚹

ExamineeNumBox
RegisterButton
TotalLabel
AverageLabel
AStudentsLabel
BStudentsLabel
CStudentsLabelཧ⪃䠖NumericUpDown 䝁䞁䝖䝻䞊䝹
NumericUpDown 䝁䞁䝖䝻䞊䝹䜢฼⏝䛩䜛䛸䚸䜰䝥䝸䜿䞊䝅䝵䞁ᐇ⾜᫬䛻䚸┤᥋ᩘ್䜢ධຊ䛩䜛䛣䛸䜒䚸ྑഃ䛾ୖୗ䝪䝍䞁䜢䜽䝸䝑䜽䛧䛶ᩘ್䜢ቑῶ䛥䛫䜛䛣䛸䜒䛷䛝䜎䛩䚹㻌䝇䝔䝑䝥3. 䝥䝻䜾䝷䝮䝁䞊䝗䛾グ㏙
1.

RegisterButton 䝪䝍䞁䛾 RegisterButton_Click 䜲䝧䞁䝖䝝䞁䝗䝷䞊䜢⾲♧䛧䚸௨ୗ䛾䝁䞊䝗䜢䚸䝠䞁䝖䜢ཧ⪃䛻᏶ᡂ䛥䛫䜎䛩䚹䖃 䝁䞊䝗
Dim numberStudent As Integer = ExamineeNumBox.Value
Dim name(numberStudent - 1)
䐟 As String
Dim score(numberStudent - 䐠1) As Integer
Dim totalScore As Integer = 0For index = 0 To numberStudent- 1䐡
name(index) = InputBox(index + 1 & "ே┠ࡢྡ๓ࢆධຊࡋ࡚ࡃࡔࡉ࠸")score(index) = InputBox(index + 1 & "ே┠ࡢⅬᩘࢆධຊࡋ࡚ࡃࡔࡉ࠸")totalScore += score(index)
䐢Next
TotalLabel.Text = totalScore234