Grinding halt in visual basic (Tag problem)

[b][red]This message was edited by Aztech at 2005-12-31 12:34:58[/red][/b][hr]
Someone Heeeelp!!! I have been stuck now for some time on the preceding problem. Actaully I have three visual basic programming questions, but the first has been haunting me now for about a year. Progress on the program I am writing has come to a grinding halt. I am stuck and I know this is not that tough of a problem but have been unsucessful in finding any examples or relevant info. I am so desperatly hoping that someone can enlighten me or show me how to address the problems outlined below. I am running visual basic 5/6

Q#1. I have set up a simple flat file system in which a pool of files reside. When prompted by the user the program randomly selects a file and presents it on screen. When the user hits the command button labled "Next file" the program returns the current file and randomly selects a new file from the pool. My problem is.... how do I tag the current file so that it will not be selected again. Because it goes back into the pool, and as the questions are randomly selected, the same file tends to come up repeatedly. Also do I need to set up some sort of counter such that when the final "untaged" file has been chosen, a message box pops up notifing the user that all files in the data base have been viewed. And how do I reset all the "taged" files back to "untaged" so that the user or another user can run the program.

Q#2. The second question that I have is in regards to sound. Having been presented with a file the user is prompted to make a response and if the response is correct then an image is displaid on screen, (Hands raised for correct and head down and explosion cloud for incorrect.)How can I add a sound file appropriate to the images presented?

Q#3. Is it possible to attach a file folder to the program where I can store all the images and "sounds" that the program uses. Curently the images utilized by the program are stored all over the computer in different places.






