Results 1 to 4 of 4

Thread: Simple Quiz Application

  1. #1

    Thread Starter
    Addicted Member condonethis's Avatar
    Join Date
    Apr 2010
    Location
    TX
    Posts
    133

    Red face Simple Quiz Application

    Hello,

    Been a while away from code, but trying to take a stab at writing a little quiz app but my code looks like I am trying too hard and runing slow. Can anyone give me an idea of what I'm doing right, if anything and what I might can change to get it working? I'm tring to pick a random line from a text file, break that into strings split by "," and pick the first resultant string and put it into label A for Answer A, B for Answer B.... and not use the same entry twice, as well as not put the entry into the same Ans twice. I will have picture boxes that I want to fill from a folder titled exactly what the correct answer is, and their is no text, the user guesses based on the image displayed in the text boxes, kinda the way Rosetta Stone works.

    Code:
    Imports System
    Imports System.IO
    Imports System.IO.File
    
    Public Class Form1
    
        'Program Variables
        Dim width As String = My.Computer.Screen.WorkingArea.Width
        Dim height As String = My.Computer.Screen.WorkingArea.Height
        Dim h As String = AppDomain.CurrentDomain.BaseDirectory.ToString
        Dim flist As String = File.ReadAllText(h & "flist.txt")
        Dim priArray() As String = flist.Split(Environment.NewLine)
    
        'Mushroom Variables
        Dim chose As String
        Dim pic As String = AppDomain.CurrentDomain.BaseDirectory & chose & "\"
    
    
        'Functions
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.width = width - (width / 100 * 20)
            Me.height = height - (height / 100 * 20)
            Me.CenterToScreen()
    
    
        End Sub
    
    
        Public Sub FPickShroom()
            Dim got(4) As String
            Dim gotA(4) As String
            Dim t As Integer = 5
            Dim usedletters As String = "5"
            Dim usedmush As String = "5"
            Dim melike As String = "5"
            Dim ListLines As String() = {"A", "B", "C", "D", "E"}
    
            ''Pick Mushrooms Randomly
            Do Until usedletters.Contains(melike) = False
                Dim Rand1 As New Random()
                Dim Index1 As Integer = Rand1.Next(0, priArray.Length - 1)
                Dim gethere() As String = priArray(Index1).Split(",")
                melike = gethere(0)
            Loop
            usedmush &= melike
            got(0) = melike
            melike = "5"
    
            Do Until usedletters.Contains(melike) = False
                Dim Rand1 As New Random()
                Dim Index1 As Integer = Rand1.Next(0, priArray.Length - 1)
                Dim gethere() As String = priArray(Index1).Split(",")
                melike = gethere(0)
            Loop
            usedmush &= melike
            got(1) = melike
            melike = "5"
    
            Do Until usedletters.Contains(melike) = False
                Dim Rand1 As New Random()
                Dim Index1 As Integer = Rand1.Next(0, priArray.Length - 1)
                Dim gethere() As String = priArray(Index1).Split(",")
                melike = gethere(0)
            Loop
            usedmush &= melike
            got(2) = melike
            melike = "5"
    
            Do Until usedletters.Contains(melike) = False
                Dim Rand1 As New Random()
                Dim Index1 As Integer = Rand1.Next(0, priArray.Length - 1)
                Dim gethere() As String = priArray(Index1).Split(",")
                melike = gethere(0)
            Loop
            usedmush &= melike
            got(3) = melike
            melike = "5"
    
            Do Until usedletters.Contains(melike) = False
                Dim Rand1 As New Random()
                Dim Index1 As Integer = Rand1.Next(0, priArray.Length - 1)
                Dim gethere() As String = priArray(Index1).Split(",")
                melike = gethere(0)
            Loop
            usedmush &= melike
            got(4) = melike
            melike = "5"
    
            ''Pick Letters Randomly
            Do Until usedmush.Contains(melike) = False
                Dim Rand1 As New Random()
                Dim Index1 As Integer = Rand1.Next(0, ListLines.Length - 1)
                melike = ListLines(Index1)
            Loop
            usedletters &= melike
            gotA(0) = melike
            melike = "5"
    
            Do Until usedmush.Contains(melike) = False
                Dim Rand1 As New Random()
                Dim Index1 As Integer = Rand1.Next(0, ListLines.Length - 1)
                melike = ListLines(Index1)
            Loop
            usedletters &= melike
            gotA(1) = melike
            melike = "5"
    
            Do Until usedmush.Contains(melike) = False
                Dim Rand1 As New Random()
                Dim Index1 As Integer = Rand1.Next(0, ListLines.Length - 1)
                melike = ListLines(Index1)
            Loop
            usedletters &= melike
            gotA(2) = melike
            melike = "5"
    
            Do Until usedmush.Contains(melike) = False
                Dim Rand1 As New Random()
                Dim Index1 As Integer = Rand1.Next(0, ListLines.Length - 1)
                melike = ListLines(Index1)
            Loop
            usedletters &= melike
            gotA(3) = melike
            melike = "5"
    
            Do Until usedmush.Contains(melike) = False
                Dim Rand1 As New Random()
                Dim Index1 As Integer = Rand1.Next(0, ListLines.Length - 1)
                melike = ListLines(Index1)
            Loop
            usedletters &= melike
            gotA(4) = melike
            melike = "5"
    
    
    
            If gotA(0) = "A" Then
                AnsA.Text = got(0)
            End If
            If gotA(0) = "B" Then
                AnsB.Text = got(0)
            End If
            If gotA(0) = "C" Then
                AnsC.Text = got(0)
            End If
            If gotA(0) = "D" Then
                AnsD.Text = got(0)
            End If
            If gotA(0) = "E" Then
                AnsE.Text = got(0)
            End If
            If gotA(1) = "A" Then
                AnsA.Text = got(1)
            End If
            If gotA(1) = "B" Then
                AnsB.Text = got(1)
            End If
            If gotA(1) = "C" Then
                AnsC.Text = got(1)
            End If
            If gotA(1) = "D" Then
                AnsD.Text = got(1)
            End If
            If gotA(1) = "E" Then
                AnsE.Text = got(1)
            End If
            If gotA(2) = "A" Then
                AnsA.Text = got(2)
            End If
            If gotA(2) = "B" Then
                AnsB.Text = got(2)
            End If
            If gotA(2) = "C" Then
                AnsC.Text = got(2)
            End If
            If gotA(2) = "D" Then
                AnsD.Text = got(2)
            End If
            If gotA(2) = "E" Then
                AnsE.Text = got(2)
            End If
            If gotA(3) = "A" Then
                AnsA.Text = got(3)
            End If
            If gotA(3) = "B" Then
                AnsB.Text = got(3)
            End If
            If gotA(3) = "C" Then
                AnsC.Text = got(3)
            End If
            If gotA(3) = "D" Then
                AnsD.Text = got(3)
            End If
            If gotA(3) = "E" Then
                AnsE.Text = got(3)
            End If
            If gotA(4) = "A" Then
                AnsA.Text = got(4)
            End If
            If gotA(4) = "B" Then
                AnsB.Text = got(4)
            End If
            If gotA(4) = "C" Then
                AnsC.Text = got(4)
            End If
            If gotA(4) = "D" Then
                AnsD.Text = got(4)
            End If
            If gotA(4) = "E" Then
                AnsE.Text = got(4)
            End If
    
    
    
            '(Latin Name, Common Name)
    
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            FPickShroom()
        End Sub
    End Class


    Thank you for you help!

    Chad

  2. #2

    Thread Starter
    Addicted Member condonethis's Avatar
    Join Date
    Apr 2010
    Location
    TX
    Posts
    133

    Re: Simple Quiz Application

    Name:  concept.jpg
