練習問題１－１

Button1

Label1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickLabel1.Text = Label1.Text + 2
End Sub

練習問題１－２

Button1

Button2Label1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickLabel1.Text = Label1.Text+ 2
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickLabel1.Text = Label1.Text - 2
End Sub

練習問題２－１

TextBox1
TextBox2
Button1TextBox3

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a, h As Double
a = Val(TextBox1.Text)
h = Val(TextBox2.Text)
TextBox3.Text = a * h / 2
End Sub

練習問題２－２

TextBox1
TextBox2
TextBox3
Button1
TextBox4

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a, b, h As Double
a = Val(TextBox1.Text)
b = Val(TextBox2.Text)
h = Val(TextBox3.Text)
TextBox4.Text = (a + b) * h / 2
End Sub

練習問題２－３

TextBox1
Button1
TextBox2
TextBox3

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim r As Doubler = Val(TextBox1.Text)
TextBox2.Text = 4 * Math.PI * r ^ 2
TextBox3.Text = 4 * Math.PI * r ^ 3 / 3
End Sub

練習問題３－１

TextBox1

TextBox2

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
TextBox1.TextChanged
Dim a, b As Integera = Val(TextBox1.Text)b = a Mod 2
If b = 0 Then
TextBox2.Text = "偶数"ElseTextBox2.Text = "奇数"End IfEnd Sub

練習問題３－２

TextBox1
TextBox2
TextBox3

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
TextBox1.TextChanged, TextBox2.TextChanged
Dim a, b, c As Single
a = Val(TextBox1.Text)
b = Val(TextBox2.Text)
c = (a - 100) * 0.9
If b > c * 1.1 Then
TextBox3.Text = "ふとりすぎです"
ElseIf b < c * 0.9 Then
TextBox3.Text = "やせすぎです"
ElseTextBox3.Text = "ちょうどいい体重です"
End IfEnd Sub

練習問題３－３
TextBox1GroupBox1
RadioButton1
RadioButton2
RadioButton3

Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
RadioButton1.CheckedChanged, RadioButton2.CheckedChanged, RadioButton3.CheckedChanged
If (RadioButton1.Checked = True) Then
TextBox1.Text = 5000

ElseIf (RadioButton2.Checked = True) Then
TextBox1.Text = 8000
ElseIf (RadioButton3.Checked = True) Then
TextBox1.Text = 10000
End IfEnd Sub

練習問題４－１

TextBox1
TextBox2

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
TextBox1.TextChanged
Dim i, n, s As Integern = Val(TextBox1.Text)
s=1
For i = 1 To n
s=s*i
Next
TextBox2.Text = s
End Sub

練習問題４－２

TextBox1
TextBox2
TextBox3
TextBox4
TextBox5

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
TextBox1.TextChanged
Dim i, s, limit As Integer
limit = Val(TextBox1.Text)
Doi=i+1s = i * (i + 1) * (i + 2)
Loop While s <= limit
TextBox2.Text = i
TextBox3.Text = i + 1

TextBox4.Text = i + 2
TextBox5.Text = s
End Sub

練習問題４－３

TextBox1
TextBox2
TextBox3

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
TextBox1.TextChanged, TextBox2.TextChanged
Dim i, j, s, n, m As Integern = Val(TextBox1.Text)
m = Val(TextBox2.Text)
s=0
For i = n To m
For j = 1 To 9
s=s+i*j
Next jNext i
TextBox3.Text = s
End Sub

練習問題５－１

TextBox1

TextBox2

Button1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
Dim n As Integer
Dim min As Integer
n = TextBox1.Lines.Length
Dim a(n - 1) As Integer
For i = 0 To n - 1

a(i) = Val(TextBox1.Lines(i))
Next imin = a(0)For i = 1 To n - 1
If min > a(i) Thenmin = a(i)End IfNext i
TextBox2.Text = min
End Sub

練習問題５－２

TextBox1

TextBox2

Button1

Button2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
Dim j As Integer
Dim n As Integer
Dim work As Integer
n = TextBox1.Lines.Length
Dim a(n - 1) As Integer
For i = 0 To n - 1a(i) = Val(TextBox1.Lines(i))
Next i
For i = 0 To n - 2
For j = i + 1 To n - 1
If a(i) > a(j) Thenwork = a(i)a(i) = a(j)a(j) = work
End IfNext jNext i
TextBox2.Text = ""For i = 0 To n - 1
TextBox2.Text = TextBox2.Text & a(i) & vbCrLf
Next iEnd Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim i As Integer
Dim j As Integer
Dim n As Integer
Dim work As Integer
n = TextBox1.Lines.Length
Dim a(n - 1) As Integer
For i = 0 To n - 1a(i) = Val(TextBox1.Lines(i))
Next i
For i = 0 To n - 2
For j = i + 1 To n - 1
If a(i) < a(j) Thenwork = a(i)a(i) = a(j)a(j) = work
End IfNext jNext i
TextBox2.Text = ""For i = 0 To n - 1
TextBox2.Text = TextBox2.Text & a(i) & vbCrLf
Next iEnd Sub

