How to stop button events from firing - vb.net

I have a problem with my btnNext.
I have btnNext and I want to limit it at its 9thclick.
After 9 clicks the button should become disabled. How do I do it?
Private Sub Button3_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnnext.Click
If btnnext.Text = "Submit" Then
calculate()
btnnext.Text = "Next>"
ElseIf btnnext.Text = "Next>" Then
CurrentRow += 5
cat += 5
showdata()
updatelbl()
clear_radio()
' calculate_case(1)
' calculate_case(2)
' calculate_case(3)
' calculate_case(4)
btnnext.Text = "Submit"
If CurrentRow & cat = ds.Tables("evaluation").Rows.Count >= 20 Then
MsgBox("Last Questions is Reached!!!")
End If
If btnnext.Text = "Management of Learning" Then
btnnext.Text = "Finish"
If btnnext.Text = "Finish" Then
CurrentRow = 35
cat = 35
MsgBox("Comment")
End If
End If
End If
End Sub

Private btnCount As Integer
Private Sub Button3_Click(...)...
btnCount += 1
If btnCount = 9 Then Button3.Enabled = False
'remainder of code here...

Like this
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Static ctClicks As Integer = 0
ctClicks += 1
If ctClicks = 9 Then Button1.Enabled = False
'other code
'
End Sub

Related

How can I use collision detection with spawned arrays

