Here's the code in case it will make it easier...
Option Explicit On
Imports Microsoft.Win32
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents lblTimeLeft As System.Windows.Forms.Label
Friend WithEvents Timer1 As System.Windows.Forms.Timer
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.components = New System.ComponentModel.Container
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.lblTimeLeft = New System.Windows.Forms.Label
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.lblTimeLeft)
Me.GroupBox1.Font = New System.Drawing.Font("Arial", 9.75!,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0,
Byte))
Me.GroupBox1.Location = New System.Drawing.Point(16, 14)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(200, 75)
Me.GroupBox1.TabIndex = 0
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "Minutes Left Today"
'
'lblTimeLeft
'
Me.lblTimeLeft.BorderStyle =
System.Windows.Forms.BorderStyle.Fixed3D
Me.lblTimeLeft.ForeColor = System.Drawing.Color.Red
Me.lblTimeLeft.Location = New System.Drawing.Point(50, 26)
Me.lblTimeLeft.Name = "lblTimeLeft"
Me.lblTimeLeft.TabIndex = 0
Me.lblTimeLeft.Text = "0"
Me.lblTimeLeft.TextAlign =
System.Drawing.ContentAlignment.MiddleCenter
'
'Timer1
'
Me.Timer1.Interval = 60000
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(232, 102)
Me.Controls.Add(Me.GroupBox1)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "Form1"
Me.ShowInTaskbar = False
Me.Text = "User Timer"
Me.GroupBox1.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
' Define API functions
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As
Long, ByVal dwReserved As Long) As Long
' Define Global variables
Public iTimeLeft As Integer
Public DoW As String
' Define Global constants
Private Const ShutdownFlag As Long = &H14
Private Const ShutdownMsg As String = "No more time left for today.
Come back tomorrow..."
Private Const ShutdownTitle As String = "BYE"
Private Const DefSun As Integer = 120
Private Const DefMon As Integer = 30
Private Const DefTue As Integer = 30
Private Const DefWed As Integer = 30
Private Const DefThu As Integer = 30
Private Const DefFri As Integer = 120
Private Const DefSat As Integer = 120
Private Sub GetRegValues()
Dim hKey As RegistryKey
' Open the registry
hKey = Registry.CurrentUser.OpenSubKey("Software\UserTimer\")
' Read time left for today from registry
iTimeLeft = hKey.GetValue(DoW, "NONE")
' Close the registry
hKey.Close()
End Sub
Public Sub SaveValues()
Dim hKey As RegistryKey
' Open the registry
hKey = Registry.CurrentUser.OpenSubKey("Software\UserTimer\", True)
' Write updated value
hKey.SetValue(DoW, iTimeLeft)
' Close the registry
hKey.Close()
End Sub
Private Sub ResetYesterday()
Dim Yesterday As String
Dim hKey As RegistryKey
Dim iDef As Integer
Select Case Today.DayOfWeek
Case DayOfWeek.Sunday
Yesterday = "Saturday"
iDef = DefSat
Case DayOfWeek.Monday
Yesterday = "Sunday"
iDef = DefSun
Case DayOfWeek.Tuesday
Yesterday = "Monday"
iDef = DefMon
Case DayOfWeek.Wednesday
Yesterday = "Tuesday"
iDef = DefTue
Case DayOfWeek.Thursday
Yesterday = "Wednesday"
iDef = DefWed
Case DayOfWeek.Friday
Yesterday = "Thursday"
iDef = DefThu
Case DayOfWeek.Saturday
Yesterday = "Friday"
iDef = DefFri
End Select
' Open the registry
hKey = Registry.CurrentUser.OpenSubKey("Software\UserTimer\", True)
' Write updated value
hKey.SetValue(Yesterday, iDef)
' Close the registry
hKey.Close()
End Sub
Private Sub UserLogout()
MsgBox(ShutdownMsg, MsgBoxStyle.Information, ShutdownTitle)
'ExitWindowsEx(ShutdownFlag, 0)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' Get day of week string
DoW = Today.DayOfWeek.ToString
'Load values from registry
GetRegValues()
If (iTimeLeft = 0) Then
UserLogout()
End If
lblTimeLeft.Text = iTimeLeft
ResetYesterday()
End Sub
Private Sub Form1_Closed(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Closed
SaveValues()
UserLogout()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
' Update time left
iTimeLeft = iTimeLeft - 1
' Update display
lblTimeLeft.Text = iTimeLeft
' Save information to registry.
SaveValues()
If (iTimeLeft = 0) Then
UserLogout()
End If
End Sub
End Class
--
+-------------------------------------------------
| "Time is the fire in which we burn..."
|
|AIM: PR Borg
|ICQ: 254445033
+-------------------------------------------------