If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > Problem with accepting strings in a loop

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-16-04, 12:54
Jane2004 Jane2004 is offline
Registered User
 
Join Date: Feb 2004
Posts: 7
Question Problem with accepting strings in a loop

Hi!
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?

Thanks!
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))
Next
Loop
MsgBox("The sum of the test grades is " & sum & " and the average is " & sum / 2 & ".")
Reply With Quote
  #2 (permalink)  
Old 02-17-04, 17:56
brianb99999 brianb99999 is offline
Registered User
 
Join Date: Feb 2004
Posts: 37
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:")
Do
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
Loop
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On