Public Class Form1
Private Sub GroupBox1_Enter(sender As Object, e As EventArgs) Handles gpbx1.Enter
End Sub
Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles chk20.CheckedChanged
End Sub
Dim Age As Integer
Dim Gender As String
Dim Male As String
Dim Female As String
Dim child As String
Dim teen As String
Dim adult As String
Dim agerange As String
Dim TeenMan As String
Dim teengirl As String
Dim childgirl As String
Dim childboy As String
Dim adultman As String
Dim adultgirl As String
Dim agegen As String
Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles chk40.CheckedChanged
End Sub
Private Sub CheckBox4_CheckedChanged(sender As Object, e As EventArgs) Handles chk60.CheckedChanged
End Sub
Private Sub CheckBox9_CheckedChanged(sender As Object, e As EventArgs)
End Sub
Private Sub GroupBox1_Enter_1(sender As Object, e As EventArgs) Handles GroupBox1.Enter
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
Age = TextBox1.Text()
End Sub
Private Sub Label3_Click(sender As Object, e As EventArgs) Handles Label3.Click
End Sub
Private Sub CheckBox6_CheckedChanged(sender As Object, e As EventArgs) Handles chk90.CheckedChanged
End Sub
Function determineage()
Age = Int(TextBox1.Text)
Return True
End Function
Function getgender()
If CheckBox7.Checked = True Then
Gender = Male
ElseIf CheckBox8.Checked = True Then
Gender = Female
ElseIf CheckBox7.Checked = False And CheckBox8.Checked = False Then
MessageBox.Show("Please select a gender")
End If
Return True
End Function
Function determineagerange()
If 20 < Age < 200 Then
agerange = adult
ElseIf 10 < Age < 20 Then
agerange = teen
ElseIf 10 < Age < 0 Then
agerange = child
End If
Return True
End Function
Function determineagegender()
If agerange = adult And Gender = Male Then
agegen = adultman
ElseIf agerange = adult And Gender = Female Then
agegen = adultgirl
ElseIf agerange = teen And Gender = Male Then
agegen = TeenMan
ElseIf agerange = teen And Gender = Female Then
agegen = teengirl
ElseIf agerange = child And Gender = Male Then
agegen = childboy
ElseIf agerange = child And Gender = Female Then
agegen = childgirl
End If
Return True
End Function
Function Temperature()
If chk20.Checked = True And agegen = TeenMan Then
PictureBox1.Load("H:\AP CSP\VB\MALE\Teen\20.jpg")
ElseIf chk40.Checked = True And agegen = TeenMan Then
PictureBox1.Load("H:\AP CSP\VB\MALE\Teen\40.jpg")
ElseIf chk50.Checked = True And agegen = TeenMan Then
PictureBox1.Load("H:\AP CSP\VB\MALE\Teen\50.jpg")
ElseIf chk60.Checked = True And agegen = TeenMan Then
PictureBox1.Load("H:\AP CSP\VB\MALE\Teen\60.jpg")
ElseIf chk80.Checked = True And agegen = TeenMan Then
PictureBox1.Load("H:\AP CSP\VB\MALE\Teen\80.jpg")
ElseIf chk90.Checked = True And agegen = TeenMan Then
PictureBox1.Load("H:\AP CSP\VB\MALE\Teen\90.jpg")
End If
If chk20.Checked = True And agegen = adultman Then
PictureBox1.Load("H:\AP CSP\VB\MALE\Adult\20.jpg")
ElseIf chk40.Checked = True And agegen = adultman Then
PictureBox1.Load("H:\AP CSP\VB\MALE\Adult\40.jpg")
ElseIf chk50.Checked = True And agegen = adultman Then
PictureBox1.Load("H:\AP CSP\VB\MALE\Adult\50.jpg")
ElseIf chk60.Checked = True And agegen = adultman Then
PictureBox1.Load("H:\AP CSP\VB\MALE\Adult\60.jpg")
ElseIf chk80.Checked = True And agegen = adultman Then
PictureBox1.Load("H:\AP CSP\VB\MALE\Adult\80.jpg")
ElseIf chk90.Checked = True And agegen = adultman Then
PictureBox1.Load("H:\AP CSP\VB\MALE\Adult\90.jpg")
End If
If chk20.Checked = True And agegen = childboy Then
PictureBox1.Load("H:\AP CSP\VB\MALE\Child\20.jpg")
ElseIf chk40.Checked = True And agegen = childboy Then
PictureBox1.Load("H:\AP CSP\VB\MALE\Child\40.jpg")
ElseIf chk50.Checked = True And agegen = childboy Then
PictureBox1.Load("H:\AP CSP\VB\MALE\Child\50.jpg")
ElseIf chk60.Checked = True And agegen = childboy Then
PictureBox1.Load("H:\AP CSP\VB\MALE\Child\60.jpg")
ElseIf chk80.Checked = True And agegen = childboy Then
PictureBox1.Load("H:\AP CSP\VB\MALE\Child\80].jpg")
ElseIf chk90.Checked = True And agegen = childboy Then
PictureBox1.Load("H:\AP CSP\VB\MALE\Child\90.jpg")
End If
Return True
End Function
function temperaturegirl()
If chk20.Checked = True And agegen = teengirl Then
PictureBox1.Load("H:\AP CSP\VB\FEMALE\Teen\20.jpg")
ElseIf chk40.Checked = True And agegen = teengirl Then
PictureBox1.Load("H:\AP CSP\VB\FEMALE\Teen\40.jpg")
ElseIf chk50.Checked = True And agegen = teengirl Then
PictureBox1.Load("H:\AP CSP\VB\FEMALE\Teen\50.jpg")
ElseIf chk60.Checked = True And agegen = teengirl Then
PictureBox1.Load("H:\AP CSP\VB\FEMALE\Teen\60.jpg")
ElseIf chk80.Checked = True And agegen = teengirl Then
PictureBox1.Load("H:\AP CSP\VB\FEMALE\Teen\80.jpg")
ElseIf chk90.Checked = True And agegen = teengirl Then
PictureBox1.Load("H:\AP CSP\VB\FEMALE\Teen\90.jpg")
End If
If chk20.Checked = True And agegen = adultgirl Then
PictureBox1.Load("H:\AP CSP\VB\FEMALE\Adult\20.jpg")
ElseIf chk40.Checked = True And agegen = adultgirl Then
PictureBox1.Load("H:\AP CSP\VB\FEMALE\Adult\30.jpg")
ElseIf chk50.Checked = True And agegen = adultgirl Then
PictureBox1.Load("H:\AP CSP\VB\FEMALE\Adult\50.jpg")
ElseIf chk60.Checked = True And agegen = adultgirl Then
PictureBox1.Load("H:\AP CSP\VB\FEMALE\Adult\60.jpg")
ElseIf chk80.Checked = True And agegen = adultgirl Then
PictureBox1.Load("H:\AP CSP\VB\FEMALE\Adult\70.jpg")
ElseIf chk90.Checked = True And agegen = adultgirl Then
PictureBox1.Load("H:\AP CSP\VB\FEMALE\Adult\90.jpg")
End If
If chk20.Checked = True And agegen = childgirl Then
PictureBox1.Load("H:\AP CSP\VB\FEMALE\Child\20.jpg")
ElseIf chk40.Checked = True And agegen = childgirl Then
PictureBox1.Load("H:\AP CSP\VB\FEMALE\Child\40.jpg")
ElseIf chk50.Checked = True And agegen = childgirl Then
PictureBox1.Load("H:\AP CSP\VB\FEMALE\Child\50.jpg")
ElseIf chk60.Checked = True And agegen = childgirl Then
PictureBox1.Load("H:\AP CSP\VB\FEMALE\Child\60.jpg")
ElseIf chk80.Checked = True And agegen = childgirl Then
PictureBox1.Load("H:\AP CSP\VB\FEMALE\Child\80].jpg")
ElseIf chk90.Checked = True And agegen = childgirl Then
PictureBox1.Load("H:\AP CSP\VB\FEMALE\Child\90.jpg")
End If
Return True
End Function
Private Sub btcalc_Click(sender As Object, e As EventArgs) Handles btcalc.Click
getgender()
determineage()
determineagerange()
determineagegender()
If Gender = Male Then
Temperature()
ElseIf Gender = Female Then
temperaturegirl()
End If
End Sub
Private Sub CheckBox5_CheckedChanged(sender As Object, e As EventArgs) Handles chk80.CheckedChanged
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub CheckBox7_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox7.CheckedChanged
End Sub
Private Sub CheckBox8_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox8.CheckedChanged
End Sub
End Class
程序的要点是根据用户提供的信息显示图像,但是它只显示每个输入的年轻男孩的图像。图像总是适合给定温度,但年龄和性别是错误的。
答案 0 :(得分:1)
这段代码写得非常糟糕,但我不会太过深入。
你最大的问题是你为一切创造了一堆变量,这些变量总是空的。
Gender
,Male
和Female
都是作为字符串变量创建的,没有任何值。
设置Gender = Male
时,您将Gender
设置为空字符串,因为Male
是一个空字符串。设置Gender = Female
时,您会执行相同的操作。
在比较时,If Gender = Male
总是成功,因为你正在比较两个空字符串。
最好只创建Gender
变量(摆脱Male
&amp; Female
变量。然后将其值设置为字符串“男性”或“女性”:
Gender = "Male"
然后根据If
语句中的字符串检查值:
If Gender = "Male" Then
年龄范围相同的问题。