I'm writing an application in vb.net 2008. It's basically a randomised image quiz. I have saved questions, answers and time taken to answer questions into 3 listboxes: listboz1, listbox2 and listbox3. I'm trying to add the content of all into a csv file. This is my code below which only saves the contents of one listbox to a txt file. How do I get a combination of all listboxes in the file with format (L1,L2,L3)? I alos want to add the user name and the date the test/ quiz was taken. Thank you :)
Code:
Public Class Form1
Dim intPic As Integer
Dim pickedImg As New List(Of Integer)
Dim rand As New Random
Dim StartTime As DateTime = Now
Dim ElapsedTime As TimeSpan
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Timer1.Interval = 6000
End Sub
Private Sub chooseImg()
Dim i As Integer = ImageList1.Images.Count
intPic = rand.Next(0, i)
If pickedImg.Count >= i Then 'if list count = max number of images, exit with message
'MessageBox.Show("End")
Button3.Enabled = False
Button4.Enabled = False
Button5.Enabled = False
Exit Sub
End If
If pickedImg.Contains(intPic) Then
chooseImg() 'if list contains intPic, choose new random
Else
pickedImg.Add(intPic)
ListBox1.Items.Add(intPic + "1".ToString) 'added for testing
End If
PictureBox1.Image = ImageList1.Images(intPic)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If pickedImg.Count < 1 Then 'if list count = less than 1 load image
chooseImg()
End If
Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
'chooseImg()
End Sub
Private Sub Button3_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Button3.MouseClick, Button4.MouseClick, Button5.MouseClick
Timer1.Stop()
ElapsedTime = Now().Subtract(StartTime)
ListBox3.Items.Add((ElapsedTime.Milliseconds).ToString)
If sender Is Button3 Then ListBox2.Items.Add("1")
If sender Is Button4 Then ListBox2.Items.Add("2")
If sender Is Button5 Then ListBox2.Items.Add("3")
chooseImg()
Timer1.Enabled = True
End Sub
Private Sub SaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveButton.Click
'WriteToTextFile()
Using SW As New IO.StreamWriter("C:\Users\Riz\Pant.txt", True)
For Each itm As String In Me.ListBox1.Items
SW.WriteLine(itm)
Next
End Using
MessageBox.Show("End")
SaveButton.Enabled = False
End Sub
End Class
Comment