472,784 Members | 834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,784 software developers and data experts.

Day Finder Program

Hi,

I'm very new to VB and need help please. I want to build a 'Day Finder' program that tells you the day for a given date between 1600 & 2100 and whether it is past, present or future. I have coded the variables and algorithm for a form with 3 text box entries and a command button . How do I get VB to recognise whether the date is past, present or future i.e. by looking to today's date? Is there any existing VB code out there? (i've had a look and could only find a c++ program which doesn't help), thanks
Jul 13 '07 #1
8 2741
ilearneditonline
130 Expert 100+
can you provide a code snippet of what you have done thus far?
Jul 13 '07 #2
Mague
137 100+
can you provide a code snippet of what you have done thus far?

Im assuming you are using vb.net cause you said you were new

I dont know excally what you want it to do but hope this helps.

Dim ts As TimeSpan
ts = (CType(DateTimePicker1.Value.Subtract(Today), TimeSpan))
If ts.TotalDays < 1 Then
Label1.Text = "Timespan: Past Date or Today's Date"
Else : Label1.Text = "Timespan: Future Date"
End If

I found this on google. I dont understand it but you might want to

The website is
http://blogs.vbcity.com/xtab/archive/2005/12/26/5755.aspx

Hope this helps
Mague
Jul 13 '07 #3
pureenhanoi
175 100+
Hi,

I'm very new to VB and need help please. I want to build a 'Day Finder' program that tells you the day for a given date between 1600 & 2100 and whether it is past, present or future. I have coded the variables and algorithm for a form with 3 text box entries and a command button . How do I get VB to recognise whether the date is past, present or future i.e. by looking to today's date? Is there any existing VB code out there? (i've had a look and could only find a c++ program which doesn't help), thanks
Subtraction two date directly. If the result < 0 then the date is in the past. If the result >0 then the date is in future.
If ur data was not already the DateTime Type, so, convert it into DateTime first
Example
Date - (Date+1) will return -1
Date - (Date-1) will return +1
(urDate - Date ) < 0 then urDate is in the past
Jul 14 '07 #4
great, thanks all. this is a DateDiff function which i want to use e.g:

Private Function IsPPOrF(ByVal strDate As String) As String
If Not IsDate(strDate) Then
IsPPOrF = "Bad date value"

Else
Select Case DateDiff("d", Now, strDate)
Case 0
IsPPOrF = "Present"
Case Is < 0
IsPPOrF = "Past"
Case Is > 0
IsPPOrF = "Future"
End Select
End If
End Function

how would i add that to my code (which is awful but just about works) so my msgbox says "the date on the 14 jun 1977 is a friday past/present/future"? (it is down at the bottom)

Public Class Gregorian_Calendar_2

'Declare variables

Dim Day As Integer
Dim dayNumber As Integer
Dim Month As String
Dim MonthCase As Integer
Dim Year As Integer


Private Sub HScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar1.Scroll

'Horizontal Scroll Bar gives the day of the month'

Dim HScrollBar As Integer
HScrollBar = HScrollBar1.Value
txtDay.Text = HScrollBar

End Sub

Private Sub txtYear_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtYear.TextChanged

'Only 4 digit years between 1900 and 2100 are allowed

Year = txtYear.Text
If Year < 1900 Or Year > 2100 Then MsgBox(" Please enter a year between 1900 and 2100 ")

End Sub


Private Sub btnFindDay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFindDay.Click

'Match variables to user input

Month = cbMonth.Text
Day = txtDay.Text

'Assign numeric values to combo box items'

Select Case Month
Case "Jan"
MonthCase = 1
Case "Feb"
MonthCase = 2
Case "Mar"
MonthCase = 3
Case "Apr"
MonthCase = 4
Case "May"
MonthCase = 5
Case "Jun"
MonthCase = 6
Case "Jul"
MonthCase = 7
Case "Aug"
MonthCase = 8
Case "Sep"
MonthCase = 9
Case "Oct"
MonthCase = 10
Case "Nov"
MonthCase = 11
Case "Dec"
MonthCase = 12

End Select

'Algorithm to use for months January or February: calculates a value 0 to 6 for Saturday to Friday

If Month = "Jan" Or Month = "Feb" Then

dayNumber = ((Day + (2 * MonthCase) + (0.6 * (MonthCase + 1)) _
+ Year + (Year / 4) - (Year / 100) + ((Year / 400) + 2)) Mod 7) - 1

Else

'Algorithm to use for months March to December: calculates a value 0 to 6 for Saturday to Friday

dayNumber = (Day + (2 * (MonthCase + 12)) + (0.6 * (MonthCase + 13)) _
+ (Year - 1) + ((Year - 1) / 4) - ((Year - 1) / 100 + (((Year - 1) / 400) + 2))) Mod 7

