DateTimePicker:盒子回到原来的日期?
DateTimePicker: the box goes back to it's original date?
大家好,我正在 vb 上做一个星座查找程序,该程序有效,但我的问题是每次我 运行 DateTimePickerBox 都会返回到当前日期我输入的日期。
这是我未完成的代码;
Public Class 星座
Private Sub HoroscopeSign_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'DateTimePicker.Format = DateTimePickerFormat.Custom
'DateTimePicker.CustomFormat = "dd MMMM yyyy"
txtDOB.Format = DateTimePickerFormat.Short
End Sub
Private Sub btnEnter_Click(sender As System.Object, e As System.EventArgs) Handles btnEnter.Click
Dim DOB As Date = txtDOB.Value
txtDOB.Text = Process(DOB)
End Sub
Public Function Process(dateOfBirth As Date) As String
Dim sign As String
Dim info As String
Dim BirthYear As Integer = dateOfBirth.Year
Dim BirthMonth As Integer = dateOfBirth.Month
Dim BirthDay As Integer = dateOfBirth.Day
If txtDOB.Value >= New Date(BirthYear, 1, 20) And txtDOB.Value <= New Date(BirthYear, 2, 18) Then
PBHoroscope.Load("E:\Aquarius.jpg")
sign = "Aquarius"
info = ""
Else txtDOB.Value >= New Date(BirthYear, 2, 19) And txtDOB.Value <= New Date(BirthYear, 3, 20) Then
PBHoroscope.Load("E:\Pisces.jpg")
sign = "Pisces"
lblSign.Text = sign
lblDescription.Text = info
End Function
Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles btnExit.Click
Dim a As Integer
a = MsgBox("Do you want to exit this application", vbYesNo, "Exit Application")
If a = vbYes Then
MsgBox("Thank you for using this application", vbOKOnly, "Exit Application")
End
Else
Me.Show()
End If
End Sub
Private Sub txtDOB_ValueChanged(sender As System.Object, e As System.EventArgs) handles txtDOB.ValueChanged
将 DOB 调暗为日期 = txtDOB.Value
出生日期 = txtDOB.Value
结束子
结束Class
因此,您已将函数 Process
声明为 return 字符串,但您并未 return 从该函数中获取任何内容。当您尝试将该函数的 return 值分配给 txtDOB.Text
属性 时,问题就出现了。您没有 return 任何东西,因此 txtDOB
将自身重置为当前日期
您应该决定要 return 的字符串(日期格式)或更好地将 Process
函数更改为 return a DateTime
并分配该值至 txtDOB.Value
属性。或者只是将这些行更改为
Private Sub btnEnter_Click(sender As System.Object, e As System.EventArgs) Handles btnEnter.Click
' REMOVE THIS LINE Dim DOB As Date = txtDOB.Value
' REMOVE THIS LINE txtDOB.Text = Process(DOB)
Process(txtDOB.Value)
End Sub
大家好,我正在 vb 上做一个星座查找程序,该程序有效,但我的问题是每次我 运行 DateTimePickerBox 都会返回到当前日期我输入的日期。
这是我未完成的代码;
Public Class 星座
Private Sub HoroscopeSign_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'DateTimePicker.Format = DateTimePickerFormat.Custom
'DateTimePicker.CustomFormat = "dd MMMM yyyy"
txtDOB.Format = DateTimePickerFormat.Short
End Sub
Private Sub btnEnter_Click(sender As System.Object, e As System.EventArgs) Handles btnEnter.Click
Dim DOB As Date = txtDOB.Value
txtDOB.Text = Process(DOB)
End Sub
Public Function Process(dateOfBirth As Date) As String
Dim sign As String
Dim info As String
Dim BirthYear As Integer = dateOfBirth.Year
Dim BirthMonth As Integer = dateOfBirth.Month
Dim BirthDay As Integer = dateOfBirth.Day
If txtDOB.Value >= New Date(BirthYear, 1, 20) And txtDOB.Value <= New Date(BirthYear, 2, 18) Then
PBHoroscope.Load("E:\Aquarius.jpg")
sign = "Aquarius"
info = ""
Else txtDOB.Value >= New Date(BirthYear, 2, 19) And txtDOB.Value <= New Date(BirthYear, 3, 20) Then
PBHoroscope.Load("E:\Pisces.jpg")
sign = "Pisces"
lblSign.Text = sign
lblDescription.Text = info
End Function
Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles btnExit.Click
Dim a As Integer
a = MsgBox("Do you want to exit this application", vbYesNo, "Exit Application")
If a = vbYes Then
MsgBox("Thank you for using this application", vbOKOnly, "Exit Application")
End
Else
Me.Show()
End If
End Sub
Private Sub txtDOB_ValueChanged(sender As System.Object, e As System.EventArgs) handles txtDOB.ValueChanged 将 DOB 调暗为日期 = txtDOB.Value 出生日期 = txtDOB.Value 结束子 结束Class
因此,您已将函数 Process
声明为 return 字符串,但您并未 return 从该函数中获取任何内容。当您尝试将该函数的 return 值分配给 txtDOB.Text
属性 时,问题就出现了。您没有 return 任何东西,因此 txtDOB
将自身重置为当前日期
您应该决定要 return 的字符串(日期格式)或更好地将 Process
函数更改为 return a DateTime
并分配该值至 txtDOB.Value
属性。或者只是将这些行更改为
Private Sub btnEnter_Click(sender As System.Object, e As System.EventArgs) Handles btnEnter.Click
' REMOVE THIS LINE Dim DOB As Date = txtDOB.Value
' REMOVE THIS LINE txtDOB.Text = Process(DOB)
Process(txtDOB.Value)
End Sub