Comments

  • [deleted]

    : Q#1. I have set up a simple flat file system in which a pool of files reside. When prompted by the user the program randomly selects a file and presents it on screen. When the user hits the command button labled "Next file" the program returns the current file and randomly selects a new file from the pool. My problem is.... how do I tag the current file so that it will not be selected again. Because it goes back into the pool, and as the questions are randomly selected, the same file tends to come up repeatedly. Also do I need to set up some sort of counter such that when the final "untaged" file has been chosen, a message box pops up notifing the user that all files in the data base have been viewed. And how do I reset all the "taged" files back to "untaged" so that the user or another user can run the program.

    You can solve this problem by using array.

    Dim isTaged(fileCount) as Boolean

    Sub ResetTag ()
    For i=0 To Ubound(isTaged)
    isTaged(i) = False
    Next
    End Sub

    'Get Index of Untaged File
    Function RandomTag() As Integer
    Dim rndNbr as Integer
    RandomTag = 0
    Randomize
    Do
    rndNbr = CInt(Rnd * fileCount + 1)
    If Not isTaged(rndNbr) Then
    isTaged(rndNbr) = True
    RandomTag = rndNbr
    Exit Do
    End If
    Loop
    End Function

    'Checking All isTaged
    Function isTagedAll () As Boolean
    isTagedAll = False
    For i=0 To Ubound(isTaged)
    If Not isTaged(i) Then Exit Function
    Next
    isTagedAll = True
    End Function

    You can put your list of files in an array or by using listbox control.
    Do isTagedAll function before you do RandomTag function, because this
    function can make your computer hang when all files is tagged.

    Good Luck n have a nice try !

    Regards,


    Sarasan


    [deleted]

  • :: Q#2. The second question that I have is in regards to sound. Having been presented with a file the user is prompted to make a response and if the response is correct then an image is displaid on screen, (Hands raised for correct and head down and explosion cloud for incorrect.)How can I add a sound file appropriate to the images presented?

    To play sound you can use windows API sndPlaySound function


    : Q#3. Is it possible to attach a file folder to the program where I can store all the images and "sounds" that the program uses. Curently the images utilized by the program are stored all over the computer in different places.

    If your images and sounds file folder is under your program folder you can use App.Path property.

    imgFolder = App.Path & "images"
    sndFolder = App.Path & "sounds"

    Regards,


    Sarasan

    ps: sorry if my english is not good enough.
  • : [deleted]
    :
    : : Q#1. I have set up a sequential file system in which a pool of files reside. When prompted by the user the program randomly selects a file and presents it on screen. When the user hits the command button labled "Next file" the program returns the current file and randomly selects a new file from the pool. My problem is.... how do I tag the current file so that it will not be selected again. Because it goes back into the pool, and as the questions are randomly selected, the same file tends to come up repeatedly. Also do I need to set up some sort of counter such that when the final "untaged" file has been chosen, a message box pops up notifing the user that all files in the data base have been viewed. And how do I reset all the "taged" files back to "untaged" so that the user or another user can run the program.
    :
    : You can solve this problem by using array.
    :
    : Dim isTaged(fileCount) as Boolean
    :
    : Sub ResetTag ()
    : For i=0 To Ubound(isTaged)
    : isTaged(i) = False
    : Next
    : End Sub
    :
    : 'Get Index of Untaged File
    : Function RandomTag() As Integer
    : Dim rndNbr as Integer
    : RandomTag = 0
    : Randomize
    : Do
    : rndNbr = CInt(Rnd * fileCount + 1)
    : If Not isTaged(rndNbr) Then
    : isTaged(rndNbr) = True
    : RandomTag = rndNbr
    : Exit Do
    : End If
    : Loop
    : End Function
    :
    : 'Checking All isTaged
    : Function isTagedAll () As Boolean
    : isTagedAll = False
    : For i=0 To Ubound(isTaged)
    : If Not isTaged(i) Then Exit Function
    : Next
    : isTagedAll = True
    : End Function
    :
    : You can put your list of files in an array or by using listbox control.
    : Do isTagedAll function before you do RandomTag function, because this
    : function can make your computer hang when all files is tagged.
    :
    : Good Luck n have a nice try !
    :
    : Regards,
    :
    :
    : Sarasan
    :
    :
    : [deleted]
    :
    : Hello... I got you e-mail address from programers Haven You had assisted a fellow programer with a Quiz programing problem. I don't know how old the response was or if you still program but I thought I would try. I have been stuck now for some time on the preceding problem. Actaully I have three visual basic programming questions. Progress on the program I am writing has come to a grinding halt. I am stuck and I know this is not that tough of a problem but have been unsucessful in finding any examples or relevant info. I am so desperatly hoping that you can enlighten me or show me how to address the problems outlined below. I am running visual basic 5/6

    Q#1. I have set up a simple sequential file system in which a pool of files reside. When prompted by the user the program randomly selects a file and presents it on screen. When the user hits the command button labled "Next file" the program returns the current file and randomly selects a new file from the pool. My problem is.... how do I tag the current file so that it will not be selected again. Because it goes back into the pool, and as the questions are randomly selected, the same file tends to come up repeatedly. Also do I need to set up some sort of counter such that when the final "untaged" file has been chosen, a message box pops up notifing the user that all files in the data base have been viewed. And how do I reset all the "taged" files back to "untaged" so that the user or another user can run the program.

    Q#2. The second question that I have is in regards to sound. Having been presented with a file the user is prompted to make a response and if the response is correct then an image is displaid on screen, (Hands raised for correct and head down and explosion cloud for incorrect.)How can I add a sound file appropriate to the images presented?

    Q#3. Is it possible to attach a file folder to the program where I can store all the images and "sounds" that the program uses. Curently the images utilized by the program are stored all over the computer in different places.

    Here is the code for the user screen....I know Iknow it is the worst/slopiest most hideious code anyone has ever laid eyes on but it works for now and as soon as I can solve these last three problems I am going to rewrite with much tighter code. I hope you ca help. My name is Richard and I can be reached at aztech@shaw.ca

    Option Explicit
    Dim Person As PersonInfo
    Dim FileNum As Integer
    Dim RecordLen As Long
    Dim CurrentRecord As Long
    Dim LastRecord As Long
    Dim Questiontype As String * 2
    Dim Rite As Integer
    Dim Wrong As Integer
    Dim Kount As Integer
    Dim Skip As Integer

    Private Sub cmdAns_Click(Index As Integer)
    'As soon as the user has made a choice; either A,B,C,D or T or F,
    'disable the other choices.
    lblComments.Visible = True
    lblComment.Visible = True
    lblComment.BackStyle = 0
    If cmdAns(0) Then
    cmdAns(1).Enabled = False
    cmdAns(2).Enabled = False
    cmdAns(3).Enabled = False
    ElseIf cmdAns(1) Then
    cmdAns(0).Enabled = False
    cmdAns(2).Enabled = False
    cmdAns(3).Enabled = False
    ElseIf cmdAns(2) Then
    cmdAns(0).Enabled = False
    cmdAns(1).Enabled = False
    cmdAns(3).Enabled = False
    ElseIf cmdAns(3) Then
    cmdAns(0).Enabled = False
    cmdAns(1).Enabled = False
    cmdAns(2).Enabled = False
    ElseIf cmdAns(4) Then
    cmdAns(5).Enabled = False
    ElseIf cmdAns(5) Then
    cmdAns(4).Enabled = False
    End If
    'display and compare user answer with the correct answer.
    lblAnswer.Caption = cmdAns(Index).Caption 'User answer
    lblHope.Caption = Person.Phone 'correct answer is person.phone
    'If the answer the user has entered matches the correct answer
    'in the database then play Music and display "Yes Well Done"
    'If however the user answer does not match the answer in the database
    'then play music and display "Wrong Answer".
    If lblAnswer.Caption = UCase(Trim(lblHope.Caption)) Then
    Beep
    Highlite
    Image1.Visible = True
    Rite = Rite + 1
    lblRite.Caption = Rite
    cmdAns(Index).Enabled = False
    lblResult.Caption = "Well Done"
    Else
    Beep
    Image2.Visible = True
    Wrong = Wrong + 1
    lblWrong.Caption = Wrong
    cmdAns(Index).Enabled = False
    lblResult.Caption = "Wrong Answer"
    End If

    If Questiontype = "TM" Then
    txtTerm.SetFocus
    Else
    cmdQuest.SetFocus
    End If

    End Sub
    Private Sub Highlite()
    'Shade the wrong answer selections,(darker color) thus making the correct
    'answer selection more visible.
    If UCase(Trim(lblAnswer.Caption)) = "A" Then
    lblAnswer2.ForeColor = QBColor(6)
    lblAnswer3.ForeColor = QBColor(6)
    lblAnswer4.ForeColor = QBColor(6)
    ElseIf UCase(Trim(lblAnswer.Caption)) = "B" Then
    lblAnswer1.ForeColor = QBColor(6)
    lblAnswer3.ForeColor = QBColor(6)
    lblAnswer4.ForeColor = QBColor(6)
    ElseIf UCase(Trim(lblAnswer.Caption)) = "C" Then
    lblAnswer2.ForeColor = QBColor(6)
    lblAnswer1.ForeColor = QBColor(6)
    lblAnswer2.ForeColor = QBColor(6)
    lblAnswer4.ForeColor = QBColor(6)
    ElseIf UCase(Trim(lblAnswer.Caption)) = "D" Then
    lblAnswer2.ForeColor = QBColor(6)
    lblAnswer1.ForeColor = QBColor(6)
    lblAnswer3.ForeColor = QBColor(6)
    lblAnswer2.ForeColor = QBColor(6)
    ElseIf UCase(Trim(lblAnswer.Caption)) = "T" Then
    lblAnswer3.ForeColor = QBColor(6)
    ElseIf UCase(Trim(lblAnswer.Caption)) = "F" Then
    lblAnswer1.ForeColor = QBColor(6)
    End If

    End Sub
    Private Sub AnsIndex()
    'Enabled all answer choices.
    cmdAns(0).Enabled = True
    cmdAns(1).Enabled = True
    cmdAns(2).Enabled = True
    cmdAns(3).Enabled = True
    cmdAns(4).Enabled = True
    cmdAns(5).Enabled = True
    End Sub
    Private Sub cmdExit_Click()
    'Unload current program
    Unload Me
    End Sub
    Private Sub cmdPrevious_Click()
    Kount = Kount - 1
    AnsIndex
    'Make sure Result, Answer, and Hope captions are empty.
    EmptyFour
    'Make sure all answer indicators are not visible.
    AnswerIndicators
    'If the current record is not the first record,
    'then save the current record and skip one record backwards.
    If CurrentRecord = 1 Or Kount = 0 Then
    cmdPrevious.Visible = False
    Beep
    MsgBox "Beginning of File Encountered!", 48
    cmdQuest.Visible = True
    QuestionMarker
    Else
    SaveCurrentRecord
    CurrentRecord = CurrentRecord - 1
    ShowCurrentRecord
    End If
    End Sub
    Private Sub cmdQuest_Click()
    'CmdQuest is "next question button"
    'Set counter to 0: Counter keeps track of number of questions addressed
    Kount = Kount + 1
    'If user skips a question then record number of skipped questions in lableskip.
    cmdQuest.BackColor = QBColor(2)
    If lblResult.Caption = "" Then
    Skip = Skip + 1
    lblskip.Caption = Skip
    End If
    'Set focus on "Next Question" command button.
    cmdQuest.Caption = "Next Question"
    'Set all the answer indexes to true.
    AnsIndex
    'Make sure Result, Answer, Hope, and Term captions are
    'empty of all text etc.
    EmptyFour
    'Make sure the "Next Question" command button is visible.
    cmdQuest.Visible = True
    'Randomly select a question from the data base
    Random
    'If the last record in the datbase file hase been reached then
    'display message box indicating so.
    If CurrentRecord < 1 Then
    cmdPrevious.Visible = False
    Storage
    Else
    cmdPrevious.Visible = True
    End If
    'Make sure all answer indicators are not visible.
    AnswerIndicators
    'If the current record is not the first record,
    'then save the current record and skip one record forwards.
    If CurrentRecord = LastRecord Or Kount = LastRecord Then
    'Beep
    'MsgBox "End of File Encountered!", 48
    QuestionMarker
    Else
    SaveCurrentRecord
    CurrentRecord = CurrentRecord + 1
    ShowCurrentRecord
    End If
    lblComment.Visible = False
    lblComments.Visible = False
    End Sub
    Private Sub cmdTerm_Click()
    Dim counter As Integer
    lblAnswer.Caption = txtTerm.Text
    lblHope.Caption = Person.Phone
    'If the answer the user entered matches the correct answer
    'in the database(Person.Phone) then play Music and display
    '"Yes Well Done". If however the user's answer does
    'not match the answer in the database then play different music and
    'display "Wrong Answer".
    If UCase(Trim(txtTerm.Text)) = UCase(Trim(lblHope.Caption)) Then
    Beep
    txtTerm.BackColor = QBColor(14)
    Image1.Visible = True
    Rite = Rite + 1
    lblRite.Caption = Rite
    lblResult.Caption = "Well Done"
    Else
    Beep
    Image2.Visible = True
    Wrong = Wrong + 1
    lblWrong.Caption = Wrong
    lblResult.Caption = "Wrong Answer"
    End If
    'Make sure the terminolgy command button(cmdTerm) is not visible
    'and make sure the Next Question (cmdQuest) button is visible.
    cmdTerm.Visible = False
    cmdQuest.Visible = True
    lblComments.Visible = False
    lblComment.Visible = False
    lblComment.BackStyle = 0
    End Sub
    Private Sub Form_Load()
    'Make the backstyle of those items that are on the user form
    'invisible.
    txtTerm.BackColor = QBColor(3)
    Kount = 0
    Skip = 0
    lblToo.BackStyle = 0 'make the backstyle of the following lables invisible.
    lblAnswer1.BackStyle = 0
    lblAnswer2.BackStyle = 0
    lblAnswer3.BackStyle = 0
    lblAnswer4.BackStyle = 0
    lblResult.BackStyle = 0
    lblAnswer.BackStyle = 0
    lblHope.BackStyle = 0
    lblRite.BackStyle = 0
    lblWrong.BackStyle = 0
    lblCount.BackStyle = 0
    lblskip.BackStyle = 0
    Image1.Visible = False 'Make image1 invisible.
    Image2.Visible = False 'Make image2 invisible.
    cmdPrevious.Visible = False 'Make command previous invisible.
    cmdQuest.Caption = "BEGIN QUIZZ"
    cmdQuest.BackColor = QBColor(10)
    cmdQuest.Visible = True 'Make commmand quest visible.
    lblRite.Caption = Rite
    lblWrong.Caption = Wrong
    lblskip.Caption = Skip
    lblComments.Visible = False
    lblComment.Visible = False
    End Sub
    Private Sub Random()
    Dim counter As Integer
    Dim Found As Integer
    Dim RecNum As Long
    Dim TmpPerson As PersonInfo
    Dim Rand As Integer
    Randomize
    For counter = 1 To LastRecord
    Rand = Int((LastRecord - 1) * Rnd + 1)
    Next
    Found = False
    For RecNum = 1 To LastRecord
    Get #FileNum, RecNum, TmpPerson

    If Rand = RecNum Then
    Found = True
    Exit For
    End If
    Next
    If Found = True Then

    SaveCurrentRecord
    CurrentRecord = RecNum

    ShowCurrentRecord
    End If

    End Sub
    Private Sub Storage()
    'Open database called PHONE.DAT
    RecordLen = Len(Person)
    FileNum = FreeFile
    Open "PHONE.DAT" For Random As FileNum Len = RecordLen
    CurrentRecord = 1
    LastRecord = FileLen("PHONE.DAT") / RecordLen
    If LastRecord < 1 Then
    LastRecord = 1
    End If
    ShowCurrentRecord
    cmdQuest.Visible = True
    End Sub
    Private Sub EmptyFour()
    'This subroutine simply makes sure that; Result, Answer, Hope, and Term
    'captions are'empty. (Contain no text etc).
    lblResult.Caption = ""
    lblAnswer.Caption = ""
    lblHope.Caption = ""
    txtTerm.Text = ""
    End Sub
    Private Sub ShowCurrentRecord()
    Get #FileNum, CurrentRecord, Person
    lblCount.Caption = Kount & " of " & LastRecord & " QUESTIONS"
    lblletsee.Caption = "Question Number: " & CurrentRecord
    lblToo.Caption = Trim(Person.Name)
    'Show chapter number and comments at bottom of screen
    'lblComment.Visible = True
    'lblComments.Visible = True
    lblComments.Caption = Trim(Person.Comments)
    lblComments.Caption = Right(Person.Comments, 247)
    lblComments.BackStyle = (0)
    'Show the possible answers
    lblAnswer1.Caption = Trim(Person.Que1)
    lblAnswer2.Caption = Trim(Person.Que2)
    lblAnswer3.Caption = Trim(Person.Que3)
    lblAnswer4.Caption = Trim(Person.Que4)
    Questiontype = Trim(Person.Comments)
    QuestionMarker
    End Sub
    Private Sub QuestionMarker()
    'If Person.Comments * 2 = MC (The first two letters in the Comments)
    'then disable and make invisible all other question indicators and display multiple choice
    'question markers, EG: A. B. C. D. etc.
    'If Person.Comments * 2 = TF then disable and make invisibleall other question indicators
    'and display true or false question markers.
    'If Person.Comments * 2 = TM then disable and make invisible all other question indicators
    'and display terminology question markers.
    If CurrentRecord = 1 Then
    cmdQuest.Visible = True
    End If
    If Questiontype = "MC" Then
    cmdQuest.Visible = True
    cmdAns(0).Visible = True
    cmdAns(1).Visible = True
    cmdAns(2).Visible = True
    cmdAns(3).Visible = True
    lblAnswer1.ForeColor = QBColor(1)
    lblAnswer2.ForeColor = QBColor(1)
    lblAnswer3.ForeColor = QBColor(1)
    lblAnswer4.ForeColor = QBColor(1)
    AnsIndex
    ElseIf Questiontype = "TF" Then
    cmdQuest.Visible = True
    cmdAns(4).Visible = True
    cmdAns(5).Visible = True
    lblAnswer1.ForeColor = QBColor(1)
    lblAnswer3.ForeColor = QBColor(1)
    AnsIndex
    ElseIf Questiontype = "TM" Then
    txtTerm.Visible = True
    txtTerm.SetFocus
    cmdTerm.Visible = True
    cmdQuest.Visible = True
    txtTerm.BackColor = QBColor(3)
    AnsIndex
    End If
    End Sub
    Private Sub SaveCurrentRecord()
    ' If I remember correct, this sub functions such that when the user clicks the "next question button"
    'The(cmdquest button) the current question is saved then sends back to get another question
    If CurrentRecord >= 1 Then
    Tag = True
    Put #FileNum, CurrentRecord, Person
    End If
    End Sub
    Private Sub AnswerIndicators()
    'This subroutine makes all answer indicators and images invisible.
    cmdAns(0).Visible = False
    cmdAns(1).Visible = False
    cmdAns(2).Visible = False
    cmdAns(3).Visible = False
    cmdAns(4).Visible = False
    cmdAns(5).Visible = False
    txtTerm.Visible = False
    cmdTerm.Visible = False
    Image1.Visible = False
    Image2.Visible = False
    'lblComments.Visible = True

    End Sub





Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories