Date Manipulation In Visual Basic

I'm trying to find the next day of the powerball, It falls on each wednesday and saturday of each week. I want the out put to be in long date format so if it is a Tuesday the program would give back "Wednesday the blah blah blah" if it were thursday the program would give back "Saturday the blah blah blah" and if it is the day the program would give back "Today, Wednesday the blah blah blah" but it also needs to calculate for the month to roll over into the next. Here are some examples of what I need in and what should come out

2/24/03 then the output should be "Wednesday, Febuary 26th 2003"

2/26/03 then the output should be "Today, Wednesday, Febuary 26th 2003"

and if it is
2/27/03 then the output should be "Saturday March 1st 2003"

the last example has been my trickiest because I know Saturday is 2 days away from Thursday (2/27) but the last day of the month is the 28th

I have been working on code and getting close but no cigar, I'm at work and my code is at home so I'll post what I got so far later but just a side note this is all behind the scenes so the user will input nothing so to get the current date I'd like to use Date$ or Now() or something similar. Basiclly a function to add N amount of days to a date and include calculation for month rollovers. I can find the N amount of days away just can't produce a new correct date.
Thanks,
MoDrop - Ascii(13)
MoDropAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MCummings111400Commented:
Oh, I bet your gonna love this. ;)

Private Sub Command1_Click()
Dim dtCurrent As Date
Dim dtPowerball As Date

    dtCurrent = Text1.Text
    If Weekday(dtCurrent) <= vbWednesday Then
        dtPowerball = dtCurrent + (vbWednesday - Weekday(dtCurrent))
    Else
        dtPowerball = dtCurrent + (vbSaturday - Weekday(dtCurrent))
    End If
   
    Text2.Text = Format(dtPowerball, "long Date")
End Sub
0
MCummings111400Commented:
Oops, didn't read the bottom:

Function NextPowerBall(ByVal dtDate as Date) as Date
Dim dtPowerball As Date

   If Weekday(dtCurrent) <= vbWednesday Then
       dtPowerball = dtDate + (vbWednesday - Weekday(dtCurrent))
   Else
       dtPowerball = dtDate + (vbSaturday - Weekday(dtCurrent))
   End If

   NextPowerBall = dtPowerBall
 End Function
0
MoDropAuthor Commented:
When I do This All I Get Returned Is The Current Date Am I Using Your Function Wrong

Private Sub Form_Load()
   msgbox NextPowerBall (Now())
   Unload Me
End Sub

Public Function NextPowerBall(ByVal dtDate as Date) as Date
Dim dtPowerball As Date

  If Weekday(dtCurrent) <= vbWednesday Then
      dtPowerball = dtDate + (vbWednesday - Weekday(dtCurrent))
  Else
      dtPowerball = dtDate + (vbSaturday - Weekday(dtCurrent))
  End If

  NextPowerBall = dtPowerBall
End Function
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

JohnMcCannCommented:
Try


Private Sub Form_Load()
  MsgBox NextPowerBall(Date)
  Unload Me
End Sub

Public Function NextPowerBall(ByVal dtDate As Date) As Date
Dim tmpDate As Date

   tmpDate = dtDate
   Do
      If Weekday(dtDate, vbWednesday) = 0 Or Weekday(dtDate, vbSaturday) = 0 Then
         NextPowerBall = dtDate
         Exit Do
      Else
         tmpDate = DateAdd("d", 1, tmpDate)
      End If
   Loop
End Function
0
JohnMcCannCommented:
Soory never noyticed the part that says you want the return to be of long date format

Replace

NextPowerBall = dtDate
       
with

NextPowerBall = Format(dtDate, "dddd, dd MMMM yyyy")
       
0
JohnMcCannCommented:
I have re read the question and realize you need to return a string in order to get "Today"

So the code

Private Sub Form_Load()
  MsgBox NextPowerBall(Date)
  Unload Me
End Sub

Public Function NextPowerBall(ByVal dtDate As Date) As String
Dim tmpDate As Date

   tmpDate = dtDate
   Do
      If Weekday(dtDate, vbWednesday) = 0 Or Weekday(dtDate, vbSaturday) = 0 Then
         If tmpDate = dtDate Then
            NextPowerBall = "Today " & Format(dtDate, "dddd, dd MMMM yyyy")
         Else
            NextPowerBall = Format(dtDate, "dddd, dd MMMM yyyy")
         End If
         Exit Do
      Else
         tmpDate = DateAdd("d", 1, tmpDate)
      End If
   Loop
