Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dayofweek 4

Status
Not open for further replies.

rozzay

Programmer
Jan 3, 2002
142
US
Hi I am doing program where it reports particular calculations. The calculation depends on the current date. The report shows the data for days Mon-Fri. For instance if the date was on a monday the calculation would be new then on the next day it would add monday's calculation to tuesday and so on until Friday then start over on Monday. My problem is I don't know how to do this in VB. I have looked at the help for firstdayweek but don't quite understand. Can anyone provide me a site where I can look at examples or provide an example so I can get some kind of start? Thanks in advance.
 
You could try the Weekday function


Select Case Weekday(<date to check>)
Case vbSunday
MsgBox &quot;its sunday&quot;
Case vbMonday
MsgBox &quot;its monday&quot;
Case vbTuesday
MsgBox &quot;its tuesday&quot;
Case vbWednesday
MsgBox &quot;its wednesday&quot;
Case vbThursday
MsgBox &quot;its thursday&quot;
Case vbFriday
MsgBox &quot;its friday&quot;
Case vbSaturday
MsgBox &quot;its saturday&quot;
End Select
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
okay i went ahead and set this up using the select case example above and try to do some calcuations with it by retrieving today's record and yesterday's record but i receive a run-time error saying the overflow of data. What did I do wrong and what can i do in order to fix this??
thanks.
============================================================
Option Explicit
Dim bValidTime As Boolean
Dim iDte As Integer
Dim iDate As Integer

Private Sub cmdNext_Click()
Dim vbResult As VbMsgBoxResult
Dim strSQL As String

If ValidData Then
strSQL = &quot;&quot;
strSQL = strSQL & &quot; SELECT * &quot;
strSQL = strSQL & &quot; FROM edi_log&quot;

rsLogAccess.Open strSQL, oConnAccess, adOpenDynamic, adLockOptimistic
If Not rsLogAccess.BOF Then
rsLogAccess.MoveFirst
End If
GetWEBEDIPOs
GetWEBEDIINVs
GetWeb_POs
GetWEB_Ven

rsLogAccess.Find &quot;[time] = &quot; & Date
If rsLogAccess.EOF Then
rsLogAccess.MoveLast
rsLogAccess.AddNew
rsLogAccess.Fields(&quot;time&quot;) = Date
LoadData
Else
rsLogAccess.Update
LoadData
End If
Unload Me
frmLogResult.Show
End If

End Sub

Private Function LoadData()
strEDPO = txtEDPO.Text
rsLogAccess.Fields(&quot;edpo&quot;) = Trim(strEDPO)

strLoadTime = txtLoadTime.Text
rsLogAccess.Fields(&quot;load&quot;) = Trim(strLoadTime)

strXMITLoadTime = txtXMITLoadTime.Text
rsLogAccess.Fields(&quot;ordernet&quot;) = Trim(strXMITLoadTime)

strIINGLoadTime = txtIingLoadTime.Text
rsLogAccess.Fields(&quot;iingout&quot;) = Trim(strIINGLoadTime)

If txtComment.Text <> &quot;&quot; Then
strComment = txtComment.Text
rsLogAccess.Fields(&quot;comment&quot;) = Trim(strComment)
End If

rsLogAccess.Fields(&quot;po&quot;) = Trim(strPOs)
rsLogAccess.Fields(&quot;inv&quot;) = Trim(strINVs)
rsLogAccess.Fields(&quot;WebP_POs&quot;) = Trim(strProPO)
rsLogAccess.Fields(&quot;WebP_Ven&quot;) = Trim(strProVen)
rsLogAccess.Fields(&quot;WebS_POs&quot;) = Trim(strTestPO)
rsLogAccess.Fields(&quot;WebS_Ven&quot;) = Trim(strTestVen)
CalculateMF
CalculateWebPO
rsLogAccess.Update
rsLogAccess.Close

End Function

Private Function CalculateMF()
iMf = 0
ValidDay

If Not rsLogAccess.BOF Then
rsLogAccess.MoveFirst
End If
If iDte = 0 Then
strMF = strEDPO
iMf = strEDPO
ElseIf iDte = 1 Then
rsLogAccess.Find &quot;[time] = &quot; & Date - 1
strMF = rsLogAccess(&quot;mf&quot;).Value + iMf
ElseIf iDte = 2 Then
ElseIf iDte = 3 Then
ElseIf iDte = 4 Then
End If

rsLogAccess.Fields(&quot;mf&quot;) = Trim(strMF)

End Function

Private Function ValidDay()
Select Case Weekday(Date)
Case vbSunday
iDte = -1
MsgBox &quot;Sunday no POs run!&quot;
Case vbMonday
iDte = 0
iDate = Date
Case vbTuesday
iDte = 1
iDate = Date - 1
Case vbWednesday
iDte = 2
iDate = Date - 2
Case vbThursday
iDte = 3
iDate = Date - 3
Case vbFriday
iDte = 4
iDate = Date - 4
Case vbSaturday
iDte = 5
MsgBox &quot;Saturday, no POs run!&quot;
End Select

End Function

 
I just coded the GetDayOfWeek function below...I haven't tested it completely, but I believe it will work. Basically, it works by knowing that April, 28, 2002 is a Sunday and then comparing the number of days from that date to the date that you are trying to query.

Private Sub Form_Load()
'Test on Friday Dec 12, 1997
MsgBox GetDayOfWeek(&quot;12 / 12 / 1997&quot;)
End Sub

Private Function GetDayOfWeek(theDate As Date) As String
Dim x As Long
x = DateDiff(&quot;d&quot;, &quot;4 / 28 / 2002&quot;, theDate) Mod 7
Select Case x
Case 0
GetDayOfWeek = &quot;Sunday&quot;
Case 1
GetDayOfWeek = &quot;Monday&quot;
Case 2
GetDayOfWeek = &quot;Tuesday&quot;
Case 3
GetDayOfWeek = &quot;Wednesday&quot;
Case 4
GetDayOfWeek = &quot;Thursday&quot;
Case 5
GetDayOfWeek = &quot;Friday&quot;
Case 6
GetDayOfWeek = &quot;Saturday&quot;
Case 0
GetDayOfWeek = &quot;Sunday&quot;
Case -1
GetDayOfWeek = &quot;Saturday&quot;
Case -2
GetDayOfWeek = &quot;Friday&quot;
Case -3
GetDayOfWeek = &quot;Thursday&quot;
Case -4
GetDayOfWeek = &quot;Wednesday&quot;
Case -5
GetDayOfWeek = &quot;Tuesday&quot;
Case -6
GetDayOfWeek = &quot;Monday&quot;
End Select
End Function
 
iDate = Date - 1

will not work
iDate is an integer and Date is a date.

what are you using iDate for? it is declared as an integer, but Date is a date. If you want iDate to be a date, then declare it as a date and use the DateDiff function to make the assignment.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
Also rossay, the WeekDay function actually return an integer with values shown below:

vbSunday 1
vbMonday 2
vbTuesday 3
vbWednesday 4
vbThursday 5
vbFriday 6
vbSaturday 7

You could replace your call to ValidDay with the statement

iDte = WeekDay(Date) - 2

Then you can use the following case statment

Select Case iDte
case 0 ' Monday
strMF = strEDPO
iMf = strEDPO
case 1, 2, e, 4 ' Tuesday thru Friday
rsLogAccess.Find &quot;[time] = &quot; & Date - iDte
strMF = rsLogAccess(&quot;mf&quot;).Value + iMf
case else
MsgBox &quot;Its a Weekend&quot;
end select
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
The easiest way to get day of week is format(now,&quot;w&quot;) Peter Meachem
peter@accuflight.com
 
Hi,
You might find this usful.
The first part (down to the double line) is
the contents of the .frm file for this procedure.

HTH
Rowland

Version 5#
Begin VB.Form Form1
Caption = &quot;Form1&quot;
ClientHeight = 3192
ClientLeft = 60
ClientTop = 348
ClientWidth = 4680
LinkTopic = &quot;Form1&quot;
ScaleHeight = 3192
ScaleWidth = 4680
StartUpPosition = 2 'CenterScreen
Begin VB.CommandButton cmdDone
Caption = &quot;Quit&quot;
Height = 396
Left = 384
TabIndex = 4
Top = 2016
Width = 972
End
Begin VB.CommandButton cmdReset
Caption = &quot;Reset&quot;
Height = 396
Left = 384
TabIndex = 3
Top = 1440
Width = 972
End
Begin VB.TextBox Text2
Height = 396
Left = 1632
TabIndex = 2
Top = 288
Width = 972
End
Begin VB.CommandButton cmdAddResults
Caption = &quot;Enter Day Results&quot;
Height = 396
Left = 384
TabIndex = 1
Top = 864
Width = 972
End
Begin VB.TextBox Text1
Height = 396
Left = 384
TabIndex = 0
Top = 288
Width = 972
End
End
Attribute VB_Name = &quot;Form1&quot;
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

==========================================

Option Explicit
Dim DayNumber
Dim arDaily(1 To 5)

Private Sub cmdAddResults_Click()
Dim i
'-------------------------------------------------
'For test purposes only, hard code numbers
'into days prior to today, then enter
'new data (for today) into the
'first text box. This block of code whould
'not be used in the final program.
arDaily(1) = 12 'Monday results
arDaily(2) = 3 'Tuesday results
arDaily(3) = 0 'Wed
arDaily(4) = 0 'Thu
arDaily(5) = 0 'Fri
'--------------------------------------------------
'This will set the first day of week
'to Monday and return a value (1 to 7)
'for each Subsequent day. You will want
'to use 1 to 5 to set your work week to
'Monday thru Friday.
DayNumber = WeekDay(Now, vbMonday)

'You will enter the days activity in
'Text1. This code will place that data
'into the array position representing that day.
arDaily(DayNumber) = Text1.Text

'This will display the sum of
'all days activity to this point.
For i = 1 To 5
Text2.Text = Val(Text2.Text) + Val(arDaily(i))
Next i
End Sub

Private Sub cmdDone_Click()
End
End Sub

Private Sub cmdReset_Click()
Dim Msg, Style, Response

Msg = &quot;Are you sure you want to clear the array ?&quot;
Style = vbYesNo + vbCritical + vbDefaultButton2
Response = MsgBox(Msg, Style)
If Response = vbNo Then Exit Sub

Erase arDaily() 'Clear the array and
Text1.Text = &quot;&quot; 'initialize the text boxes
Text2.Text = 0 'to prepare for a new week.
Text1.SetFocus
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top