練習問題５－３

TextBox1

TextBox3

TextBox2

TextBox4
TextBox6

TextBox5

TextBox7

Button1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i, j, k, data(2, 5), work(2), heikinn(2) As Integer
Dim simei(5), worksimei As String
For i = 0 To 5simei(i) = TextBox1.Lines(i)data(0, i) = Val(TextBox2.Lines(i))
data(1, i) = Val(TextBox3.Lines(i))
Next iFor i = 0 To 5data(2, i) = data(0, i) + data(1, i)
Next i
For i = 0 To 2
For j = 0 To 5
heikinn(i) = heikinn(i) + data(i, j)
Next jheikinn(i) = heikinn(i) / 6
Next i
TextBox5.Text = heikinn(0)TextBox6.Text = heikinn(1)TextBox7.Text = heikinn(2)For i = 0 To 4
For j = i + 1 To 5
If data(2, i) < data(2, j) Thenworksimei = simei(i)simei(i) = simei(j)simei(j) = worksimei
For k = 0 To 2work(k) = data(k, i)data(k, i) = data(k, j)data(k, j) = work(k)Next kEnd IfNext jNext i
TextBox1.Text = ""TextBox2.Text = ""TextBox3.Text = ""TextBox4.Text = ""For i = 0 To 5
TextBox1.Text = TextBox1.Text & simei(i) & vbCrLf
TextBox2.Text = TextBox2.Text & data(0, i) & vbCrLf
TextBox3.Text = TextBox3.Text & data(1, i) & vbCrLf
TextBox4.Text = TextBox4.Text & data(2, i) & vbCrLf
Next iEnd Sub

練習問題６－１

Button 1
TextBox1
TextBox2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim n, s, a As Integer
FileOpen(1, "data.txt", OpenMode.Input)
n=0
s=0
Do Until EOF(1)Input(1, a)
n=n+1
s=s+a
Loop
TextBox1.Text = n
TextBox2.Text = s / n
FileClose()
End Sub

練習問題６－２

Button 1
TextBox1
TextBox2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a, maxa As Integer
Dim namae, maxnamae As StringFileOpen(1, "data.txt", OpenMode.Input)
maxnamae = ""maxa = 0namae = ""Do Until EOF(1)Input(1, namae)
Input(1, a)
If (a > maxa) Then
maxnamae = namae
maxa = a
End IfLoop
TextBox1.Text = maxnamae
TextBox2.Text = maxa
FileClose()
End Sub

練習問題６－３

TextBox1

TextBox3

TextBox2

TextBox4

Button1

Button2

Public Structure seiseki<VBFixedString(12)> Public simei As String
Public kokugo As Integer
Public suugaku As Integer
Public eigo As Integer
End Structure
Dim kojinseiseki As seiseki
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
Dim fname As String
SaveFileDialog1.ShowDialog()
fname = SaveFileDialog1.FileName
FileOpen(1, fname, OpenMode.Random, , , Len(kojinseiseki))
For i = 1 To 6
kojinseiseki.simei = TextBox1.Lines(i - 1)
kojinseiseki.kokugo = Val(TextBox2.Lines(i - 1))
kojinseiseki.suugaku = Val(TextBox3.Lines(i - 1))
kojinseiseki.eigo = Val(TextBox4.Lines(i - 1))
FilePut(1, kojinseiseki, i)Next
FileClose(1)End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim i As Integer
Dim fname As String
OpenFileDialog1.ShowDialog()
fname = OpenFileDialog1.FileName
FileOpen(1, fname, OpenMode.Random, , , Len(kojinseiseki))
TextBox1.Text = ""TextBox2.Text = ""TextBox3.Text = ""TextBox4.Text = ""For i = 1 To 6
FileGet(1, kojinseiseki, i)TextBox1.Text = TextBox1.Text & kojinseiseki.simei & vbCrLf
TextBox2.Text = TextBox2.Text & kojinseiseki.kokugo & vbCrLf
TextBox3.Text = TextBox3.Text & kojinseiseki.suugaku & vbCrLf
TextBox4.Text = TextBox4.Text & kojinseiseki.eigo & vbCrLf
Next i
FileClose(1)End Sub

練習問題７－１

TextBox1