Since I have been trying to make a space invaders style game I have been having trouble with collision detection with spawned objects in arrays (and having a bit of trouble with the bullets, they keep stopping and having another generate). I am new at coding and would like some help with these issues, or at least some links to some forums that had the same thread question.
here is my code:
Public Class Form1
'global variables
Dim intAmountOfEnemys As Short = 9
Dim intRowsOfEnemys As Integer = 0 '**
Dim intAmountOfBullets As Integer = 0
Dim picEnemysWave1(intAmountOfEnemys) As PictureBox
Dim lblBullets As New Label
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Welcome_Screen.Hide()
Call EnemyWaves(picEnemysWave1)
End Sub
Sub PlayerMovement(ByVal sender As Object, ByVal e As KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.A Then
If picShip.Right <= 0 Then
picShip.Left = 1567
Else
picShip.Left -= 10
End If
ElseIf e.KeyCode = Keys.D Then
If picShip.Left >= 1567 Then
picShip.Left = -15
Else
picShip.Left += 10
End If
ElseIf e.KeyCode = Keys.Space Then
Do
BulletGeneration(lblBullets)
Loop Until Keys.Space
lblBullets.Left = (picShip.Left + 7)
End If
End Sub
#Region "Enemy waves, Movement, and Properties"
Sub EnemyWaves(ByRef picEnemysWave1() As PictureBox)
'Enemy Generator
Const srtENEMYSPACING_Y As Short = 155
For intCounterForEnemys As Integer = 0 To intAmountOfEnemys
Dim intEnemySpacing As Integer = srtENEMYSPACING_Y * intCounterForEnemys
picEnemysWave1(intCounterForEnemys) = New PictureBox
picEnemysWave1(intCounterForEnemys).Location = New Point(42 + intEnemySpacing, 1)
picEnemysWave1(intCounterForEnemys).Image = My.Resources.enemy
picEnemysWave1(intCounterForEnemys).Width = 124
picEnemysWave1(intCounterForEnemys).Height = 84
picEnemysWave1(intCounterForEnemys).Show()
Me.Controls.Add(picEnemysWave1(intCounterForEnemys))
Next intCounterForEnemys
End Sub``
Private Sub TmrAlien1_Tick(sender As Object, e As EventArgs) Handles TmrAlien1.Tick
For intRandom As Integer = 0 To 9
picEnemysWave1(intRandom).Top += 3
Dim intRandomNum As Integer = Rnd()
If intRandomNum > 0.66 Then
picEnemysWave1(intRandom).Left += 2 'goes left randomly
ElseIf intRandomNum < 0.33 Then
picEnemysWave1(intRandom).Left -= 2 'goes right randomly
End If
If picEnemysWave1(intRandom).Top <= 0 Then
TmrAlien1.Start()
End If
If picEnemysWave1(intRandom).Top >= 952 Then
TmrAlien1.Stop()
End If
Next intRandom
End Sub
#End Region
#Region "Bullet Generation, Movement, and Properties"
Sub BulletGeneration(ByRef lblBullets As Object)
'Generation of Bullets
For intBulletCounter As Integer = 0 To intAmountOfBullets
lblBullets = New Label
lblBullets.location = New Point(760, 785)
lblBullets.image = My.Resources.blast2
lblBullets.width = 32
lblBullets.height = 64
lblBullets.show()
Me.Controls.Add(lblBullets)
Next intBulletCounter
End Sub
Private Sub tmrBullets_Tick(sender As Object, e As EventArgs) Handles tmrBullets.Tick
lblBullets.Top -= 20
End Sub
#End Region
#Region "Collision Detection"
Sub BulletCollision(ByRef lblBullets As Label, ByRef intAmontOfEnemys As Integer)
For Each picEnemy As PictureBox In picEnemysWave1
If lblBullets.Bounds.IntersectsWith(picEnemy.Bounds) Then
picEnemy.Location = New Point(3900, 8700)
Exit For
End If
Next
'what Im trying
End Sub
#End Region

Need assistance with writing to a CSV file and saving entries

I am creating a student test score application which shows student averages, class averages (I haven't done this part yet) and can search for a particular student which shows up in the text boxes.
Can someone please tell me how to write the test scores and name of student entered into the text boxes to an Excel CSV file?
Also the save button keeps clearing all the enteries to the CSV file when I click on it. If anyone could tell me whats going on there, that would be great.
Imports System.IO
Public Class Form1
Structure Students
Dim StudentName As String
Dim Test1 As Double
Dim Test2 As Double
Dim Test3 As Double
Dim Test4 As Double
Dim Test5 As Double
End Structure
Dim StudentCounter As Integer = 0
Dim MyStudentArray(StudentCounter) As Students
Private Sub LoadDataFromFileToArray()
Dim TextFile As New System.IO.StreamReader(“..\..\StudentDataFile.csv”)
Dim strStudentData As String
strStudentData = TextFile.ReadLine()
Do Until strStudentData Is Nothing
lstAllStudentData.Items.Add(strStudentData)
WriteToArray(strStudentData)
strStudentData = TextFile.ReadLine()
Loop
TextFile.Close()
End Sub
Private Sub WriteToArray(ByVal CurrentLine)
Dim Values() As String = Split(CurrentLine, ",")
ReDim Preserve MyStudentArray(StudentCounter)
MyStudentArray(StudentCounter).StudentName = Values(0)
MyStudentArray(StudentCounter).Test1 = (Values(1))
MyStudentArray(StudentCounter).Test2 = (Values(2))
MyStudentArray(StudentCounter).Test3 = (Values(3))
MyStudentArray(StudentCounter).Test4 = (Values(4))
MyStudentArray(StudentCounter).Test5 = (Values(5))
StudentCounter += 1
End Sub
Private Sub btnAddStudent_Click(sender As Object, e As EventArgs) Handles btnAddStudent.Click
ReDim Preserve MyStudentArray(StudentCounter)
MyStudentArray(StudentCounter).Test1 = CDbl(txtTest1.Text)
MyStudentArray(StudentCounter).Test2 = CDbl(txtTest1.Text)
MyStudentArray(StudentCounter).Test3 = CDbl(txtTest1.Text)
MyStudentArray(StudentCounter).Test4 = CDbl(txtTest1.Text)
MyStudentArray(StudentCounter).Test5 = CDbl(txtTest1.Text)
MyStudentArray(StudentCounter).StudentName = (txtStudentName.Text)
StudentCounter += 1
End Sub
Private Sub CalculateIndividual()
Dim AverageScore As Double = 0
Dim Test1 As Double = CDbl(txtTest1.Text)
Dim Test2 As Double = CDbl(txtTest2.Text)
Dim Test3 As Double = CDbl(txtTest3.Text)
Dim Test4 As Double = CDbl(txtTest4.Text)
Dim Test5 As Double = CDbl(txtTest5.Text)
Dim AverageGrade As String
AverageScore = (Test1 + Test2 + Test3 + Test4 + Test5) / 5
lblScoreOutput.Text = AverageScore
lblScoreOutput.Visible = True
Select Case AverageScore
Case > 90
AverageGrade = "A+"
Case 80 To 90
AverageGrade = "A"
Case 70 To 80
AverageGrade = "B"
Case 60 To 70
AverageGrade = "C"
Case 50 To 60
AverageGrade = "D"
Case 35 To 50
AverageGrade = "E"
Case Else
AverageGrade = "UG"
End Select
lblLetterOutput.Text = AverageGrade
lblLetterOutput.Visible = True
End Sub
Private Sub Form_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim response As MsgBoxResult
response = MsgBox("Do you want to close Student Calculator", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Confirm")
If response = MsgBoxResult.Yes Then
Me.Dispose()
ElseIf response = MsgBoxResult.No Then
e.Cancel = True
Exit Sub
End If
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Dim response As MsgBoxResult
response = MsgBox("Do you want to close Student Calculator?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Confirm")
If response = MsgBoxResult.Yes Then
Me.Dispose()
ElseIf response = MsgBoxResult.No Then
Exit Sub
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
lstAllStudentData.Items.Clear()
LoadDataFromFileToArray()
lstAllStudentData.Items.Clear()
LoadDataFromFileToArray()
Dim MySource As New AutoCompleteStringCollection()
For StudentCounter = 0 To StudentCounter - 1
MySource.Add(MyStudentArray(StudentCounter).StudentName)
Next
With txtSearch
.AutoCompleteCustomSource = MySource
.AutoCompleteMode = AutoCompleteMode.SuggestAppend
.AutoCompleteSource = AutoCompleteSource.CustomSource
.Visible = True
Me.Controls.Add(txtSearch)
End With
End Sub
Private Sub lstAllStudentData_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstAllStudentData.SelectedIndexChanged
txtStudentName.Text = MyStudentArray(lstAllStudentData.SelectedIndex).StudentName
txtTest1.Text = MyStudentArray(lstAllStudentData.SelectedIndex).Test1
txtTest2.Text = MyStudentArray(lstAllStudentData.SelectedIndex).Test2
txtTest3.Text = MyStudentArray(lstAllStudentData.SelectedIndex).Test3
txtTest4.Text = MyStudentArray(lstAllStudentData.SelectedIndex).Test4
txtTest5.Text = MyStudentArray(lstAllStudentData.SelectedIndex).Test5
CalculateIndividual()
End Sub
Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
Dim SearchField As String = txtSearch.Text
For StudentCounter = 0 To StudentCounter
If rdbStudent.Checked = True Then
If UCase(SearchField) = UCase(MyStudentArray(StudentCounter).StudentName) Then
lstAllStudentData.SelectedIndex = StudentCounter
Exit For
End If
End If
If rdbStudent.Checked = True Then
If UCase(SearchField) = UCase(MyStudentArray(StudentCounter).StudentName) Then
lstAllStudentData.SelectedIndex = StudentCounter
Exit For
End If
End If
Next
End Sub
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
Dim StudentFile As New System.IO.StreamWriter("..\..\StudentDataFile.csv")
For StudentCounter = 0 To MyStudentArray.Length - 1
StudentFile.Write(MyStudentArray(StudentCounter).StudentName)
StudentFile.Write(",")
StudentFile.Write(MyStudentArray(StudentCounter).Test1)
StudentFile.Write(",")
StudentFile.Write(MyStudentArray(StudentCounter).Test3)
StudentFile.Write(",")
StudentFile.Write(MyStudentArray(StudentCounter).Test4)
StudentFile.Write(",")
StudentFile.Write(MyStudentArray(StudentCounter).Test4)
StudentFile.Write(",")
StudentFile.WriteLine(MyStudentArray(StudentCounter).Test5)
Next
StudentFile.Close()
End Sub
End Class

how to count the number of check boxes checked in visual basic?

Private Sub Btn_Cast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_Cast.Click
Dim Counter As Integer = 0
If ChkBox_Barton.CheckState = 1 And ChkBox_Martin.CheckState = 1 And ChkBox_Richards.CheckState = 1 Then
MsgBox("Don't vote for more than 2")
End If
Dim Count_Barton As Integer
Dim Count_Martin As Integer
Dim Count_Richards As Integer
If ChkBox_Barton.Checked Then Count_Barton += 1
If ChkBox_Martin.Checked = 1 Then Count_Martin += 1
If ChkBox_Richards.CheckState = 1 Then Count_Richards += 1
End Sub
Problem is, I'm trying to count it everytime, then let it reset and count again.
Example. I select Barton one time, click vote, then i should be able to select someone new and click vote and it should keep counting.
what can I do?
I need to then display my results. Should I just hold the number in a text or Integer file then display it that way?
I quickly set up your application myself.
Following Code applies to this GUI:
Code:
Public Class VoteCounter
Dim intCountBarton As Integer
Dim intCountMartin As Integer
Dim intCountRichards As Integer
Private Sub ButtonVote_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonVote.Click
If CheckBoxBarton.CheckState = 1 And CheckBoxMartin.CheckState = 1 And CheckBoxRichards.CheckState = 1 Then
MsgBox("Don't vote for more than 2")
CheckBoxBarton.Checked = False
CheckBoxMartin.Checked = False
CheckBoxRichards.Checked = False
End If
If CheckBoxBarton.Checked Then
intCountBarton += 1
End If
If CheckBoxMartin.Checked Then
intCountMartin = intCountMartin + 1
End If
If CheckBoxRichards.Checked Then
intCountRichards = intCountRichards + 1
End If
CheckBoxBarton.Checked = False
CheckBoxMartin.Checked = False
CheckBoxRichards.Checked = False
End Sub
Private Sub ButtonResult_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonResult.Click
MsgBox("Barton: " & intCountBarton & vbNewLine & "Martin: " & intCountMartin & vbNewLine & "Richards: " & intCountRichards)
End Sub
Private Sub ButtonReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonReset.Click
CheckBoxBarton.Checked = False
CheckBoxMartin.Checked = False
CheckBoxRichards.Checked = False
intCountBarton = 0
intCountMartin = 0
intCountRichards = 0
End Sub
End Class
Dim Count_Barton As Integer = 0
Dim Count_Martin As Integer = 0
Dim Count_Richards As Integer = 0
Private Sub Btn_Cast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_Cast.Click
Dim Counter As Integer = 0 'NOT SURE WHAT THIS IS DOING... NOT BEING USED
If ChkBox_Barton.CheckState = 1 And ChkBox_Martin.CheckState = 1 And ChkBox_Richards.CheckState = 1 Then
MsgBox("Don't vote for more than 2")
Else
If ChkBox_Barton.Checked Then Count_Barton += 1
If ChkBox_Martin.Checked = 1 Then Count_Martin += 1
If ChkBox_Richards.CheckState = 1 Then Count_Richards += 1
End If
End Sub

How to automatically restart a program after it's closed

I'm developing a timer for my kids that will automatically shut down the computer once the time is up and I was trying to figure out a way that the program would automatically restart if it were to be closed via task manager.
I've posted my code for my program bellow if it's any help.
Imports System
Imports System.IO
Imports System.Text
Imports System.Collections.Generic
Public Class Digparent
'add to startupp:
' My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).SetValue(Application.ProductName, Application.ExecutablePath)
'remove from startup
'My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).DeleteValue(Application.ProductName)
'use application setting boolean to not add same application to startup more than once
'charge for this feature
'to do
'
'wrongn height when make timer unstopable
'above all
Dim X, Y As Integer
Dim NewPoint As New System.Drawing.Point
Public second As Integer
Public checkdone As Boolean
Public checkoff As Boolean
Public unstop As Boolean
Dim Mondayt As String
Dim Tuesdayt As String
Dim Wendsdayt As String
Dim Thursdayt As String
Dim Fridayt As String
Dim Saturdayt As String
Dim Sundayt As String
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' //
' //
' //
' //Start reader
' //
Dim timeinfo As String = "C:\Users\DigiParent\Desktop\Project data\good.txt"
' IO.File.SetAttributes("C:\Users\DigiParent\Desktop\Project data\Digitimeinfo.txt", IO.FileAttributes.Hidden)
Dim timeChecker As New System.IO.StreamWriter(timeinfo, True)
timeChecker.Close()
Dim readertime As New System.IO.StreamReader(timeinfo, Encoding.Default)
Dim texttime As String = readertime.ReadToEnd
readertime.Close()
If texttime = "" Then
Dim timeobjWriter As New System.IO.StreamWriter(timeinfo, True)
timeobjWriter.Write(",,,,")
timeobjWriter.Close()
End If
Dim startup As String = "C:\Users\DigiParent\Desktop\Project data\good.txt"
Dim reader As New System.IO.StreamReader(startup, Encoding.Default)
Dim data As String = reader.ReadToEnd
Dim aryTextFile(6) As String
aryTextFile = data.Split(",")
Mondayt = aryTextFile(0)
Tuesdayt = aryTextFile(1)
Wendsdayt = aryTextFile(2)
Thursdayt = aryTextFile(3)
Fridayt = aryTextFile(4)
'
'enable this for saturday and sunday
'
'Saturdayt = aryTextFile(5)
'Sundayt = aryTextFile(6)
reader.Close()
' //
' //
' //Finish reader
' //
End Sub
Private Sub Panel2_MouseMove(sender As Object, e As MouseEventArgs) Handles Panel2.MouseMove, time.MouseMove, timeup.MouseMove
If unstop = True Then
If e.Button = Windows.Forms.MouseButtons.Left Then
NewPoint = Control.MousePosition
NewPoint.X -= (X)
NewPoint.Y -= (Y)
Me.Location = NewPoint
End If
End If
End Sub
Private Sub Panel2_MouseDown(sender As Object, e As MouseEventArgs) Handles Panel2.MouseDown, time.MouseDown, timeup.MouseDown
If unstop = True Then
X = Control.MousePosition.X - Me.Location.X
Y = Control.MousePosition.Y - Me.Location.Y
End If
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
NumericUpDownhrs.Left -= 40
NumericUpDownmin.Left -= 40
NumericUpDownsec.Left -= 29 '25
Hourstxt.Left -= 40
Minutestxt.Left -= 30
secondstxt.Left -= 30
Panel1.Left -= 30
RadioButton2.Left -= 30
RadioButton1.Left -= 30
Label4.Left -= 30
Label5.Left -= 30
Button4.Left -= 30
time.Left -= 30
timeup.Left -= 30
If RadioButton1.Location = RadioButton5.Location Then
Timer1.Stop()
Else
End If
If Me.Height < 265 Then
Me.Height = Me.Height + 1
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
more.Visible = False
updateb.Visible = False
feedbackb.Visible = False
Timer1.Start()
Button1.Visible = False
End Sub
Private Sub RadioButton5_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton5.CheckedChanged
End Sub
Private Sub Button4_Click(snder As Object, e As EventArgs) Handles Button4.Click
My.Settings.Data = True
If RadioButton6.Checked = True Then
My.Settings.unstopable = True
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
Me.ShowInTaskbar = False
Me.ControlBox = False
Me.Text = ""
Me.ShowIcon = False
Me.ShowInTaskbar = False
Me.ControlBox = False
unstop = True
Me.Height = 149
Else
My.Settings.unstopable = False
End If
If RadioButton1.Checked = True Then
My.Settings.Shutdown = True
checkoff = True
' System.Diagnostics.Process.Start("ShutDown", "/s")
Else
My.Settings.Shutdown = False
End If
vhrs = NumericUpDownhrs.Value
vmin = NumericUpDownmin.Value
vsec = NumericUpDownsec.Value
My.Settings.hours = vhrs
My.Settings.min = vmin
My.Settings.second = vsec
PictureBox1.Dock = DockStyle.None
PictureBox1.Visible = False
starttime.Start()
realTimer.Start()
End Sub
Public Hrs As Integer 'number of hours '
Public Min As Integer 'number of Minutes '
Public Sec As Integer 'number of Sec '
Public Function GetTime(Time As Integer) As String
'Seconds'
Sec = Time Mod 60
'Minutes'
Min = ((Time - Sec) / 60) Mod 60
'Hours'
Hrs = ((Time - (Sec + (Min * 60))) / 3600) Mod 60
Return Format(Hrs, "00") & ":" & Format(Min, "00") & ":" & Format(Sec, "00")
End Function
Private Sub realTimer_Tick(sender As Object, e As EventArgs) Handles realTimer.Tick
second = second + 1
time.Text = GetTime(second)
'now
If Min >= vmin And Hrs >= vhrs And Sec >= vsec Then
checkdone = True
Me.TopMost = True
'Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedSingle
endtime.Start()
If unstop = True Then
closeb.Visible = True
End If
realTimer.Stop()
End If
If checkdone = True And checkoff = True Then
endtime.Start()
System.Diagnostics.Process.Start("ShutDown", "/s")
End If
End Sub
Private Sub starttime_Tick(sender As Object, e As EventArgs) Handles starttime.Tick
time.Left -= 30
Panel1.Left -= 30
RadioButton2.Left -= 30
RadioButton1.Left -= 30
Label4.Left -= 30
Label5.Left -= 30
Button4.Left -= 30
timeup.Left -= 30
If time.Location = Label2.Location Then
starttime.Stop()
End If
If Me.Height > 189 Then
Me.Height = Me.Height - 5
End If
End Sub
Private Sub endtime_Tick(sender As Object, e As EventArgs) Handles endtime.Tick
time.Left -= 30
timeup.Left -= 30
If timeup.Location = labeltimeup.Location Then
endtime.Stop()
End If
End Sub
Private Sub more_Click(sender As Object, e As EventArgs) Handles more.Click
Form3.Show()
'more.Visible = False
'moretimer.Start()
End Sub
Private Sub moretimer_Tick(sender As Object, e As EventArgs) Handles moretimer.Tick
If updateb.Location = Updatebutton.Location Then
moretimer.Stop()
End If
feedbackb.Left += 15
updateb.Left -= 15
End Sub
Private Sub updateb_Click(sender As Object, e As EventArgs) Handles updateb.Click
System.Diagnostics.Process.Start("http://digiparent.weebly.com/beta-20-update.html")
End Sub
Private Sub feedbackb_Click(sender As Object, e As EventArgs) Handles feedbackb.Click
System.Diagnostics.Process.Start("http://digiparent.weebly.com/feedback.html")
End Sub
Private Sub closeb_Click(sender As Object, e As EventArgs) Handles closeb.Click
Me.Close()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
NumericUpDownsec.Value = My.Settings.second
NumericUpDownmin.Value = My.Settings.min
NumericUpDownhrs.Value = My.Settings.hours
If My.Settings.Shutdown = True Then
RadioButton1.Checked = True
End If
If My.Settings.unstopable = True Then
RadioButton6.Checked = True
End If
Button2.Visible = False
End Sub
Private Sub Numericchanged(sender As Object, e As EventArgs) Handles NumericUpDownsec.ValueChanged, NumericUpDownmin.ValueChanged, NumericUpDownhrs.ValueChanged
If NumericUpDownsec.Value = 0 Then ' NumericUpDownhrs.Value = 0 NumericUpDownmin.Value = 0 Then
If NumericUpDownhrs.Value = 0 Then
If NumericUpDownmin.Value = 0 Then
Button2.Visible = True
Else
Button2.Visible = False
End If
Else
Button2.Visible = False
End If
Else
Button2.Visible = False
End If
End Sub
Private Sub Label4_Click(sender As Object, e As EventArgs) Handles Label4.Click
End Sub
End Class
Here's a very basic windowless watchdog app.
Start with a standard WinForms project.
Add a Module.
Add a Public Sub Main to it.
Go to Project --> Properties --> Application Tab, and Uncheck the "Enable Application Framework" box.
Above that, change the "Startup object:" dropdown from "Form1" to "Sub Main".
The code...
Module Module1
Public Sub Main()
Application.Run(New Watchdog)
End Sub
End Module
Public Class Watchdog
Inherits ApplicationContext
Private AppToWatch As String
Private FullPath As String = "C:\WINDOWS\system32\calc.exe"
Private WithEvents P As Process
Public Sub New()
AppToWatch = System.IO.Path.GetFileNameWithoutExtension(FullPath)
Dim PS() As Process = Process.GetProcessesByName(AppToWatch)
If PS.Length = 0 Then
StartIt()
Else
P = PS(0)
P.EnableRaisingEvents = True
End If
End Sub
Private Sub P_Exited(sender As Object, e As EventArgs) Handles P.Exited
StartIt()
End Sub
Private Sub StartIt()
P = Process.Start(FullPath)
P.EnableRaisingEvents = True
End Sub
End Class
Compile the program as a service, and configure it to start automatically.

The button.BackColor statement seem to be executed, but no colour change is show

I'm trying to re-create the classic game "Simon" for a project. The code I have here should hopefully create a random number, translate that to a colour change for a random button, wait a short time, and then do the same for another random button. I can't spot any problems, but on execution the buttons remain uchanged.
Public Class MenuForm
Dim failure As Boolean
Dim pattern() As Integer
Dim maincounter As Integer = 1
Dim diff As Integer
Dim sender As Object
Dim e As EventArgs
Dim timewaited As Integer
Dim timefinished As Boolean
Private Sub Menuform_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Get the difficulty level from the player
Dim InputtedDifficulty As Integer = InputBox("Please enter difficulty. 1-Easy 2-Medium 3-Hard")
'Validate difficulty choice
Do While InputtedDifficulty > 3 Or InputtedDifficulty < 1
InputtedDifficulty = InputBox("Input incorrect. Please re-enter selection. 1-Easy 2-Medium 3-Hard")
Loop
'Set speed of blinking based on difficulty choice
Select Case InputtedDifficulty
Case 1
diff = 1000
Case 2
diff = 500
Case 3
diff = 20
End Select
End Sub
Private Sub run_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles run.Click
Call GameController()
End Sub
Private Sub GameController()
Dim buttonRepeater As Integer
'Call checkFail()
Do While failure = False
maincounter = maincounter + 1
Call Pattern_creator(sender, e)
For buttonRepeater = 1 To maincounter
Call button_controller(sender, e)
timewaited = 0
timefinished = False
ButtonTimer.Enabled = True
If timefinished = True Then
End If
Button1.BackColor = Color.Blue
Button2.BackColor = Color.Blue
Button3.BackColor = Color.Blue
Button4.BackColor = Color.Blue
Next buttonRepeater
Loop
End Sub
Private Sub Pattern_creator(ByVal sender As System.Object, ByVal e As System.EventArgs)
ReDim Preserve pattern(maincounter)
Randomize()
pattern(maincounter) = Int((Rnd() * 4) + 1)
ReDim Preserve pattern(maincounter + 1)
End Sub
Private Sub button_controller(ByVal sender As System.Object, ByVal e As System.EventArgs)
'Ths case statement takes the random number generated earlier and translates that to
'a button flash
Select Case pattern(maincounter)
Case 1
Button1.BackColor = Color.Red
Case 2
Button2.BackColor = Color.Red
Case 3
Button3.BackColor = Color.Red
Case 4
Button4.BackColor = Color.Red
End Select
End Sub
Private Sub ButtonTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonTimer.Tick
If timewaited = 5 Then
ButtonTimer.Enabled = False
timefinished = True
Else
timewaited = timewaited + 1
End If
End Sub
End Class
Any help would be very much appreciated, I've been staring at this for ages with no progress.