Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2004

    Question Unanswered: Problem with accepting strings in a loop

    Can somebody please help me out for my class project?

    I'm trying to run a loop that accept strings. Each string contains a last name, first name and a trest grade, supposedly separated by commas. After the strings had been accepted, the text box should show something like First name Last name score.

    Somehow my loop doesn't work and the strings aren't show up in the text box after I input them into the inputboxes.
    Can somebody help me please?

    That's the code that I have so far:

    Dim inputfn, inputln, inputgrade, result As String
    Dim items() As String
    Dim sum As Double = 0
    Dim ctr As Integer = 0
    Dim max As Integer

    Do While sum <= max
    inputfn = InputBox("Enter First Name:")
    inputln = InputBox("Enter Last Name:")
    inputgrade = InputBox("Enter Test Grade:")
    items = inputfn.Split(",")
    txtinput.Text = inputfn & vbTab & inputln & vbTab & inputgrade
    For ctr = 0 To items.GetUpperBound(0)
    sum = sum + (items(ctr))
    MsgBox("The sum of the test grades is " & sum & " and the average is " & sum / 2 & ".")

  2. #2
    Join Date
    Feb 2004
    This will do what you need, have to remove the sum from the loop or it will double count also sum<=max replace it with quit (now when it asks you for first name, if you type in quit it will finish), make sure you do not add the code into the form's load event or the form will not display correctly until after all the code is run (I added the code in the form_activate event).

    Private Sub Form_Activate()
    Dim strInputFN As String
    Dim strInputLN As String
    Dim strInputGrade As String
    Dim strResult As String
    Dim intCounter As Integer
    Dim intMax As Integer
    Dim dblSum As Double
    Dim dblItem() As Double

    ReDim dblItem(0)
    Do While Not strInputFN = "quit"
    strInputFN = InputBox("Input First Name:")
    If Not strInputFN = "quit" Then
    strInputLN = InputBox("Input Last Name:")
    strInputGrade = InputBox("Input Test Grade:")
    Loop While Not IsNumeric(strInputGrade)
    ReDim Preserve dblItem(UBound(dblItem) + 1)
    dblItem(UBound(dblItem)) = CDbl(strInputGrade)
    txtInput.Text = strInputFN & " " & strInputLN & ": " & strInputGrade
    End If
    For intCounter = 1 To UBound(dblItem)
    dblSum = dblSum + dblItem(intCounter)
    Next intCounter
    MsgBox ("The sum of the test grades is " & dblSum & " and the average is " & CDbl(dblSum / 2) & ".")
    End Sub

Posting Permissions

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