TextBox3

TextBox2

TextBox4

Button1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim simei(5) As String
Dim data(5, 2) As Integer
nyuuryoku(simei, data)keisan(data)
narabikae(simei, data)hyouji(simei, data)
End Sub
Private Sub nyuuryoku(ByRef simei() As String, ByRef data(,) As Integer)
Dim i As Integer
For i = 0 To 5simei(i) = TextBox1.Lines(i)data(i, 0) = Val(TextBox2.Lines(i))
data(i, 1) = Val(TextBox3.Lines(i))
Next iEnd Sub
Private Sub keisan(ByRef data(,) As Integer)
Dim i As Integer
For i = 0 To 5data(i, 2) = data(i, 0) + data(i, 1)
Next iEnd Sub
Private Sub narabikae(ByRef simei() As String, ByRef data(,) As Integer)
Dim i, j, k, work As Integer
Dim worksimei As String
For i = 0 To 4

For j = i + 1 To 5
If data(i, 2) < data(j, 2) Thenworksimei = simei(i)simei(i) = simei(j)simei(j) = worksimei
For k = 0 To 2
work = data(i, k)data(i, k) = data(j, k)data(j, k) = work
Next kEnd IfNext jNext iEnd Sub
Private Sub hyouji(ByRef simei() As String, ByRef data(,) As Integer)
Dim i As Integer
TextBox1.Text = ""TextBox2.Text = ""TextBox3.Text = ""TextBox4.Text = ""For i = 0 To 5
TextBox1.Text = TextBox1.Text & simei(i) & vbCrLf
TextBox2.Text = TextBox2.Text & data(i, 0) & vbCrLf
TextBox3.Text = TextBox3.Text & data(i, 1) & vbCrLf
TextBox4.Text = TextBox4.Text & data(i, 2) & vbCrLf
Next iEnd Sub

練習問題７－２

TextBox1
TextBox2

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
TextBox1.TextChanged
Dim a As Integera = Val(TextBox1.Text)
TextBox2.Text = hantei(a)End Sub
Function hantei(ByVal a As Integer) As String
If a >= 80 Then

hantei = "A"
ElseIf a >= 70 Thenhantei = "B"
ElseIf a >= 60 Thenhantei = "C"
Elsehantei = "D"End If
End Function

練習問題７－３

TextBox1
TextBox2
TextBox3
TextBox4

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
TextBox1.TextChanged, TextBox2.TextChanged, TextBox3.TextChanged
Dim k, a As Double
Dim n As Integera = Val(TextBox1.Text)
k = Val(TextBox2.Text)
n = Val(TextBox3.Text)
TextBox4.Text = fukuri(a, k, n)
End Sub
Function fukuri(ByVal a As Double, ByVal k As Double, ByVal n As Integer) As Integer
Dim i As Integer
For i = 1 To na = a * (1 + k / 100)
Next ifukuri = aEnd Function

練習問題８－１

Button1

PictureBox1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a As Graphics = PictureBox1.CreateGraphics()
Dim i As Integer
For i = 0 To 330 Step 30
a.DrawPie(Pens.Red, 0, 0, 100, 100, i, 30)
Next iEnd Sub

練習問題８－２

PictureBox1

Button1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a As Graphics = PictureBox1.CreateGraphics()
Dim i, xs As Integer
Dim s As Double
For i = 0 To 720
s = i / 360 * 2 * Math.PI
xs = -50 * (Math.Sin(s) + 1 / 3 * Math.Sin(3 * s) + 1 / 5 * Math.Sin(5 * s)) + 60
a.FillRectangle(Brushes.Red, i, xs, 2, 2)
Next iEnd Sub

練習問題８－３

Button2

Button1

PictureBox1PictureBox2

Button4

Button3

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim fname As String
OpenFileDialog1.Filter = "Bitmap Image|*.bmp|JPeg Image|*.jpg|Gif Image|*.gif"
OpenFileDialog1.ShowDialog()
fname = OpenFileDialog1.FileName
Dim bmap As Bitmap = New Bitmap(fname)PictureBox1.Image = bmap
PictureBox2.Size = PictureBox1.Size
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim fname As String
OpenFileDialog1.Filter = "Bitmap Image|*.bmp|JPeg Image|*.jpg|Gif Image|*.gif"
OpenFileDialog1.ShowDialog()
fname = OpenFileDialog1.FileName
Dim bmap As Bitmap = New Bitmap(fname)PictureBox2.Image = bmap
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim bmpa As Bitmap = PictureBox1.Image
Dim bmpb As Bitmap = PictureBox2.Image
Dim iroa As Color
Dim heikin As Integer
Dim i As Integer
Dim j As Integer
For i = 0 To bmpa.Width - 1
For j = 0 To bmpa.Height - 1
iroa = bmpa.GetPixel(i, j)heikin = Int((Val(iroa.R) + Val(iroa.G) + Val(iroa.B)) / 3)
If (heikin < 250) Thenbmpb.SetPixel(i, j, iroa)
End IfNext

