Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27569

Cant store text file information to structure and use RND functionon the structure.

$
0
0
I recently created this code, it is for a flash card quiz i am designing. I have a text file which i have put at the bottom of this post. The information from this text file needs to be brought into vb and then stored in my structure. From here i then need to randomize all the elements in the text file so each time you go onto the form it is a different part of the key word. For some reason I cannot seem to get this to work. Any help would be appreciated.

Here is the notepad file (txt):

cellulose
Tough substance that makes up the cell walls of green plants.
respiration
A chemical reaction that causes energy to be released from glucose.
haemoglobin
A substance which joins to oxygen and carries it round the body in blood.
ventilation
Breathing.
cartilage
Tough and smooth substance covering the ends of bones to protect them.
cytoplasm
Jelly-like part of a cell where chemical reactions happen.
nucleus
Controls what happens inside a cell.
alveoli
Tiny air sacs in the lungs.
amino acids
Produced when proteins are digested.
virus
The smallest type of microbe.
white blood cells
Can engulf bacteria or make antibodies.
photosynthesis
The process of turning carbon dioxide water and light into glucose and oxygen.
stomata
Small holes in the underside of a leaf.
vaccine
Dead or inactive forms of a microorganism.
fibre
A nutrient that cannot be digested.


It includes a key word and then on the next line the definition. I need to display 3 definitions at once and one keyword. All of these must be randomized.


Here is the code I have for this part of the program:

Public Class Quiz
Dim Lines() As String = System.IO.File.ReadAllLines("I:\Computer Science\Option B\JBrown2009\Mock Exam\component 1 scenario 4\Keywords.txt")
Dim seconds, minutes, hours As Integer
Private Sub btnBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBack.Click
'Open Start quiz page'
Me.Close()
Start_Quiz.Visible = True
End Sub

Private Sub Quiz_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Randomise Keyword At Top Of Form
Dim sKeywords(14) As String
Dim ValueChosen As New ArrayList
Dim iRnd As Integer
Dim iUpperBound As Integer = 14
Dim iLowerBound As Integer = 0

'Put structure elements into a array'
LKeywords.sCellulose = Lines(0)
LKeywords.sRespiration = Lines(2)
LKeywords.sHaemoglobin = Lines(4)
LKeywords.sVentilation = Lines(6)
LKeywords.sCartilage = Lines(8)
LKeywords.sCytoplasm = Lines(10)
LKeywords.sNucleus = Lines(12)
LKeywords.sAlveoli = Lines(14)
LKeywords.sAmino_Acids = Lines(16)
LKeywords.sVirus = Lines(18)
LKeywords.sWhite_Blood_Cells = Lines(20)
LKeywords.sPhotosynthesis = Lines(22)
LKeywords.sStomata = Lines(24)
LKeywords.sVaccine = Lines(26)
LKeywords.sFibre = Lines(28)

sKeywords(0) = LKeywords.sCellulose
sKeywords(1) = LKeywords.sRespiration
sKeywords(2) = LKeywords.sHaemoglobin
sKeywords(3) = LKeywords.sVentilation
sKeywords(4) = LKeywords.sCartilage
sKeywords(5) = LKeywords.sCytoplasm
sKeywords(6) = LKeywords.sNucleus
sKeywords(7) = LKeywords.sAlveoli
sKeywords(8) = LKeywords.sAmino_Acids
sKeywords(9) = LKeywords.sVirus
sKeywords(10) = LKeywords.sWhite_Blood_Cells
sKeywords(11) = LKeywords.sPhotosynthesis
sKeywords(12) = LKeywords.sStomata
sKeywords(13) = LKeywords.sVaccine
sKeywords(14) = LKeywords.sFibre

iRnd = CInt(Math.Floor((iUpperBound - iLowerBound + 1) * Rnd())) + iLowerBound
lblKeyword.Text = sKeywords(Val(iRnd))

Dim sDefinition(14) As String
Dim aValueChosen As New ArrayList