End If

'Tell the user what day it is from the date entered

If dayNumber = 0 Then MsgBox(" The day on the " & Day & " " & Month & " " & Year & " is a Saturday ")
If dayNumber = 1 Then MsgBox(" The day on the " & Day & " " & Month & " " & Year & " is a Sunday ")
If dayNumber = 2 Then MsgBox(" The day on the " & Day & " " & Month & " " & Year & " is a Monday ")
If dayNumber = 3 Then MsgBox(" The day on the " & Day & " " & Month & " " & Year & " is a Tuesday ")
If dayNumber = 4 Then MsgBox(" The day on the " & Day & " " & Month & " " & Year & " is a Wednesday ")
If dayNumber = 5 Then MsgBox(" The day on the " & Day & " " & Month & " " & Year & " is a Thursday ")
If dayNumber = 6 Then MsgBox(" The day on the " & Day & " " & Month & " " & Year & " is a Friday ")

End Sub

'Exit Program

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

End

End Sub
End Class
Jul 15 '07 #5
pureenhanoi
175 100+
great, thanks all. this is a DateDiff function which i want to use e.g:

Private Function IsPPOrF(ByVal strDate As String) As String
If Not IsDate(strDate) Then
IsPPOrF = "Bad date value"

Else
Select Case DateDiff("d", Now, strDate)
Case 0
IsPPOrF = "Present"
Case Is < 0
IsPPOrF = "Past"
Case Is > 0
IsPPOrF = "Future"
End Select
End If
End Function

how would i add that to my code (which is awful but just about works) so my msgbox says "the date on the 14 jun 1977 is a friday past/present/future"? (it is down at the bottom)

Public Class Gregorian_Calendar_2

'Declare variables

Dim Day As Integer
Dim dayNumber As Integer
Dim Month As String
Dim MonthCase As Integer
Dim Year As Integer


Private Sub HScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar1.Scroll

'Horizontal Scroll Bar gives the day of the month'

Dim HScrollBar As Integer
HScrollBar = HScrollBar1.Value
txtDay.Text = HScrollBar

End Sub

Private Sub txtYear_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtYear.TextChanged

'Only 4 digit years between 1900 and 2100 are allowed

Year = txtYear.Text
If Year < 1900 Or Year > 2100 Then MsgBox(" Please enter a year between 1900 and 2100 ")

End Sub


Private Sub btnFindDay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFindDay.Click

'Match variables to user input

Month = cbMonth.Text
Day = txtDay.Text

'Assign numeric values to combo box items'

Select Case Month
Case "Jan"
MonthCase = 1
Case "Feb"
MonthCase = 2
Case "Mar"
MonthCase = 3
Case "Apr"
MonthCase = 4
Case "May"
MonthCase = 5
Case "Jun"
MonthCase = 6
Case "Jul"
MonthCase = 7
Case "Aug"
MonthCase = 8
Case "Sep"
MonthCase = 9
Case "Oct"
MonthCase = 10
Case "Nov"
MonthCase = 11
Case "Dec"
MonthCase = 12

End Select

'Algorithm to use for months January or February: calculates a value 0 to 6 for Saturday to Friday

If Month = "Jan" Or Month = "Feb" Then

dayNumber = ((Day + (2 * MonthCase) + (0.6 * (MonthCase + 1)) _
+ Year + (Year / 4) - (Year / 100) + ((Year / 400) + 2)) Mod 7) - 1

Else

'Algorithm to use for months March to December: calculates a value 0 to 6 for Saturday to Friday

dayNumber = (Day + (2 * (MonthCase + 12)) + (0.6 * (MonthCase + 13)) _
+ (Year - 1) + ((Year - 1) / 4) - ((Year - 1) / 100 + (((Year - 1) / 400) + 2))) Mod 7

End If

'Tell the user what day it is from the date entered

If dayNumber = 0 Then MsgBox(" The day on the " & Day & " " & Month & " " & Year & " is a Saturday ")
If dayNumber = 1 Then MsgBox(" The day on the " & Day & " " & Month & " " & Year & " is a Sunday ")
If dayNumber = 2 Then MsgBox(" The day on the " & Day & " " & Month & " " & Year & " is a Monday ")
If dayNumber = 3 Then MsgBox(" The day on the " & Day & " " & Month & " " & Year & " is a Tuesday ")
If dayNumber = 4 Then MsgBox(" The day on the " & Day & " " & Month & " " & Year & " is a Wednesday ")
If dayNumber = 5 Then MsgBox(" The day on the " & Day & " " & Month & " " & Year & " is a Thursday ")
If dayNumber = 6 Then MsgBox(" The day on the " & Day & " " & Month & " " & Year & " is a Friday ")

End Sub

