VB.net Navigating Text Adventure Game - vb.net

I am working on a text adventure game. The goal of this program is to display three options and a textbox. The user can select one of the options by entering the corresponding number into a text box, which then is supposed to navigate the user into the next area, where the user is presented with another 3 options.
The issue I am currently having is navigating through the area game areas.
Sub gameOver(ByVal DeathMessage)
lblTitle.Text = "Game Over!"
lblMain.Text = DeathMessage
End Sub
Sub pgMain()
lblMain.Text = $"Enter 1 to start the game{vbCrLf}Enter 2 to quit the game"
If aryInput(0) = "1" Then
pg1()
ElseIf aryInput(0) = "2" Then
Me.Close()
End If
End Sub
Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
aryInput(0) = tbxInput.Text
End Sub
Sub pg1() ' User picks a starting option
lblTitle.Text = "You spot a secret magical lair do you"
lblMain.Text = $"1. Enter the lair through the front door{vbCrLf}2. Enter the lair through the back door{vbCrLf}3. Wait untill midnight to enter the lair."
If aryInput(0) = "1" Then
MsgBox("Front door") 'pg2()
ElseIf aryInput(0) = "2" Then
MsgBox("backdoor")
pg3()
ElseIf aryInput(0) = "3" Then
gameOver("You were mauled by wolves")
End If
End Sub
'Sub pg2() ' User entered through the front door.
' lblMain.Text = $"1. Go to the chest{vbCrLf}2. Go to the bookshelf{vbCr}3. Go to the cauldron"
' If tbxInput.Text = "1" Then
' pg5() ' They went to the chest
' ElseIf tbxInput.Text = "2" Then
' pg6() ' User went to the bookshelf
' ElseIf tbxInput.Text = "3" Then
' pg7() ' User went to the cauldron
' End If
'End Sub
Sub pg3()
tbxInput.Text = Nothing
lblTitle.Text = "You were splashed with a poison spell do you"
lblMain.Text = $"1. Cut off the infected part{vbCrLf}2. Drink a bucket of milk{vbCrLf}3. Inject yourself with some sort of medical syringe"
If tbxInput.Text = "1" Then
MsgBox("Infected Part") 'pg8()
ElseIf tbxInput.Text = "2" Then
MsgBox("Milk") 'pg9()
ElseIf tbxInput.Text = "3" Then
gameOver("You injected yourself with viper venom.")
End If
End Sub
As you can probably tell I am having issues with getting the content of the textbox to decide where the user will go next. I have tried using Input Boxes, and yes it works but they have a character limit and I would prefer figuring out a way to do this with a text box. I was also considering a way using key presses instead of a button click. Sorry for the beginner question, I am still learning my way around Visual Basic. Thank you in advance!

I like radio buttons better because it is easier to control user input. A user can put anything in a text box and you need to handle the possibility that it is not 1, 2, or 3.
Initially RadioButton3.Visible is set to False at design time. It becomes visible if the user selects to start the game.
We kick the whole thing off in Form.Load. I declared a Form level variable to keep track of what page we are on, PageNum.
I have only set properties in the pgX subs. All the action is in the submit button. The first thing is to find which radio button is selected. The GetSelectedRadioButton returns the selected button or Nothing. You have to pass Me (which refers to the Form, the class where the code is running) as the container. Often radio buttons are found in a GroupBox or other container control so this allows for that.
You will need to write the code for pg5, pg6, pg7, pg8, and pg9. Also add Case 5, Case 6, Case 7, Case 8, and Case 9 to the submit button.
Private PageNum As Integer
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
pgMain()
End Sub
Private Sub pgMain()
lblMain.Text = "Make a selection and click Submit"
RadioButton1.Text = "start the game"
RadioButton2.Text = "quit the game"
End Sub
Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
Dim rb As RadioButton = GetSelectedRadioButton(Me)
If rb IsNot Nothing Then
Dim Name = rb.Name
Select Case PageNum
Case 0
If Name = "RadioButton1" Then
pg1()
ElseIf Name = "RadioButton2" Then
Close()
End If
Case 1
If Name = "RadioButton1" Then
MsgBox("Front door") '
pg2()
ElseIf Name = "RadioButton2" Then
MsgBox("backdoor")
pg3()
ElseIf Name = "RadioButton3" Then
gameOver("You were mauled by wolves")
End If
Case 2
If Name = "RadioButton1" Then
pg5() ' They went to the chest
ElseIf Name = "RadioButton2" Then
pg6() ' User went to the bookshelf
ElseIf Name = "RadioButton3" Then
pg7() ' User went to the cauldron
End If
Case 3
If Name = "RadioButton1" Then
MsgBox("Infected Part")
pg8()
ElseIf Name = "RadioButton2" Then
MsgBox("Milk")
pg9()
ElseIf Name = "RadioButton3" Then
gameOver("You injected yourself with viper venom.")
End If
End Select
Else
MessageBox.Show("Please make a selection.")
End If
End Sub
Public Function GetSelectedRadioButton(Container As Control) As RadioButton
Dim rb = Container.Controls.OfType(Of RadioButton)().FirstOrDefault(Function(r) r.Checked = True)
Return rb
End Function
Private Sub pg1() ' User picks a starting option
PageNum = 1
lblTitle.Text = "You spot a secret magical lair do you"
RadioButton1.Text = "Enter the lair through the front door"
RadioButton2.Text = "Enter the lair through the back door"
RadioButton3.Visible = True 'Set to False at design time
RadioButton3.Text = "Wait untill midnight to enter the lair."
End Sub
Private Sub pg2() ' User entered through the front door.
PageNum = 2
lblTitle.Text = "You see a chest, a bookself, and a cauldron"
RadioButton1.Text = "Go to the chest"
RadioButton2.Text = "Go to the bookshelf"
RadioButton3.Text = "Go to the cauldron"
End Sub
Private Sub pg3()
PageNum = 3
lblTitle.Text = "You were splashed with a poison spell do you"
RadioButton1.Text = "Cut off the infected part"
RadioButton2.Text = "Drink a bucket of milk"
RadioButton3.Text = "Inject yourself with some sort of medical syringe"
End Sub
Private Sub gameOver(DeathMessage As String)
lblTitle.Text = "Game Over!"
lblMain.Text = DeathMessage
RadioButton1.Visible = False
RadioButton2.Visible = False
RadioButton3.Visible = False
btnSubmit.Visible = False
End Sub

Related

Creating a confirmation which switches back to previous radio button if user cancels