'Put structure elements into a array'
LDefinitions.sDefCellulose = Lines(1)
LDefinitions.sDefRespiration = Lines(3)
LDefinitions.sDefHaemoglobin = Lines(5)
LDefinitions.sDefVentilation = Lines(7)
LDefinitions.sDefCartilage = Lines(9)
LDefinitions.sDefCytoplasm = Lines(11)
LDefinitions.sDefNucleus = Lines(13)
LDefinitions.sDefAlveoli = Lines(15)
LDefinitions.sDefAmino_Acids = Lines(17)
LDefinitions.sDefVirus = Lines(19)
LDefinitions.sDefWhite_Blood_Cells = Lines(21)
LDefinitions.sDefPhotosynthesis = Lines(23)
LDefinitions.sDefStomata = Lines(25)
LDefinitions.sDefVaccine = Lines(27)
LDefinitions.sDefFibre = Lines(29)

sDefinition(0) = LDefinitions.sDefCellulose
sDefinition(1) = LDefinitions.sDefRespiration
sDefinition(2) = LDefinitions.sDefHaemoglobin
sDefinition(3) = LDefinitions.sDefVentilation
sDefinition(4) = LDefinitions.sDefCartilage
sDefinition(5) = LDefinitions.sDefCytoplasm
sDefinition(6) = LDefinitions.sDefNucleus
sDefinition(7) = LDefinitions.sDefAlveoli
sDefinition(8) = LDefinitions.sDefAmino_Acids
sDefinition(9) = LDefinitions.sDefVirus
sDefinition(10) = LDefinitions.sDefWhite_Blood_Cells
sDefinition(11) = LDefinitions.sDefPhotosynthesis
sDefinition(12) = LDefinitions.sDefStomata
sDefinition(13) = LDefinitions.sDefVaccine
sDefinition(14) = LDefinitions.sDefFibre

'Label will display random keyword'

lblA.Text = sDefinition(Val(iRnd)) 'Label will display random keyword'
lblB.Text = sDefinition(Val(iRnd)) 'Label will display random keyword'
lblC.Text = sDefinition(Val(iRnd)) 'Label will display random keyword'

Timer1.Interval = 1000
Timer1.Start()
End Sub

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If seconds = 60 Then
seconds = 0
minutes = minutes + 1
End If
If minutes = 60 Then
If seconds = 60 Then
seconds = 0
minutes = 0
hours = hours + 1
End If
End If
seconds = seconds + 1
txtTimer.Text = Format(hours, "00") & "." & Format(minutes, "00") & "." & Format(seconds, "00")
End Sub

Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
Timer1.Stop()
End Sub
End Class



Here is a copy of my module:
Module Module1
Public LDefinitions As Populate_Definitions_Structure 'Name Structure'
Public LKeywords As Populate_Keywords_Structure

'Structure for definitions from text file'
Structure Populate_Keywords_Structure
Public sCellulose As String
Public sRespiration As String
Public sHaemoglobin As String
Public sVentilation As String
Public sCartilage As String
Public sCytoplasm As String
Public sNucleus As String
Public sAlveoli As String
Public sAmino_Acids As String
Public sVirus As String
Public sWhite_Blood_Cells As String
Public sPhotosynthesis As String
Public sStomata As String
Public sVaccine As String
Public sFibre As String
End Structure

'Structure for Keywords from text file'
Structure Populate_Definitions_Structure
Public sDefCellulose As String
Public sDefRespiration As String
Public sDefHaemoglobin As String
Public sDefVentilation As String
Public sDefCartilage As String
Public sDefCytoplasm As String
Public sDefNucleus As String
Public sDefAlveoli As String
Public sDefAmino_Acids As String
Public sDefVirus As String
Public sDefWhite_Blood_Cells As String
Public sDefPhotosynthesis As String
Public sDefStomata As String
Public sDefVaccine As String
Public sDefFibre As String
End Structure

End Module

Viewing all articles
Browse latest Browse all 27569

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>