CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2000
    Location
    IL, U.S.A.
    Posts
    218

    Could someone tell me what these lines of code are doing?

    I am not sure what these lines of code are doing in this program. It loads a Sequential
    file and makes Buttons for each Question.
    Here is the entire main form. What does the lines of code do under
    the cmdDisplay button? Under the Form_Load procedure, What does each line
    do starting from the Redim statement to the End Sub? The Sequential file
    is at the Bottom.

    option Explicit
    Dim m_intIndex as Integer



    private Sub cmdComputeGrade_Click()
    Dim intFileNum as Integer, strFilter as string
    intFileNum = FreeFile
    'prompt = "Enter your Name."
    ' title = "Your Name"
    ' name = InputBox(prompt, title)

    intFileNum = FreeFile
    strFilter = "Text Files (*.txt)|*.txt|" & "All files (*.*)|*.*"
    cdlOpenfile.Filter = strFilter
    cdlOpenfile.ShowOpen
    g_strFileName = cdlOpenfile.FileName

    Open g_strFileName for input as #intFileNum

    End Sub

    'This will display the command buttons
    private Sub cmdDisplay_Click(intIndex as Integer)
    txtInputbox.Text = g_strQuestionsAndAnswers(7, intIndex)
    lblQuestion.Caption = g_strQuestionsAndAnswers(2, intIndex)
    txtInputbox.SetFocus
    m_intIndex = intIndex
    End Sub
    private Sub cmdDisplay_GotFocus(Index as Integer)
    cmdDisplay(Index).BackColor = vbYellow
    End Sub

    private Sub cmdDisplay_LostFocus(Index as Integer)
    cmdDisplay(Index).BackColor = vbRed
    End Sub

    'This will ask the user if they want to end the program.
    private Sub cmdEndprogram_Click()
    Dim intResponse as Integer
    Const conPrompt as string = "Are you sure?"
    Const conTitle as string = "Quit?"
    intResponse = MsgBox(conPrompt, vbYesNo + vbQuestion, conTitle)
    If intResponse = vbYes then
    Unload me

    End If
    End Sub
    'This is the main form code to show the splash screen and input the file
    'name as well as the control array size.
    private Sub Form_Load()
    'Dim strQuestions as string
    Dim intFileNum as Integer, strName as string
    Dim strFilter as string, NumberCorrect as Integer
    Dim intNumberOfQuestions as Integer
    Dim intLoadQuestions as Integer
    Dim intLoadFields as Integer
    Dim strTestName as string
    Const conTitle as string = "Your Name"
    Const conPrompt as string = "Enter your name:"



    'frmQuizzerSplash.Show vbModal

    strName = InputBox(conPrompt, conTitle)

    intFileNum = FreeFile
    strFilter = "Text Files (*.txt)|*.txt|" & "All files (*.*)|*.*"
    cdlOpenfile.Filter = strFilter
    cdlOpenfile.ShowOpen
    g_strFileName = cdlOpenfile.FileName
    'on error GoTo FileOpenErr
    Open g_strFileName for input as #intFileNum

    input #intFileNum, strTestName, intNumberOfQuestions ', strAnswere1, strAnswere2, strAnswere3
    'input #intFileNum, strAnswere1, strAnswere2, strAnswere3

    me.Caption = strName & "'s " & strTestName

    ReDim g_strQuestionsAndAnswers(1 to 7, 1 to intNumberOfQuestions) as string

    for intLoadQuestions = 1 to intNumberOfQuestions
    Call MakeTheButtons(intLoadQuestions)
    for intLoadFields = 1 to 6
    input #intFileNum, g_strQuestionsAndAnswers(intLoadFields, intLoadQuestions)
    next intLoadFields
    g_strQuestionsAndAnswers(intLoadFields, intLoadQuestions) = "<Enter you answer>"
    next intLoadQuestions

    Close #intFileNum


    'If txtInputbox.Text = strAnswere1 then
    'NumberCorrect = NumberCorrect + 1
    'ElseIf txtInputbox.Text = strAnswere2 then
    'NumberCorrect = NumberCorrect + 1
    'ElseIf txtInputbox.Text = strAnswere3 then
    'NumberCorrect = NumberCorrect + 1
    'End If
    'FileOpenErr:
    'MsgBox "Open error:" & Err.Description, vbCritical, "error!- #" & Err.Number


    End Sub


    'This will output the Queston to the user
    private Sub lblQuestion_Click()

    End Sub
    'This will tell the user about the program.
    private Sub mnuabout_Click()
    frmInformation_Screen.Show
    End Sub
    'This procedure will end the program
    private Sub mnudone_Click()
    End
    End Sub

    'This will give infprmation about the computer system and the program
    private Sub mnuinformation_Click()
    frmAbout.Show vbModal
    End Sub
    'This is the input box so the user can type in the answere
    private Sub txtInputbox_GotFocus()
    txtInputbox.SelStart = 0
    txtInputbox.SelLength = len(txtInputbox.Text)
    End Sub
    'This procedure will make the buttons for each question
    private Sub MakeTheButtons(byval intLoadQuestions as Integer)
    Load cmdDisplay(intLoadQuestions)

    cmdDisplay(0).Visible = false
    cmdDisplay(intLoadQuestions).Visible = true
    cmdDisplay(intLoadQuestions).Caption = intLoadQuestions

    Select Case intLoadQuestions
    Case is <= 10


    cmdDisplay(intLoadQuestions).Left = cmdDisplay(0).Left + cmdDisplay(0).Width * intLoadQuestions


    If intLoadQuestions = 1 then
    cmdDisplay(intLoadQuestions).Left = cmdDisplay(1).Left
    else
    cmdDisplay(intLoadQuestions).Left = cmdDisplay(0).Left + cmdDisplay(0).Width * intLoadQuestions
    End If
    Case is <= 20
    If intLoadQuestions = 11 then
    cmdDisplay(11).Left = cmdDisplay(0).Left
    else
    cmdDisplay(intLoadQuestions).Left = cmdDisplay(intLoadQuestions - 1).Left + _
    cmdDisplay(0).Width
    End If
    cmdDisplay(intLoadQuestions).Top = cmdDisplay(0).Top + cmdDisplay(0).Height
    Case else
    If intLoadQuestions = 21 then
    cmdDisplay(21).Left = cmdDisplay(0).Left
    else
    cmdDisplay(intLoadQuestions).Left = cmdDisplay(intLoadQuestions - 1).Left + cmdDisplay(0).Width
    End If
    cmdDisplay(intLoadQuestions).Top = cmdDisplay(0).Top + 2 * (cmdDisplay(0).Height)
    End Select


    End Sub

    private Sub txtInputbox_LostFocus()
    g_strQuestionsAndAnswers(7, m_intIndex) = txtInputbox.Text
    End Sub



    Sequential File
    I have this text file to Input as a sequential Access File

    Data-types Quiz, 8
    1, What data-type would you use for the population of Chicago?, LONG,LONG,lng,1
    2, What data-type would you use for a Social Security number?, STRING,STRING,str,1
    3, What data-type would you use for a variable where the only valid values are ON/OFF?, BOOLEAN,BOOLEAN,bln,1
    4, What data-type would you use for a constant with a value for Pi?, SINGLE,SINGLE,sng,1
    5, What data-type would you use for a variable to hold the grains of sand on a beach?, DOUBLE,DOUBLE,dbl,1
    6, "What initial should proceed a Public variable in a module to indicate its scope?
    a. p
    b. g
    c. m
    d. No initial", B,G,"B. g",5
    7, "What initial should proceed a variable that is used in a form to indicate its scope?
    a. p
    b. g
    c. m
    d. No initial", C,M,"C. M",5
    8, "What initial should proceed a variable that is used in a local procedure to indicate its scope?
    a. p
    b. g
    c. m
    d. No initial", D,NO INITIAL,"D. NO INITIAL",5



  2. #2
    Join Date
    Dec 2000
    Location
    Canada
    Posts
    59

    Re: Could someone tell me what these lines of code are doing?

    The code you are talking about basically takes the infomation from the Input file and puts it into a 2D array that is then used to populate the textboxes in the cmdDisplay button.

    I hope this helps
    Raistlin


  3. #3
    Join Date
    Nov 2000
    Location
    IL, U.S.A.
    Posts
    218

    Re: Could someone tell me what these lines of code are doing?

    Under the cmdDisplay Button this line
    txtInputbox.Text = g_strQuestionsAndAnswers(7, intIndex)

    What does the 7 and the intIndex do?
    Really, What does the complete line do?


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

Featured