Next
PictureBox2.Image = bmpb
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim fname As String
SaveFileDialog1.Filter = "Bitmap Image|*.bmp"
SaveFileDialog1.ShowDialog()
fname = SaveFileDialog1.FileName
Dim bmap As Bitmap
bmap = PictureBox2.Image
bmap.Save(fname, System.Drawing.Imaging.ImageFormat.Bmp)
End Sub

練習問題９－１
Label1
PictureBox1

PictureBox3

PictureBox5

PictureBox7

PictureBox9

PictureBox11

PictureBox2

PictureBox4

PictureBox6

PictureBox8

PictureBox10

PictureBox12

Timer1
Enable を True

PictureBox1 から PictureBox6 の上にInterval を 700

PictureBox7 から PictureBox12 を重ねるDim a As Integer
Dim pic(6) As PictureBox
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integerpic(1) = PictureBox7
pic(2) = PictureBox8
pic(3) = PictureBox9
pic(4) = PictureBox10
pic(5) = PictureBox11
pic(6) = PictureBox12
For i = 1 To 6pic(i).Visible = False
Next iRandomize()a = Int(Rnd() * 6) + 1
pic(a).Visible = True
End Sub
Private Sub PictureBox7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox7.Click,
PictureBox8.Click, PictureBox9.Click, PictureBox10.Click, PictureBox11.Click, PictureBox12.ClickLabel1.Text = Val(Label1.Text) + 1
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
pic(a).Visible = False
a = Int(Rnd() * 6 + 1)
pic(a).Visible = True
End Sub

練習問題９－２

TextBox1

TextBox

TextBox32
TextBox4

TextBox

TextBox6

5
TextBox7

TextBox

TextBox98

Button4

Button1

Button2

Button3Label1

Timer1
Enable を True
Interval を 700

Dim f1 As Integer
Dim f2 As Integer
Dim f3 As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadRandomize()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.ClickLabel1.Text = Label1.Text - 1
f1 = 1
f2 = 1
f3 = 1End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickIf (f1 = 1) Then
f1 = 0hantei()
End IfEnd Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickIf (f2 = 1) Then
f2 = 0hantei()
End IfEnd Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.ClickIf (f3 = 1) Then
f3 = 0hantei()
End IfEnd Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If (f1 = 1) Then
TextBox1.Text = Int(Rnd() * 9)
TextBox4.Text = Int(Rnd() * 9)
TextBox7.Text = Int(Rnd() * 9)
End IfIf (f2 = 1) Then
TextBox2.Text = Int(Rnd() * 9)
TextBox5.Text = Int(Rnd() * 9)
TextBox8.Text = Int(Rnd() * 9)
End IfIf (f3 = 1) Then
TextBox3.Text = Int(Rnd() * 9)
TextBox6.Text = Int(Rnd() * 9)
TextBox9.Text = Int(Rnd() * 9)
End IfEnd Sub
Private Sub hantei()If (f1 = 0 And f2 = 0 And f3 = 0) ThenIf (TextBox1.Text = TextBox2.Text And TextBox1.Text = TextBox3.Text) Then
Label1.Text = Label1.Text + 50
If (TextBox1.Text = 7) Then
Label1.Text = Label1.Text + 50
End IfEnd IfIf (TextBox4.Text = TextBox5.Text And TextBox4.Text = TextBox6.Text) Then
Label1.Text = Label1.Text + 50
If (TextBox4.Text = 7) Then
Label1.Text = Label1.Text + 50
End IfEnd IfIf (TextBox7.Text = TextBox8.Text And TextBox7.Text = TextBox9.Text) Then
Label1.Text = Label1.Text + 50
If (TextBox7.Text = 7) Then
Label1.Text = Label1.Text + 50

End If
End IfIf (TextBox1.Text = TextBox5.Text And TextBox1.Text = TextBox9.Text) Then
Label1.Text = Label1.Text + 50
If (TextBox1.Text = 7) Then
Label1.Text = Label1.Text + 50
End IfEnd IfIf (TextBox3.Text = TextBox5.Text And TextBox3.Text = TextBox7.Text) Then
Label1.Text = Label1.Text + 50
If (TextBox3.Text = 7) Then
Label1.Text = Label1.Text + 50
End IfEnd IfEnd IfEnd Sub