'Exit Program

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

End

End Sub
End Class
Sorry to say this. But its a complicated program to do a very small work. Try make something thats not such boring. People said that: everything is begining at zero, but i think thats an invalid statement.
Jul 16 '07 #6
darni
1
hey hi i too faced the same problem..
but i got the soln to get the day wen u type in the date with month and year....
to be frank i got the logic from the agarwal's quantitative aptitude book..
like u first take mod for the y-1... then subtract the result from the value of y-1
... u get two gr8 values a and b say... now perform this in both the values....
1) divide b (say) by 4-say c

2)b=b-c(now)

3)this is to calculate the number of odd days in the year....o1=2*c+b

4)if the number is greater than 7 then perform mod 7 of ans and get hte result...

5) do the same 1-4 procedure in a also...

6)add both the odd num of days...

7)perform mod 7 to get the exact odd days....

8)count the number of days from day 1 of the year till ur i/p date....

9)add it to odd num of days perform mod 7 and get the final answer....
u cud even simplify it... refer to r.s.agarwal's aptitude book u can get it cleared....
use switch case from 0-6 starting from sun to sat... and end up with ur desired result...
all the best..!
Jul 16 '07 #7
pureenhanoi
175 100+
hey hi i too faced the same problem..
but i got the soln to get the day wen u type in the date with month and year....
to be frank i got the logic from the agarwal's quantitative aptitude book..
like u first take mod for the y-1... then subtract the result from the value of y-1
... u get two gr8 values a and b say... now perform this in both the values....
1) divide b (say) by 4-say c

2)b=b-c(now)

3)this is to calculate the number of odd days in the year....o1=2*c+b

4)if the number is greater than 7 then perform mod 7 of ans and get hte result...

5) do the same 1-4 procedure in a also...

6)add both the odd num of days...

7)perform mod 7 to get the exact odd days....

8)count the number of days from day 1 of the year till ur i/p date....

9)add it to odd num of days perform mod 7 and get the final answer....
u cud even simplify it... refer to r.s.agarwal's aptitude book u can get it cleared....
use switch case from 0-6 starting from sun to sat... and end up with ur desired result...
all the best..!
Ouch!!!!!
Nice idea
Jul 17 '07 #8
Killer42
8,435 Expert 8TB
We may have overlooked some simpler options here (unless the required range of 1600 to 2100 isn't acceptable to VB - I haven't checked that).

Here's a code module (VB6) containing two functions to convert a date to a weekday, and a day, month and year to a weekday. As you can see from the code, you don't need a special function, since they both just invoke the Format() function to do the work.

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Public Function Date2Weekday(ByVal parmDate As Date) As String
  4.   Date2Weekday = Format$(parmDate, "ddd")
  5. End Function
  6.  
  7. Public Function DDMMYYYY2Weekday(ByVal parmDD As Byte, ByVal parmMM As Byte, ByVal parmYYYY As Integer) As String
  8.   DDMMYYYY2Weekday = Format$(DateSerial(parmYYYY, parmMM, parmDD), "ddd")
  9. End Function
Jul 17 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Jann Rosendahl | last post by:
Hi friends! Working with the old-fashioned VB6, i'm trying to make my own newsgroup-attachment-finder/decoder/saver. Anyone got an idea for some code, free ocx's or what-ever. Anything will...
2
by: Robert Oschler | last post by:
One of the recurring bugs I find in my program, is a bug due to a misspelling of a variable name. Is there a code checker out there that can help find these critters? If so, URL's please. ...
4
by: Wanhua Yi | last post by:
Hi all, anybody out there with experience in using EMC's Time Finder Software and DB2 UDB EEE on AIX ? Especially in using BCV for Backup ? Any white papers ?
1
by: Tom | last post by:
If anyone is looking for a cost effective postcode finder try this http://www.postcodeanywhere.co.uk/ it is brilliant and very easy to use
7
by: ezusbo | last post by:
Hi I have implemented this AJAX enabled route finder for getting from A to B on the London Underground network, with built in Google Maps for each station along the way. The AJAX piece allows...
3
by: wbmca | last post by:
I am new to C++ and need help. I'm trying to create a program in which a user is prompted to enter a character and an integer. The program will attempt to find words that begin with the character and...
2
by: WardB | last post by:
Hi, I'm looking for an app that can find duplicate code within a large solution. I found something like Simian (see also...
3
by: Richard | last post by:
Hi, I wonder if you could advice me on the best solution. I will receive from my client a raw data with locations of their stores, which probably would look like this: "B&Q, Industrial Park,...
0
by: brahimbb17 | last post by:
There is no foolproof way to always win when gambling http://crop-finder-for-travian.blogspot.com . That is why itís called gambling, you take risks and reap the benefits when lady lucks sides by...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.