So I currently have a form where I have 4 teams, each with 4 teammates. This cannot change.
my form GUI
Initially when the program starts, it automatically selects the "current value" radio button which displays labels with blank data, you can then select "edit values" which can be saved by pressing the big green apply button. This stores the data under a 2d array named stTeamName, which the labels reference whenever you select "current value" again.
There are 4 radio buttons which allow you to switch between the teams.
My problem is, when I change the radio buttons, any data put into the text labels that has not been saved will be deleted.
I solved this problem by adding a message box which will stop the data in the labels from changing unless the user gives confirmation to do so.
However, my only problem is that after I cancel this, the radio button stays at the current selection which does not help.
I solved this issue by using rbTeamName1.Checked = True (rbTeamname 1 to 4 being the radio buttons named team 1-4) to switch back to the previous state.
This of course only goes back to rbTeamname1 no matter what, so I employed an 1d array and select case to help solve this issue.
"""
Dim RadioCounter(1) As Integer
the code below simply gives the default Radio button value on load.`
Sub DeclareRadio(RadioButton)
RadioButton(1) = 1
End Sub
"""
Whenever a radio button is successfully selected, RadioCounter(1) is set to the number 1-4 respectively. Whenever a new radio button is selected, the value of RadioCounter(1) is moved to RadioCounter(0) and the current radio button's value is to RadioCounter(1).
If the user selects no, RadioCounter(0)'s value is referenced and a select case selects the radio button.
(Please note, RadioTeam() is used as a counter to store Team name and Teammate name string variables correctly within the 2d array: stTeamName. I will most likely merge this with RadioCounter as soon as I get this problem fixed)
"""
Private Sub rbTeamName1_CheckedChanged(sender As Object, e As EventArgs) Handles rbTeamName1.CheckedChanged
'note txtTeamName starts at 0, however RadioTeam starts at 1, RadioTeam = 0 has no team designated to it.
'this function is for swapping teams via radio button, each time, a confirmation is given to make sure the user saves the current team, or risk deletion of the inputted data.
RadioCounter(1) = RadioCounter(0)
stTeamname(0, RadioTeam) = txtTeamName.Text
stTeamname(1, RadioTeam) = txtMate1.Text
stTeamname(2, RadioTeam) = txtMate2.Text
stTeamname(3, RadioTeam) = txtMate3.Text
stTeamname(4, RadioTeam) = txtMate4.Text
Dim Dialog As DialogResult
Dialog = MessageBox.Show("Are you sure you want to change team? Any unsaved changes will be lost. If this box shows on starting the program, just press no", "Change team?", MessageBoxButtons.YesNo)
If Dialog = DialogResult.No Then
'need to run function to check previous result of radio button'
Select Case RadioCounter(0)
Case 1
rbTeamName1.Checked = True
Case 2
rbTeamName2.Checked = True
Case 3
rbTeamName3.Checked = True
Case 4
rbTeamName4.Checked = True
End Select
ElseIf Dialog = DialogResult.Yes Then
RadioCounter(1) = 1 'this equals the respective number for each radio button'
RadioTeam = 1
txtTeamName.Text = stTeamname(0, RadioTeam)
txtMate1.Text = stTeamname(1, RadioTeam)
txtMate2.Text = stTeamname(2, RadioTeam)
txtMate3.Text = stTeamname(3, RadioTeam)
txtMate4.Text = stTeamname(4, RadioTeam)
lblTeamName.Text = stTeamname(0, RadioTeam)
lblMate1.Text = stTeamname(1, RadioTeam)
lblMate2.Text = stTeamname(2, RadioTeam)
lblMate3.Text = stTeamname(3, RadioTeam)
lblMate4.Text = stTeamname(4, RadioTeam)
End If
End Sub
"""
....Or it should do that. But it doesnt. Im not sure why, but when I force it to check a specific radio button, by removing the select case and only running rbTeamName4.Checked = True it will work perfectly fine, theres something about the select case that simply doesnt run the code.
Also, despite stTeamname(0, RadioTeam) = txtTeamName.Text etc. being given before the messagebox shows, if I do not press the apply button to save, press another team button, then press no, it will still not save those parameters, which I find extremely weird.
What is the ideal solution to this?
To clarify:
If a user writes team names and teammates and does not press the apply button to save and then changes team by selecting another radio button, a text box should appear asking whether they want to switch team and lose the data (Yes) or stay on the previous radio button to edit and apply the data (No).
Upon pressing no, the program automatically switches the current radio button to the previous selection to make it seem as if no radio button was selected in the first place.
And im not sure if I have to make it obvious but im new to both stackoverflow and VB.net in general. Thank you in advance.
Essentially what you are asking for is dirty form checking. The basic principle is that you need to compare the value to what it was previously.
So for example:
When the TextBox values change, set a form level boolean variable to true
When you go to switch teams or current/edit you would check if that form level boolean variable is true
If the variable is true then you would display the prompt, otherwise just do the action
After the action, reset the global level boolean variable
There are some caveats, for example, when you toggle between current/edit the check changed will fire twice: once for the current radio button and once for the edit. But you just need to work around those edge cases.
Here is a largely untested example for you to go off of:
Imports System.ComponentModel
Imports System.Runtime.CompilerServices
Public Class Form1
Private _team1 As Team
Private _team2 As Team
Private _team3 As Team
Private _team4 As Team
Private _isFormDirty As Boolean = False
Private _selectedTeamRadioButton = RadioButtonTeam1
Private Sub RadioButtonCurrent_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButtonCurrent.CheckedChanged
If (RadioButtonCurrent.Checked AndAlso _isFormDirty AndAlso MessageBox.Show("By doing this, you will lose all unsaved changes. Are you sure?", "Dirty Form", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.No) Then
RadioButtonEdit.Checked = True
Return
End If
If (Not RadioButtonCurrent.Checked) Then
Return
End If
TextBoxTeamName.Enabled = False
TextBoxTeammate1.Enabled = False
TextBoxTeammate2.Enabled = False
TextBoxTeammate3.Enabled = False
TextBoxTeammate4.Enabled = False
ResetTeam()
End Sub
Private Sub RadioButtonEdit_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButtonEdit.CheckedChanged
TextBoxTeamName.Enabled = True
TextBoxTeammate1.Enabled = True
TextBoxTeammate2.Enabled = True
TextBoxTeammate3.Enabled = True
TextBoxTeammate4.Enabled = True
End Sub
Private Sub RadioButtonTeamChanged(sender As Object, e As EventArgs) Handles RadioButtonTeam1.CheckedChanged, RadioButtonTeam2.CheckedChanged, RadioButtonTeam3.CheckedChanged, RadioButtonTeam4.CheckedChanged
If (_selectedTeamRadioButton IsNot DirectCast(sender, RadioButton) AndAlso _isFormDirty AndAlso MessageBox.Show("By doing this, you will lose all unsaved changes. Are you sure?", "Dirty Form", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.No) Then
_selectedTeamRadioButton.Checked = True
Return
End If
If (_selectedTeamRadioButton IsNot DirectCast(sender, RadioButton)) Then
Return
End If
_selectedTeamRadioButton = DirectCast(sender, RadioButton)
ResetTeam()
End Sub
Private Sub TextBoxTeamValueChanged(sender As Object, e As EventArgs) Handles TextBoxTeamName.TextChanged, TextBoxTeammate1.TextAlignChanged, TextBoxTeammate2.TextAlignChanged, TextBoxTeammate3.TextAlignChanged, TextBoxTeammate4.TextAlignChanged
_isFormDirty = True
End Sub
Private Sub ButtonApply_Click(sender As Object, e As EventArgs) Handles ButtonApply.Click
Select Case True
Case RadioButtonTeam1.Checked
_team1 = New Team() With {
.Name = TextBoxTeamName.Text,
.Teammate1 = TextBoxTeammate1.Text,
.Teammate2 = TextBoxTeammate2.Text,
.Teammate3 = TextBoxTeammate3.Text,
.Teammate4 = TextBoxTeammate4.Text
}
Case RadioButtonTeam2.Checked
_team2 = New Team() With {
.Name = TextBoxTeamName.Text,
.Teammate1 = TextBoxTeammate1.Text,
.Teammate2 = TextBoxTeammate2.Text,
.Teammate3 = TextBoxTeammate3.Text,
.Teammate4 = TextBoxTeammate4.Text
}
Case RadioButtonTeam3.Checked
_team3 = New Team() With {
.Name = TextBoxTeamName.Text,
.Teammate1 = TextBoxTeammate1.Text,
.Teammate2 = TextBoxTeammate2.Text,
.Teammate3 = TextBoxTeammate3.Text,
.Teammate4 = TextBoxTeammate4.Text
}
Case RadioButtonTeam4.Checked
_team4 = New Team() With {
.Name = TextBoxTeamName.Text,
.Teammate1 = TextBoxTeammate1.Text,
.Teammate2 = TextBoxTeammate2.Text,
.Teammate3 = TextBoxTeammate3.Text,
.Teammate4 = TextBoxTeammate4.Text
}
End Select
_isFormDirty = False
End Sub
Private Sub ButtonDeleteTeam_Click(sender As Object, e As EventArgs) Handles ButtonDeleteTeam.Click
If (MessageBox.Show("Are you sure you want to delete this team?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.No) Then
Return
End If
_isFormDirty = False
Select Case True
Case RadioButtonTeam1.Checked
_team1 = New Team()
Case RadioButtonTeam2.Checked
_team2 = New Team()
Case RadioButtonTeam3.Checked
_team3 = New Team()
Case RadioButtonTeam4.Checked
_team4 = New Team()
End Select
ResetTeam()
End Sub
Private Sub ResetTeam()
Dim selectedTeam As Team = Nothing
Select Case True
Case RadioButtonTeam1.Checked
selectedTeam = _team1
Case RadioButtonTeam2.Checked
selectedTeam = _team2
Case RadioButtonTeam3.Checked
selectedTeam = _team3
Case RadioButtonTeam4.Checked
selectedTeam = _team4
End Select
If (selectedTeam IsNot Nothing) Then
TextBoxTeamName.Text = selectedTeam.Name
TextBoxTeammate1.Text = selectedTeam.Teammate1
TextBoxTeammate2.Text = selectedTeam.Teammate2
TextBoxTeammate3.Text = selectedTeam.Teammate3
TextBoxTeammate4.Text = selectedTeam.Teammate4
Else
TextBoxTeamName.Clear()
TextBoxTeammate1.Clear()
TextBoxTeammate2.Clear()
TextBoxTeammate3.Clear()
TextBoxTeammate4.Clear()
End If
End Sub
End Class
Public Class Team
Implements INotifyPropertyChanged
Private _name As String
Public Property Name As String
Get
Return _name
End Get
Set(value As String)
If (_name <> value) Then
_name = value
NotifyPropertyChanged()
End If
End Set
End Property
Private _teammate1 As String
Public Property Teammate1 As String
Get
Return _teammate1
End Get
Set(value As String)
If (_teammate1 <> value) Then
_teammate1 = value
NotifyPropertyChanged()
End If
End Set
End Property
Private _teammate2 As String
Public Property Teammate2 As String
Get
Return _teammate2
End Get
Set(value As String)
If (_teammate2 <> value) Then
_teammate2 = value
NotifyPropertyChanged()
End If
End Set
End Property
Private _teammate3 As String
Public Property Teammate3 As String
Get
Return _teammate3
End Get
Set(value As String)
If (_teammate3 <> value) Then
_teammate3 = value
NotifyPropertyChanged()
End If
End Set
End Property
Private _teammate4 As String
Public Property Teammate4 As String
Get
Return _teammate4
End Get
Set(value As String)
If (_teammate4 <> value) Then
_teammate4 = value
NotifyPropertyChanged()
End If
End Set
End Property
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Private Sub NotifyPropertyChanged(<CallerMemberName()> Optional propertyName As String = Nothing)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End Sub
End Class

Or function only looks at first value

Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
Dim difficulty As Integer 'Sets difficulty as integer
If txtBack.Visible = True Or btnDisplay.Enabled = False Then 'if back of the flashcard is visible and if the start button has been clicked
If Integer.TryParse(TxtDifficulty.Text, difficulty) AndAlso difficulty >= 1 AndAlso difficulty <= 3 Then 'If diffiuclty is between 1 and 3
Dim front = txtFront.Text 'Defines front as variable which is equal to txtfront.text
UpdateDifficultyLevel(front, difficulty) 'Calls subroutine
MsgBox("Difficulty updated succesfully") 'outputs messagebox saying difficulty has been updated succesfully
Else 'If user input is not an integer
MsgBox("Please enter a number between 1 and 3") ' tells user that the difficulty must be a number
End If
Else 'If back of the flashcard is not visible and is start button has not been clicked
MsgBox("Please display the flashcard") 'Tells user to display flashcard.
End If
End Sub
This code is supposed to check if txtback.visible = true or btndisplay.enabled = false then runs the appropriate code. However only the txtback.visible works. How would I get the code to also check if btndisplay.enabled = false?
Are you sure you want to use Or? The comment on that if statement says:
"if condition1 AND condition2 are true, then...". In that case, if you want both to be checked and evaluated as true just do
If txtBack.Visible = True And btnDisplay.Enabled = False Then

VB.NET Form.Show closes the application for unknown reason

VB.NET Framework 4.7.2
Visual Studio Community 2019 V16.11.2
I have a WinForms application and, for the most part, I start with a form to display the loading of datatables. This is handled in the Application Events module:
Private Sub MyApplication_Startup(sender As Object, e As StartupEventArgs) Handles Me.Startup
If String.IsNullOrEmpty(My.Settings.TheCompany) Then
MainForm = FormConnection
Else
MainForm = FormDataLoad
End If
End Sub
When the datatables are all loaded the FormDataLoad has a close button which is enabled by the procedure which loads all the datatables:
With FormDataLoad
.ButtonClose.Visible = True
End With
When the button is pressed it calls another form which displays various charts etc based on the datatables which have been loaded:
Private Sub ButtonClose_Click(sender As Object, e As EventArgs) Handles ButtonClose.Click
Me.Close()
End Sub
Private Sub FormDataLoad_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
With FormOverview
.Show()
End With
End Sub
When FormOverview loads, its labels, charts etc are all initialised and drawn BUT, mysteriously, the form closes and the application ends. The Application Shutdown event is raised:
' Shutdown: Raised after all application forms are closed. This event is not raised if the application terminates abnormally.
Private Sub MyApplication_Shutdown(sender As Object, e As EventArgs) Handles Me.Shutdown
MessageBox.Show("Closing the application for some unknown reason")
End Sub
When this message box is displayed it means that the application has closed but not as a result of any unhandled exception. Nowhere in the project is there any code to call FormOverview.close so I am at a loss to understand what is happening.
The form load code is here:
Private Sub FormOverview_Load(sender As Object, e As EventArgs) Handles Me.Load
With Me
'Set the form caption and back colour and font
.Text = "Retail Management Hero Data Visualisation Overview"
.BackColor = Color.GhostWhite
.Font = U.BasicFontSmall
'Add event handler for the DAL
AddHandler D.ConnectionOpened, AddressOf Connected
'Form level variables for the KPJs
Dim ITO As String = ""
Dim ATV As String = ""
Dim CRR As String = ""
Dim GMROI As String = ""
Dim OOS As String = ""
Dim StocksSales As String = ""
With KPIData.Rows(0)
Me.Text = My.Settings.TheCompany & " " & Me.Text
ITO = .Item("ITO").ToString
CRR = .Item("CRR").ToString
ATV = "€" & .Item("ATV").ToString
GMROI = "€" & .Item("GMROI").ToString
OOS = .Item("OOSRatio").ToString
StocksSales = .Item("StocksToSales").ToString
End With
For Each CTL As Control In .Controls
If TypeOf CTL Is Label Then
With CTL
If .Name.Contains("Value") Then
.Font = U.BasicFontSuperLarge
.BackColor = Color.Yellow
Else
.BackColor = U.Spurs
.ForeColor = Color.GhostWhite
End If
End With
End If
Next
With .LabelReportDate
.Text = "Reports As Of " & ReportDate
End With
With .LabelATVValue
.Text = U.DecimalToSuperSubFormat(ATV, True)
End With
With .LabelGMROIValue
.Text = U.DecimalToSuperSubFormat(GMROI, True)
End With
With .LabelCRRValue
.Text = U.DecimalToSuperSubFormat(CRR, True) & "%"
End With
With .LabelITOValue
.Text = U.DecimalToSuperSubFormat(ITO, True)
End With
With .LabelOOSValue
.Text = U.DecimalToSuperSubFormat(OOS, True) & "%"
End With
With .LabelStocksSalesValue
.Text = U.DecimalToSuperSubFormat(StocksSales, True) & "%"
End With
'Extract the names of the X and Y axes
Dim Xname As String = ""
Dim Yname As String = ""
With WineData
Xname = .Columns("Department").ColumnName
Yname = .Columns("Day").ColumnName
End With
'Draw the charts
DrawColumnChart(WineData, .ChartWine, "Wine sales", Xname, Yname, 250, False)
DrawColumnChart(OtherData, .ChartNonWine, "Other sales", Xname, Yname, 25, False)
'Centre on the screen
.CenterToScreen()
End With
End Sub
So, what should happen is that this form displays centre screen with charts etc all displayed correctly.
If anyone has any ideas I would be most grateful.
Dermot
I found out what was causing the problem.
In the Project's properties, in the Application tab, there Combo selector, Shutdown mode.
The option I had selected was When startup form closes - by changing this to When last form closes the issue went away.
Like many problems, when you look at it too long you can't see the woods for the trees.

Label not Showing Variable as Coded

I have a series of tests which when completed by a user the score is stored in a variable and written into a file. Within my program is a progress screen for each user, which is supposed to show all of the test scores in labels.
I have used this code to show the score in the label :
lblTopic1Score.Text = Topic1Score
However when I run the system and go onto the progress form the label is blank.
Can anyone help ?
Code for the Progress form:
Private Sub StProgress_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lblTopic1Score.Text = Topic1Score
lblTotalScore.Text = TotalScore
lblStName.Text = namest
LblStSurname.Text = surnamest
End Sub
Module was created to store Public variables
Public Topic1Score As String
This is a code extract from the test itself
If answers(i) = questions(i, 4) And FileOpenStatusTS = False Then
Topic1Score += 1
TotalScore += 1
End If
Next
If yearst = "12" And classst = "A" Then
FileOpen(1, FileName12A1, OpenMode.Append)
FileOpenStatus12A1 = True
'Once all the details have been entered and checked, then they are written to the Teacher accounts text file'
WriteLine(1, Username, Topic1Score, TotalScore)
FileClose(1)
End If`

Changing ToolStripMenuItem Enabled Property Based on Successful Login

What I've done so far . . .
Private Sub LogInToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles LogInToolStripMenuItem.Click
Try
If (txtAdminUserId.Text <> "admin" AndAlso txtMaintenacePassword.Text <> "1234") Then
MessageBox.Show("Please enter the correct UserID and also verify your Pasword. ", "UserID and Password Error")
txtAdminUserId.Select()
txtAdminUserId.Focus()
Return
Else
txtAdminUserId.Clear()
txtMaintenacePassword.Clear()
Dim frmGameMaintenanceX As New frmGameMaintenance() 'declare game order form
Me.Visible = False
frmGameMaintenanceX.Show() 'switch to order movie form
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Caught General Error") ' last attempt to catch an exception
End Try
End Sub
Based on the requirements for a ToolStripMenuItem as follows verbatim from my instructor:
“Add a maintenance menu with Log-in (enabled) as menu item. When the user successfully logs in (with admin and 1234 as the userid and password), disable the log-in menu item and make menu items Games, Platforms, Ratings, and Log-out visible. When the user logs out, enable the log-in menu item, hide the Games, Platforms, Ratings, and Log-out menu items.”
Let's keep it simple. Use an if statement to test if the user attempts to log in with the proper userid and password (defined as constants in your code).”
What is an efficient way to handle ToolStripMenuItem with very limited password requirements?  You have the click event from “Log-In”  but where would the maintenance user enter his userid and password smoothly?
Use the following method in module and you can call it anywhere when you want to enable/disable ToolStripMenuItems
Public Sub SetAllMenuItems(ByRef menuStrip As MenuStrip, ByVal enable As Boolean)
Dim c As ToolStripItem
Dim t As ToolStripMenuItem
For Each c In menuStrip.Items
c.Enabled = enable
If c.GetType Is GetType(ToolStripMenuItem) Then
t = c
SetAllMenuItems(t.DropDownItems, enable)
End If
Next
End Sub
Public Sub SetAllMenuItems(ByRef menus As ToolStripItemCollection, ByVal enable As Boolean)
Dim c As ToolStripItem
Dim t As ToolStripMenuItem
For Each c In menus
c.Enabled = enable
If c.GetType Is GetType(ToolStripMenuItem) Then
t = c
SetAllMenuItems(t.DropDownItems, enable)
End If
Next
End Sub
This code will suffice while I continue to learn . . .
Private Sub LogInToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles LogInToolStripMenuItem.Click
Try
If (txtAdminUserId.Text <> cstUsrId OrElse txtMaintenacePassword.Text <> cstPsswrd OrElse txtAdminUserId.Text.Length <> 5 OrElse txtMaintenacePassword.Text.Length <> 4) Then
MessageBox.Show("Please enter the correct UserID and also verify your Pasword. ", "UserID and Password Error")
txtAdminUserId.Select()
txtAdminUserId.Focus()
Return
Else
txtAdminUserId.Clear()
txtMaintenacePassword.Clear()
LogInToolStripMenuItem.Visible = False
LogOutToolStripMenuItem.Visible = True
LogOutToolStripMenuItem.Visible = True
GameToolStripMenuItem.Visible = True
GamesToolStripMenuItem.Visible = True
PlatformToolStripMenuItem.Visible = True
RatingsToolStripMenuItem.Visible = True
LogInToolStripMenuItem.Enabled = False
LogOutToolStripMenuItem.Enabled = True
LogOutToolStripMenuItem.Enabled = True
GameToolStripMenuItem.Enabled = True
GamesToolStripMenuItem.Enabled = True
PlatformToolStripMenuItem.Enabled = True
RatingsToolStripMenuItem.Enabled = True
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Caught General Error") ' last attempt to catch an exception
End Try
End Sub