Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Eunice

Eunice

Scheduled Pinned Locked Moved Visual Basic
helpquestiondata-structureslounge
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Eunice VB junior
    wrote on last edited by
    #1

    I have a problem on the below random codes. The codes are actually working. But sometime it just hang after clicked on the randomise button. (I suspect it kept looping at (while loop) to search for random number. Can it be??)Can anyone help me? Here are my codes. Private oQuestionCount As Integer = 5 Private sQuestionCount As Integer = 2 Dim tQuestion As Integer = ds.Tables("FilteredQuestion").Rows.Count Dim aSize As Integer If Me.cbQuesType.Text = "Obj" Then aSize = oQuestionCount Else aSize = sQuestionCount End If If tQuestion = 0 And tQuestion < aSize Then MessageBox.Show("The questions from the Question Bank is not enough") Me.Dispose() End If Dim rnd = New Random Dim irnd As Integer Dim arnd(aSize - 1) As Integer Dim aID(aSize - 1) As Integer Dim i As Integer Dim sID As String Dim iStudentCount As Integer Randomize() For i = 0 To aSize - 1 irnd = rnd.Next(0, tQuestion - 1) Do While Array.IndexOf(arnd, irnd) > -1 irnd = rnd.next(0, aSize - 1) Loop arnd(i) = irnd aID(i) = ds.Tables("FilteredQuestion").Rows(irnd)(0) If i = aSize - 1 Then sID = sID & aID(i) Else sID = sID & aID(i) & "," End If Next Thanks ....

    C 1 Reply Last reply
    0
    • E Eunice VB junior

      I have a problem on the below random codes. The codes are actually working. But sometime it just hang after clicked on the randomise button. (I suspect it kept looping at (while loop) to search for random number. Can it be??)Can anyone help me? Here are my codes. Private oQuestionCount As Integer = 5 Private sQuestionCount As Integer = 2 Dim tQuestion As Integer = ds.Tables("FilteredQuestion").Rows.Count Dim aSize As Integer If Me.cbQuesType.Text = "Obj" Then aSize = oQuestionCount Else aSize = sQuestionCount End If If tQuestion = 0 And tQuestion < aSize Then MessageBox.Show("The questions from the Question Bank is not enough") Me.Dispose() End If Dim rnd = New Random Dim irnd As Integer Dim arnd(aSize - 1) As Integer Dim aID(aSize - 1) As Integer Dim i As Integer Dim sID As String Dim iStudentCount As Integer Randomize() For i = 0 To aSize - 1 irnd = rnd.Next(0, tQuestion - 1) Do While Array.IndexOf(arnd, irnd) > -1 irnd = rnd.next(0, aSize - 1) Loop arnd(i) = irnd aID(i) = ds.Tables("FilteredQuestion").Rows(irnd)(0) If i = aSize - 1 Then sID = sID & aID(i) Else sID = sID & aID(i) & "," End If Next Thanks ....

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Your name is not an intelligent subject, please try to choose one that makes sense. It helps people know if they can help you. This looks like a mess. What are you trying to do ? Have you tried breaking into your code when it hangs to see what is going wrong ?

      Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      E 1 Reply Last reply
      0
      • C Christian Graus

        Your name is not an intelligent subject, please try to choose one that makes sense. It helps people know if they can help you. This looks like a mess. What are you trying to do ? Have you tried breaking into your code when it hangs to see what is going wrong ?

        Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        E Offline
        E Offline
        Eunice VB junior
        wrote on last edited by
        #3

        Hi Christian Graus, Thanks for the comment on the subject. I had changed it. Yes, i tried to break the code and found out that it kept looping in the (while loop) to search for numbers i guess. Actually what i'm trying to do is to retrieve random question from a table. This is a exam. paper program. So the student will login their ID to sit for exam. This program is to retrieve random question so that every student will not get the same quetion. This is my first time writing code for randomise. No idea what went wrong. Can you advice me? thanks in advance.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups