gentage funktion / sub periodisk
Jeg har en windows form lavet i vs.net 2003, der skal starte på et klik - derefter skal den sub, der startes onclick gentages hvert minut.Jeg har prøvet med timere, men jeg kan ikke få skidtet til at fungere. Hvad gør jeg ?
Kode:
Imports System.Threading
Imports MySql.Data.MySqlClient
'Imports CustomUIControls
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
taskbarNotifier1 = New TaskBarNotifier
taskbarNotifier1.SetBackgroundBitmap(New Bitmap(MyClass.GetType(), "skin.bmp"), Color.FromArgb(255, 0, 255))
taskbarNotifier1.SetCloseBitmap(New Bitmap(MyClass.GetType(), "close.bmp"), Color.FromArgb(255, 0, 255), New Point(195, 8))
taskbarNotifier1.TitleRectangle = New Rectangle(40, 9, 170, 25)
taskbarNotifier1.TextRectangle = New Rectangle(8, 50, 210, 90)
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 Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(80, 48)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.Button1)
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.MaximizeBox = False
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private WithEvents taskbarNotifier1 As TaskBarNotifier
Public Sub tbn()
With taskbarNotifier1
.CloseButtonClickEnabled = 1 'checkBoxCloseClickable.Checked
.TitleClickEnabled = 0 'checkBoxTitleClickable.Checked
.TextClickEnabled = 0 'checkBoxContentClickable.Checked
.DrawTextFocusRect = 1 'checkBoxSelectionRectangle.Checked
.KeepVisibleOnMouseOver = 1 'checkBoxKeepVisibleOnMouseOver.Checked
.ReShowOnMouseOver = 1 'checkBoxReShowOnMouseOver.Checked
.Show("Test", tekst3(), Integer.Parse(200), Integer.Parse(9000), Integer.Parse(3000))
End With
End Sub
Function tekst3()
Dim ligaen As String
If Now.Hour < 3 Then
Dim dd As DateTime = Now
dd = DateAdd(DateInterval.Hour, -3, dd)
tekst3 = SelectRows("select * from pppppp where year(begynd) = " & Year(dd) & " and MONTH(begynd)=" & Month(dd) & " and DAY(begynd)=" & dd.Day & " and HOUR(begynd)>=" & Hour(dd) & " and year(begynd) = " & Year(Now) & " OR MONTH(begynd)=" & Month(Now) & " and DAY(begynd)=" & dd.Day & ligaen, "resultater")
Else
tekst3 = SelectRows("select * from ppppp where year(begynd) = " & Year(Now) & " and MONTH(begynd)=" & Month(Now) & " and DAY(begynd)=" & Now.Day & " and HOUR(begynd)>=" & Hour(Now) - 3 & "", "resultater")
End If
End Function
Function SelectRows(ByVal mySelectQuery, ByVal myTableName)
Dim myConnectionString As String = "DATABASE=sport;SERVER=xxx.xxx.xxx.xxx;User Id=xxx;Password=xxx;Allow Zero Datetime=True;"
Dim streng As String
Dim myConn As New MySqlConnection(myConnectionString)
Dim myDataAdapter As New MySqlDataAdapter
myDataAdapter.SelectCommand = New MySqlCommand(mySelectQuery, myConn)
Dim cb As MySqlCommandBuilder = New MySqlCommandBuilder(myDataAdapter)
myConn.Open()
Dim MyDataReader As MySqlDataReader
Dim MySqlCommand As MySqlCommand = New MySqlCommand(mySelectQuery, myConn)
MyDataReader = MySqlCommand.ExecuteReader(CommandBehavior.CloseConnection)
While MyDataReader.Read()
streng = streng & MyDataReader.Item("xxx") & " | " & MyDataReader.Item("yyy") & " | " & MyDataReader.Item("zzz") & " - " & MyDataReader.Item("æææ") & vbCrLf
Console.WriteLine(streng)
End While
myConn.Close()
SelectRows = streng
End Function
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
tbn()
End Sub
End Class