Views: 833
Size:  28.4 KBTrying something different, equally befuddled but much shorter. Having issues trying to find out how to store String into Array piece by piece.
    Code:
     Public Sub TRIAL2()
            Dim T As Integer = 0
            Dim M As String = 0
            Dim st As ArrayList
            Dim used As String = ""
    
    
            Do Until T = 4
                Dim Rand1 As New Random()
                Dim Index1 As Integer = Rand1.Next(0, priArray.Length - 1)
                Dim gethere() As String = priArray(Index1).Split(",")
                st.Add(gethere(0))
                T = T + 1
            Loop
    
            Do Until M = 4
                Me.Controls("Ans" & M).Text = st(M).ToString
                M = M + 1
            Loop
    
    
        End Sub
    Thanks!
    Last edited by condonethis; Oct 31st, 2013 at 03:46 AM. Reason: pic

  3. #3

    Thread Starter
    Addicted Member condonethis's Avatar
    Join Date
    Apr 2010
    Location
    TX
    Posts
    133

    Re: Simple Quiz Application

    I got it kinda altered to something much more approachable but I'm seeing difficulties rendering the strings??Name:  why.jpg
Views: 899
Size:  43.6 KB

    Code:
        Public Sub TRIAL2()
    
            'Dim a As Integer = 1
    
            'Do Until a = 5
            '    Me.Controls("Ans1" & (a)).Visible = False
            '    a = a + 1
            'Loop
            'a = 5
    
            Ans1.Visible = False
            Ans2.Visible = False
            Ans3.Visible = False
            Ans4.Visible = False
            Ans5.Visible = False
    
            Dim T As Integer = 0
            Dim M As String = 0
            Dim list As New ArrayList
            Dim used As String = ""
    
    
            Dim Rand1 As New Random()
            Do Until T = 4
    
                Dim Index1 As Integer = Rand1.Next(0, priArray.Length - 1)
                Dim gethere() As String = priArray(Index1).Split(Environment.NewLine)
                list.Add(gethere(0).ToString)
                T = T + 1
            Loop
    
            Ans1.Text = list(0)
            Ans2.Text = list(1)
            Ans3.Text = list(2)
            Ans4.Text = list(3)
            ' Ans5.Text = list(4)
    
    
            ' Create an ArrayList and add three strings to it.
    
    
            Do Until M = 4
                'Me.Controls("Ans" & M).Text = st(M).ToString
                M = M + 1
            Loop
    
            'Do Until a = 5
            '    Me.Controls("Ans1" & (a)).Visible = True
            '    a = a + 1
            'Loop
            'a = 5
            Ans1.Visible = True
            Ans2.Visible = True
            Ans3.Visible = True
            Ans4.Visible = True
            Ans5.Visible = True
        End Sub

  4. #4

    Thread Starter
    Addicted Member condonethis's Avatar
    Join Date
    Apr 2010
    Location
    TX
    Posts
    133

    Resolved Re: Simple Quiz Application

    I figured everything out. If anyone is interested, I present a simple quiz application.

    Sometimes you give yourself better advice than you receive.

    DoceusFungii (Solution on Google Drive due to images size)


    Quiz App
    vb.net Code:
    1. Imports System
    2. Imports System.IO
    3. Imports System.Collections
    4. Imports System.IO.File
    5.  
    6. Public Class Form1
    7.  
    8.     'Program Variables
    9.     Dim mywidth As String = My.Computer.Screen.WorkingArea.Width
    10.     Dim myheight As String = My.Computer.Screen.WorkingArea.Height
    11.     Dim h As String = AppDomain.CurrentDomain.BaseDirectory.ToString
    12.     Dim flist As String = File.ReadAllText(h & "flist.txt")
    13.     Dim priArray() As String = flist.Split(Environment.NewLine)
    14.     Dim ad As String = AppDomain.CurrentDomain.BaseDirectory
    15.     Dim thefile1 As String
    16.     Dim thefile2 As String
    17.     Dim thefile3 As String
    18.     Dim spore As String
    19.     Dim ispore As Boolean
    20.     Dim score As String = 0
    21.  
    22.     'Mushroom Variables
    23.     Dim chose As String = Nothing
    24.     Public Sub tryans()
    25.         If LstAns.SelectedIndex > -1 Then
    26.             If LstAns.SelectedItem.ToString.Trim() = LblAns.Text.Trim() Then
    27.                 score = score + 10
    28.                 'MsgBox("AWESOME YOU GOT IT RIGHT!")
    29.                 LblScore.Text = score
    30.                 Dim curline As String = File.ReadAllLines(ad & "flist.txt").FirstOrDefault(Function(x) x.Contains(chose.Trim()))
    31.                 Dim chArray As String() = curline.Split(",")
    32.                 MsgBox(chArray(0) & " " & chArray(1))
    33.                 LstAns.Text = chArray(1)
    34.                 FindMush()
    35.             Else
    36.                 'MsgBox("Woops, try again!")
    37.                 score = score - 7
    38.                 For i As Integer = 0 To LstAns.SelectedIndices.Count - 1
    39.                     LstAns.Items.RemoveAt(LstAns.SelectedIndex)
    40.                 Next
    41.                 LblScore.Text = score
    42.             End If
    43.         End If
    44.     End Sub
    45.     'Functions
    46.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    47.         Me.MaximizeBox = False
    48.         Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedToolWindow
    49.         LblAns.Hide()
    50.         Me.CenterToScreen()
    51.         PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
    52.         PictureBox2.SizeMode = PictureBoxSizeMode.StretchImage
    53.         PictureBox3.SizeMode = PictureBoxSizeMode.StretchImage
    54.         FindMush()
    55.     End Sub
    56.  
    57.     Public Sub FindMush()
    58.  
    59.         Try
    60.             PictureBox1.Image.Dispose()
    61.             PictureBox2.Image.Dispose()
    62.             PictureBox3.Image.Dispose()
    63.         Catch ex As Exception
    64.  
    65.         End Try
    66.  
    67.         Dim T As Integer = 0
    68.         Dim M As String = 0
    69.         Dim list As New ArrayList
    70.         Dim used As String = ""
    71.         Dim pic As Integer = 0
    72.         Dim Rand1 As New Random()
    73.         chose = Nothing
    74.  
    75.         Do Until T = 5
    76.             Dim Index1 As Integer = Rand1.Next(0, priArray.Length - 1)
    77.             Dim gethere() As String = priArray(Index1).Split(Environment.NewLine)
    78.             Dim nocommon() As String = gethere(0).Split(",")
    79.             If used.Contains(nocommon(0).ToString) = False Then
    80.                 list.Add(nocommon(0).ToString)
    81.                 used &= nocommon(0).ToString & ","
    82.                 T = T + 1
    83.                 pic = pic + 1
    84.             End If
    85.         Loop
    86.  
    87.         Dim posans() As String = used.Split(",")
    88.         Dim RandChoose As New Random()
    89.         Dim MyPic As Integer = RandChoose.Next(0, posans.Length - 1)
    90.         LblAns.Text = posans(MyPic)
    91.         chose = LblAns.Text
    92.  
    93.         LstAns.Items.Clear()
    94.         LstAns.Items.Add(list(0).ToString)
    95.         LstAns.Items.Add(list(1).ToString)
    96.         LstAns.Items.Add(list(2).ToString)
    97.         LstAns.Items.Add(list(3).ToString)
    98.         LstAns.Items.Add(list(4).ToString)
    99.  
    100.         If ispore = True Then
    101.             thefile1 = ad & LblAns.Text.Trim() & "\mush1.jpg"
    102.             thefile2 = ad & LblAns.Text.Trim() & "\mush2.jpg"
    103.         Else
    104.             thefile1 = ad & LblAns.Text.Trim() & "\mush2.jpg"
    105.             thefile2 = ad & LblAns.Text.Trim() & "\mush1.jpg"
    106.         End If
    107.         thefile3 = ad & LblAns.Text.Trim() & "\mush3.jpg"
    108.         spore = ad & LblAns.Text.Trim() & "\spore1.jpg"
    109.         If File.Exists(thefile1) = True Then
    110.             Try
    111.                 Me.PictureBox1.Image = Bitmap.FromFile(thefile1.ToString)
    112.             Catch ex As Exception
    113.                 MsgBox(ex.Message)
    114.             End Try
    115.             Try
    116.                 Me.PictureBox2.Image = Bitmap.FromFile(thefile2.ToString)
    117.             Catch ex As Exception
    118.                 MsgBox(ex.Message)
    119.             End Try
    120.             If File.Exists(spore) = True Then
    121.                 ispore = True
    122.                 Try
    123.                     Me.PictureBox3.Image = Bitmap.FromFile(spore)
    124.                 Catch ex As Exception
    125.                     MsgBox(ex.Message)
    126.                 End Try
    127.  
    128.             Else
    129.                 Try
    130.                     Me.PictureBox3.Image = Bitmap.FromFile(thefile3)
    131.                 Catch ex As Exception
    132.                     MsgBox(ex.Message)
    133.                 End Try
    134.                 ispore = False
    135.             End If
    136.         Else
    137.             Me.PictureBox1.Image = Bitmap.FromFile(ad & "notdone.jpg")
    138.         End If
    139.     End Sub
    140.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnPick.Click
    141.         FindMush()
    142.     End Sub
    143.  
    144.     Private Sub BtnFinalAns_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnFinalAns.Click
    145.         tryans()
    146.     End Sub
    147.  
    148.     Private Sub LstAns_DoubleClicked(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LstAns.DoubleClick
    149.         tryans()
    150.     End Sub
    151.  
    152.     Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
    153.         Dim todo As String = Chr(34) & "C:\Program Files\Windows Photo Viewer\PhotoViewer.dll" & Chr(34) & "," & Chr(34) & thefile1 & Chr(34)
    154.         Windows.Forms.Clipboard.SetText(todo)
    155.         Process.Start("C:\Windows\explorer.exe", thefile1)
    156.     End Sub
    157.  
    158.     Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click
    159.         Process.Start("C:\Windows\explorer.exe", thefile2)
    160.     End Sub
    161.  
    162.     Private Sub PictureBox3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox3.Click
    163.         If ispore = True Then
    164.             Process.Start("C:\Windows\explorer.exe", spore)
    165.         Else
    166.             Process.Start("C:\Windows\explorer.exe", thefile3)
    167.         End If
    168.     End Sub
    169.  
    170.  
    171.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    172.         FindMush()
    173.         Timer1.Enabled = False
    174.     End Sub
    175.  
    176.     Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
    177.         AddNew.Show()
    178.     End Sub
    179. End Class


    Add Stuff
    vb.net Code:
    1. Imports System
    2. Imports System.IO
    3. Imports System.Collections
    4. Imports System.IO.File
    5.  
    6. Public Class AddNew
    7.     Dim h As String = AppDomain.CurrentDomain.BaseDirectory.ToString
    8.     Dim dfile As String = h & "flist.txt"
    9.     Dim flist As String = File.ReadAllText(dfile)
    10.  
    11.     Public Sub doupdate()
    12.         Dim pcdir As String = h & TxtLatin.Text & "\"
    13.         If Directory.Exists(pcdir) = False Then
    14.             Directory.CreateDirectory(pcdir)
    15.         End If
    16.         flist &= Environment.NewLine & TxtLatin.Text & "," & TxtCommon.Text & "," & TxtEdibility.Text & "," & TxtSummary.Text & "," & TxtLink.Text
    17.         File.WriteAllText(dfile, flist)
    18.         Try
    19.             My.Computer.Network.DownloadFile(TxtImg1.Text, pcdir & "mush1.jpg")
    20.         Catch ex As Exception
    21.         End Try
    22.         Try
    23.             My.Computer.Network.DownloadFile(TxtImg2.Text, pcdir & "mush2.jpg")
    24.         Catch ex As Exception
    25.         End Try
    26.         Try
    27.             My.Computer.Network.DownloadFile(TxtImg3.Text, pcdir & "mush3.jpg")
    28.         Catch ex As Exception
    29.         End Try
    30.         TxtCommon.Clear()
    31.         TxtLatin.Clear()
    32.         TxtEdibility.Clear()
    33.         TxtSummary.Clear()
    34.         TxtLink.Clear()
    35.         TxtImg1.Clear()
    36.         TxtImg2.Clear()
    37.         TxtImg3.Clear()
    38.     End Sub
    39.  
    40.     Private Sub AddNew_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    41.         Me.TopMost = True
    42.         Me.Opacity = 0.75
    43.         Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedToolWindow
    44.     End Sub
    45.  
    46.     Private Sub BtnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAdd.Click
    47.         Form1.Close()
    48.         doupdate()
    49.         Form1.Show()
    50.  
    51.     End Sub
    52.  
    53.     Private Sub TxtImg1_DubClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtImg1.DoubleClick
    54.         TxtImg1.Text = Windows.Forms.Clipboard.GetText
    55.     End Sub
    56.  
    57.     Private Sub TxtImg2_DubClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtImg2.DoubleClick
    58.         TxtImg2.Text = Windows.Forms.Clipboard.GetText
    59.     End Sub
    60.  
    61.     Private Sub TxtImg3_DubClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtImg3.DoubleClick
    62.         TxtImg3.Text = Windows.Forms.Clipboard.GetText
    63.     End Sub
    64.  
    65.     Private Sub TxtLatin_DubClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtLatin.DoubleClick
    66.         TxtImg3.Text = Windows.Forms.Clipboard.GetText
    67.     End Sub
    68.     Private Sub TxtCommon_DubClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtCommon.DoubleClick
    69.         TxtImg3.Text = Windows.Forms.Clipboard.GetText
    70.     End Sub
    71.     Private Sub TxtEdibility_DubClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtEdibility.DoubleClick
    72.         TxtImg3.Text = Windows.Forms.Clipboard.GetText
    73.     End Sub
    74.     Private Sub TxtSummary_DubClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtSummary.DoubleClick
    75.         TxtSummary.Text = Windows.Forms.Clipboard.GetText
    76.     End Sub
    77.     Private Sub TxtLink_DubClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtLink.DoubleClick
    78.         TxtLink.Text = Windows.Forms.Clipboard.GetText
    79.     End Sub
    80. End Class

    Hope this helps someone out :-)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width