date  selection problem
date  selection problem
date  selection problem
date  selection problem
date  selection problem
date  selection problem date  selection problem date  selection problem date  selection problem date  selection problem date  selection problem date  selection problem date  selection problem
date  selection problem date  selection problem
date  selection problem
Go Back  Xtreme Visual Basic Talk > > > date selection problem


Reply
 
Thread Tools Display Modes
  #1  
Old 09-16-2011, 09:54 AM
locksmith46 locksmith46 is offline
Newcomer
 
Join Date: Jun 2011
Posts: 8
Default date selection problem


Hi all I have a slight problem , using vb 2008 i have written some code that checks the current datetime on the computer. This gives me the answer in the format mon, tues etc. what i now want to do is to use that to call a spreadsheet dependent on the day of the week. here is my code so far

Code:
Dim TIME As DateTime = DateTime.Now
        Dim FORMAT As String = " ddd  "
        TextBox1.Text = TIME.ToString(FORMAT)
that gives me the day in a text box i.e. mon. The next part of the code is the problem

Code:
If TextBox1.Text = "WED" Then
            Call WEDS()
        ElseIf TextBox1.Text = "THUR" Then
            Call THURS()
        ElseIf TextBox1.Text = "Fri" Then
            Call FRIS()
        ElseIf TextBox1.Text = "SAT" Then
            Call SATS()
        ElseIf TextBox1.Text = "SUN" Then
            Call SUNS()
        ElseIf TextBox1.Text = "MON" Then
            Call MONS()
        ElseIf TextBox1.Text = "TUES" Then
            Call TUES()

        End If
Now i have tried the private sub eg SATS() on a separate button and it works perfectly .
so it appears to be that the sub is not been called. I think it is probably a syntax where the datetime answer is not been recognised, in that textbox1.text = "sat" is not the same as datetime = sat . Any help would be much appreciated
Reply With Quote
  #2  
Old 09-16-2011, 09:59 AM
DrPunk's Avatar
DrPunkdate  selection problem DrPunk is offline
Senior Contributor

* Expert *
 
Join Date: Apr 2003
Location: Never where I want to be
Posts: 1,403
Default

Code:
Select Case Now.DayOfWeek
    Case DayOfWeek.Monday
        ' It's monday today
    Case DayOfWeek.Tuesday
        ' It's tuesday today
    Case DayOfWeek.Wednesday
        ' It's wednesday today
    Case DayOfWeek.Thursday
        ' It's thursday today
    Case DayOfWeek.Friday
        ' It's friday today
    Case DayOfWeek.Saturday
        ' It's saturday today
    Case DayOfWeek.Sunday
        ' It's sunday today
End Select
Replaces your date formatting as well.

Edit :- If you still want the day of the week in your textbox then use Textbox1.Text= Now.DayOfWeek.ToString, but there's no point using the textbox in the select case.
__________________
There are no computers in heaven!

Last edited by DrPunk; 09-16-2011 at 10:05 AM.
Reply With Quote
  #3  
Old 09-16-2011, 04:31 PM
Gruff's Avatar
Gruffdate  selection problem Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

Right. Also if all you want is to open workbooks named Mon.xls, Tue.xls, ... then you do not need any selection process.

Code:
Public Class Form1 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click ' Open Excel WorkBook Process.Start("C:\AAA\" & Today.ToString("ddd") & ".xls") End Sub End Class
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #4  
Old 09-17-2011, 02:03 AM
locksmith46 locksmith46 is offline
Newcomer
 
Join Date: Jun 2011
Posts: 8
Default

A big thank you DRPunk for the help . I had thought of a select case but did not realise that now.dayofweek existed (teaching myself as i go ). Your solution has solved the problem for me so ever onward to the next one.

I also see the simplicity in your reply gruff, unfortunately,in this case i dont think it would work as the in formation is not sent as a different spreadsheet per day, but all the days on 1 spreadsheet and I am effectively splitting it into areas via cell location ie mon = A1 - Y25 etc. but i will be keeping a note of your method for further use.
Reply With Quote
  #5  
Old 09-19-2011, 10:56 AM
Gruff's Avatar
Gruffdate  selection problem Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

Well if your column ranges are static then a simple array lookup for the ranges per weekday would do the trick as well.

Dim WeekDayRanges as string {"A1:Y25","A26:Y50","Etc..."}
Dim TodaysRange as string = WeekDayRanges(Now.DayOfWeek)
'Etc...
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
date  selection problem
date  selection problem
date  selection problem date  selection problem
date  selection problem
date  selection problem
date  selection problem date  selection problem date  selection problem date  selection problem date  selection problem date  selection problem date  selection problem
date  selection problem
date  selection problem
 
date  selection problem
date  selection problem
 
-->