Reputation: 21
Hey guys so im doing a program for a zodiac finder on vb,The program works and all but my problem is that everytime I run it the DateTimePickerBox goes back to the current date instead of the date I have entered.
Here's my unfinished code;
Public Class HoroscopeSign
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 Dim DOB As Date = txtDOB.Value DOB = txtDOB.Value End Sub End Class
Upvotes: 2
Views: 84
Reputation: 216243
So you have declared your function Process
to return a string, but you don't return anything from that function. The problem then arises when you try to assign the return value of that function to the txtDOB.Text
property. You don't return anything and so the txtDOB
resets itself to the current date
You should decide what string (in a date format) you want to return or better change your Process
function to return a DateTime
and assign that value to txtDOB.Value
property. Or just change these lines to
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
Upvotes: 0