Hi,
I am new to VB, and I having problems to re-run a code by the click of a button, I has been searching all over the internett and it seems that the answers I found don't seem to work with my code..
What I want to do is, when the user click the button NEXT then the codes runs again to update the information presented in the labels of the form, the problem is that when I added the line Call Me() in the event handler next_button_click to rerun the code I get this error message: expresion is not a method.
I would apreciate any advice to solve this problem.
Thanks in advance.
Here is my code:
Imports System.IO.Path
Imports System.IO
Public Class Thor2_questions
Dim arrayfiles As IO.FileInfo
Public Sub Thor2_questions_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'define the directory to look for the files
Dim directory As New IO.DirectoryInfo("C:\Users\t727058\Desktop\VB\Sat quiz\Sat quiz\Thor 2 subsystem A questions and answers")
'define an array which is going to have files of type .txt from the directory
Dim arrayFiles = directory.GetFiles("*.txt")
'to randomize the index of the arrayfiles array
Dim randomtext As New Random
Dim index As Integer
index = randomtext.Next(arrayFiles.Length)
'this variable is going to content a single .txt file from the directory
Dim file As IO.FileInfo
'this variable is going to access/read the name of the txt file in the array
Dim FSR As StreamReader
'declare a string variable which is going to read the whole (to the end) .txt file
Dim filecontent As String
' ---------------------------------------------------------------------------------------------------------------------------------------------------
'This is the part for the questions and answer from a single .txt file!
For Each file In arrayFiles
file = arrayFiles(index)
'define FSR as new streamreader which contents the name of the .txt file in the array
FSR = New StreamReader(file.FullName)
'read the whole .txt file until the end and place the content in the string variable filecontent
filecontent = FSR.ReadToEnd
'close the reader in order to make place to the other .txt file?
FSR.Close()
'make an array of type string with 4 indexes for the one question and three answer
Dim QA(4) As String
'split the content of the filecontent variable by the ~ sign
QA = Split(filecontent, "~")
Try
'place the content of the .txt file in correct order in the labels of the form
QUESTION.Text = QA(0)
ANSWER1.Text = QA(1)
ANSWER2.Text = QA(2)
ANSWER3.Text = QA(3)
Catch ex As Exception
End Try
Next
End Sub
Public Sub next_button_Click(sender As Object, e As EventArgs) Handles next_button.Click
Call Me()
End Sub
End Class
I am new to VB, and I having problems to re-run a code by the click of a button, I has been searching all over the internett and it seems that the answers I found don't seem to work with my code..
What I want to do is, when the user click the button NEXT then the codes runs again to update the information presented in the labels of the form, the problem is that when I added the line Call Me() in the event handler next_button_click to rerun the code I get this error message: expresion is not a method.
I would apreciate any advice to solve this problem.
Thanks in advance.
Here is my code:
Imports System.IO.Path
Imports System.IO
Public Class Thor2_questions
Dim arrayfiles As IO.FileInfo
Public Sub Thor2_questions_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'define the directory to look for the files
Dim directory As New IO.DirectoryInfo("C:\Users\t727058\Desktop\VB\Sat quiz\Sat quiz\Thor 2 subsystem A questions and answers")
'define an array which is going to have files of type .txt from the directory
Dim arrayFiles = directory.GetFiles("*.txt")
'to randomize the index of the arrayfiles array
Dim randomtext As New Random
Dim index As Integer
index = randomtext.Next(arrayFiles.Length)
'this variable is going to content a single .txt file from the directory
Dim file As IO.FileInfo
'this variable is going to access/read the name of the txt file in the array
Dim FSR As StreamReader
'declare a string variable which is going to read the whole (to the end) .txt file
Dim filecontent As String
' ---------------------------------------------------------------------------------------------------------------------------------------------------
'This is the part for the questions and answer from a single .txt file!
For Each file In arrayFiles
file = arrayFiles(index)
'define FSR as new streamreader which contents the name of the .txt file in the array
FSR = New StreamReader(file.FullName)
'read the whole .txt file until the end and place the content in the string variable filecontent
filecontent = FSR.ReadToEnd
'close the reader in order to make place to the other .txt file?
FSR.Close()
'make an array of type string with 4 indexes for the one question and three answer
Dim QA(4) As String
'split the content of the filecontent variable by the ~ sign
QA = Split(filecontent, "~")
Try
'place the content of the .txt file in correct order in the labels of the form
QUESTION.Text = QA(0)
ANSWER1.Text = QA(1)
ANSWER2.Text = QA(2)
ANSWER3.Text = QA(3)
Catch ex As Exception
End Try
Next
End Sub
Public Sub next_button_Click(sender As Object, e As EventArgs) Handles next_button.Click
Call Me()
End Sub
End Class