Can anyone help? I'm writing an application that keeps track of pupils in my small music school. Everything's working apart from one small thing that I can't seem to solve.
Pupils pay for four lessons at a time so it was easy to take the start date and add 28 days to get the renewal date. Also, the renewal date has a backcolor green as long as the renewal date is ahead of the current system date. What I'm trying to do is get the backcolor to change to red if the renewal date is equal to, or greater than the system date, to highlight that the renewal is due.
The textboxes are created as controls in code as follows and I've been trying to change the backcolor of the textbox named "RenewalDate". Clearly I'm doing something wrong as everything I've tried either makes no change, or makes the control disappear altogether.
Dim TBS(200)
Dim j As Integer
Dim MyReadWrite As New ReadWrite
Dim btnRenew(200) As Button
Dim r As Integer = 100
Private Sub StudentList_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MyReadWrite.read()
TextBox1.Text = Format(Today, "dd/MM/yyyy")
TextBox2.Text = ReadWrite.Renewal(ReadWrite.a - 1)
TextBox3.Text = TextBox1.Text
TextBox4.Text = TextBox2.Text
For n = 1 To ReadWrite.SintCount
j = n
TBS
= New TextBox
TBS
.Name = "RegNum" & n.ToString
TBS
.Text = ReadWrite.RegNo
TBS
.Size = New Size(55, 20)
TBS
.Location = New Point(34, r)
TBS
.BorderStyle = BorderStyle.Fixed3D
Me.Controls.Add(TBS
)
TBS
= New TextBox
TBS
.Name = "Name" & n.ToString
TBS
.Text = ReadWrite.ForeName
& " " & ReadWrite.SurName
TBS
.Size = New Size(155, 20)
TBS
.Location = New Point(95, r)
TBS
.BorderStyle = BorderStyle.Fixed3D
Me.Controls.Add(TBS
)
TBS
= New TextBox
TBS
.Name = "Age" & n.ToString
TBS
.Text = ReadWrite.Age
TBS
.Size = New Size(45, 20)
TBS
.Location = New Point(257, r)
TBS
.BorderStyle = BorderStyle.Fixed3D
Me.Controls.Add(TBS
)
TBS
= New TextBox
TBS
.Name = "Subject" & n.ToString
TBS
.Text = ReadWrite.Subject
TBS
.Size = New Size(95, 20)
TBS
.Location = New Point(308, r)
TBS
.BorderStyle = BorderStyle.Fixed3D
Me.Controls.Add(TBS
)
TBS
= New TextBox
TBS
.Name = "Room" & n.ToString
TBS
.Text = ReadWrite.Room
TBS
.Size = New Size(45, 20)
TBS
.Location = New Point(409, r)
TBS
.BorderStyle = BorderStyle.Fixed3D
Me.Controls.Add(TBS
)
TBS
= New TextBox
TBS
.Name = "Day" & n.ToString
TBS
.Text = ReadWrite.Day
TBS
.Size = New Size(100, 20)
TBS
.Location = New Point(460, r)
TBS
.BorderStyle = BorderStyle.Fixed3D
Me.Controls.Add(TBS
)
TBS
= New TextBox
TBS
.Name = "Time" & n.ToString
TBS
.Text = ReadWrite.Time
TBS
.Size = New Size(60, 20)
TBS
.Location = New Point(566, r)
TBS
.BorderStyle = BorderStyle.Fixed3D
Me.Controls.Add(TBS
)
TBS
= New TextBox
TBS
.Name = "Paid" & n.ToString
TBS
.Text = ReadWrite.Paid
.ToString("C")
TBS
.Size = New Size(80, 20)
TBS
.Location = New Point(632, r)
TBS
.BorderStyle = BorderStyle.Fixed3D
Me.Controls.Add(TBS
)
TBS
= New TextBox
TBS
.Name = "RenewalDate" & n.ToString
TBS
.Text = ReadWrite.Renewal
.ToShortDateString
TBS
.Size = New Size(80, 20)
TBS
.Location = New Point(720, r)
TBS
.BorderStyle = BorderStyle.Fixed3D
TBS
.BackColor = Color.Green
TBS
.ForeColor = Color.White
If TextBox3.Text = TextBox4.Text Then
For Each ctrl As Control In Me.Controls
If TypeOf ctrl Is TextBox And
ctrl.Name = "RenewalDate" & j Then
TBS(j).BackColor = New Color = Color.Red
End If
Next
End If
Me.Controls.Add(TBS
)
btnRenew
= New Button
btnRenew
.Name = "Renewed" & n.ToString("C")
btnRenew
.Text = "Renew"
btnRenew
.Size = New Size(60, 20)
btnRenew
.Location = New Point(823, r)
btnRenew
.Parent = Me
AddHandler btnRenew
.Click, AddressOf btn_Click
Me.Controls.Add(btnRenew
)
r += 25
Next
r = 100
End Sub
Pupils pay for four lessons at a time so it was easy to take the start date and add 28 days to get the renewal date. Also, the renewal date has a backcolor green as long as the renewal date is ahead of the current system date. What I'm trying to do is get the backcolor to change to red if the renewal date is equal to, or greater than the system date, to highlight that the renewal is due.
The textboxes are created as controls in code as follows and I've been trying to change the backcolor of the textbox named "RenewalDate". Clearly I'm doing something wrong as everything I've tried either makes no change, or makes the control disappear altogether.
Dim TBS(200)
Dim j As Integer
Dim MyReadWrite As New ReadWrite
Dim btnRenew(200) As Button
Dim r As Integer = 100
Private Sub StudentList_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MyReadWrite.read()
TextBox1.Text = Format(Today, "dd/MM/yyyy")
TextBox2.Text = ReadWrite.Renewal(ReadWrite.a - 1)
TextBox3.Text = TextBox1.Text
TextBox4.Text = TextBox2.Text
For n = 1 To ReadWrite.SintCount
j = n
TBS
TBS
TBS
TBS
TBS
TBS
Me.Controls.Add(TBS
TBS
TBS
TBS
TBS
TBS
TBS
Me.Controls.Add(TBS
TBS
TBS
TBS
TBS
TBS
TBS
Me.Controls.Add(TBS
TBS
TBS
TBS
TBS
TBS
TBS
Me.Controls.Add(TBS
TBS
TBS
TBS
TBS
TBS
TBS
Me.Controls.Add(TBS
TBS
TBS
TBS
TBS
TBS
TBS
Me.Controls.Add(TBS
TBS
TBS
TBS
TBS
TBS
TBS
Me.Controls.Add(TBS
TBS
TBS
TBS
TBS
TBS
TBS
Me.Controls.Add(TBS
TBS
TBS
TBS
TBS
TBS
TBS
TBS
TBS
If TextBox3.Text = TextBox4.Text Then
For Each ctrl As Control In Me.Controls
If TypeOf ctrl Is TextBox And
ctrl.Name = "RenewalDate" & j Then
TBS(j).BackColor = New Color = Color.Red
End If
Next
End If
Me.Controls.Add(TBS
btnRenew
btnRenew
btnRenew
btnRenew
btnRenew
btnRenew
AddHandler btnRenew
Me.Controls.Add(btnRenew
r += 25
Next
r = 100
End Sub