End Function
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MoDropAuthor Commented:
Well I Still Found Problems In The Code, Although Now I See All The Wonderful Date Functions After Tinkering With The Code Given To Me And Looking In The MSDN Library I Have Taken JohnMcCann's Function And Fixed It, John I'm Gonna Give You The Points, Yea!!! So Here's The Code Below. Thanks To Everyone Who Helped. If Your're Interested About Why I Needed To Know The Next Powerball Dates Look Below The Code For A Description Of The Program I'm Making, Might Help Your Luck...

Private Sub Form_Load()
    MsgBox NextPowerBall(Date)
    Unload Me
End Sub

Public Function NextPowerBall(ByVal dtDate As Date) As String
    Dim tmpDate As Date
   
    tmpDate = dtDate
    Do
        If Weekday(tmpDate) = 4 Or Weekday(tmpDate) = 7 Then
            If tmpDate = dtDate Then
                NextPowerBall = "Today " & Format(dtDate, "dddd, MMMM dd, yyyy")
            Else
                NextPowerBall = Format(tmpDate, "dddd, MMMM dd, yyyy")
            End If
            Exit Do
        Else
            tmpDate = DateAdd("d", 1, tmpDate)
        End If
    Loop
End Function

I'm Making A Program Which Downloads The Text Files Contating All The Powerball Numbers Ever Picked. After Editing The Text Into Array's I Then Display The 5 Most Picked Numbers (5 Modes) The 2 Averages (The Mean And The Natual Log Mean) And The Median. The Date Was Just To Look Nice For The User It Displays The Next Day It's On And The Estimated Jackpot. It Also Can Generate Random Lotto Balls Or Generate Then With-in A Close Range Of The Modes. Anywho It Has More Options But Is Still In Process. If You Are Interested In Source Code When I'm Done Just Email Me, crolfson@uwm.ed, If You Win Using My Program All I'm Asking For Is A Litte Cash For College, And Maybe A Sweet Car, And Maybe...... Well Lets Just Hope The Program Works :)
0
MoDropAuthor Commented:
I Needed To Fix It Up But The Functions Were Just What I Needed, I Don't Know If You Tested It But The Last Code I Posted Works. Thanks A Mill And If Your're Interested In Why I Needed It Look At My Last Post,
Thanks Until Real Time,
MoDrop Ascii(13)
0
JohnMcCannCommented:
NEVER NEVER NEVER USE Weekday(tmpDate) without giving a default say as it will use the systems.  i.e. my system may be set to firstday = Monday and yours SunDay the code wold then produce different results.  That is worth noting for all functions never assume default behavior always explictly declare it.

0
MoDropAuthor Commented:
Ahh.. Much Praise. I'm Still Rough With These Date Functions And Didn't Realize The Effect That May Have Until You Brought It Up. Could You Please Check This New Code To See If It Is Good On All Systems No Matter What The System's firstday is equal to. Otherwise I Was Thinking About Changing The First Day To What I Need And Then Back To The Original After The Functions Works. Thanks A Mill,
MoDrop - Ascii(13)

Private Sub Form_Load()
    MsgBox NextPowerBall(Date)
    Unload Me
End Sub

Public Function NextPowerBall(ByVal dtDate As Date) As String
    Dim tmpDate As Date

    tmpDate = dtDate
    Do
        If Weekday(tmpDate, vbWednesday) = 1 Or Weekday(tmpDate, vbSaturday) = 1 Then
            If tmpDate = dtDate Then
                NextPowerBall = "Today " & Format(dtDate, "dddd, MMMM dd, yyyy")
            Else
                NextPowerBall = Format(tmpDate, "dddd, MMMM dd, yyyy")
            End If
            Exit Do
        Else
            tmpDate = DateAdd("d", 1, tmpDate)
        End If
        DoEvents
    Loop
End Function
0
MCummings111400Commented:
MoDrop,
   You were getting back the current day because 2/26/2003 is a wednesday, hence a PowerBall day, If you had tried something other than Now() you would have seen different results.

0
MCummings111400Commented:
MoDrop,
   You were getting back the current day because 2/26/2003 is a wednesday, hence a PowerBall day, If you had tried something other than Now() you would have seen different results.

0
JohnMcCannCommented:
Sorry I made a mistake

The weekday function always assumes vbSunday as day 1 and for some reason though it returned 0.

But still it is always worth specifiying the behavior you expect.
0
MoDropAuthor Commented:
To MCummings,
 About Your Comment:

MoDrop,
  You were getting back the current day because 2/26/2003 is a wednesday, hence a PowerBall day, If you had tried something other than Now() you would have seen different results.

I Tried Changeing My Date On The System. I Still Kept Now() But I Would Change My Day To 2/27/03 And Other Random Dates To Check For It Rolling Over Into The Next Month. The Last Function I Posted Works For All Dates. Thanks Everyone,
MoDrop
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Game Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.