Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Visual Basic (http://www.programmingforums.org/forum18.html)
-   -   Do..while loop and ....error! (http://www.programmingforums.org/showthread.php?t=12198)

dsbabyGurl Dec 17th, 2006 10:38 AM

Do..while loop and ....error!
 
Hello all, my post is about visual basic 6.0. Im tryin to add 10 scores using the DO ... while loop and adding them as an array element, after adding, it simply displays the sum of all quiz scores. I dont know if the syntax is correct and when i increment the counters, and the counters for the index of the array, an error occurs, it says,

"Compile Error
Expected: Expression"

I know this is simple, and just learning on this, i just want to know why it wont let me increment. Please help me on this.
Here is the code below:
:

Dim q1 As Integer
Dim q2 As Integer
Dim q3 As Integer
Dim q4 As Integer
Dim q5 As Integer
Dim q6 As Integer
Dim q7 As Integer
Dim q8 As Integer
Dim q9 As Integer
Dim q10 As Integer
Dim total As Integer
Dim i As Integer
Dim cnt As Integer


Private Sub cmdadd_Click()
Dim quiz() As String
    q1 = Val(txt1.Text)
    q2 = Val(txt2.Text)
    q3 = Val(txt3.Text)
    q4 = Val(txt4.Text)
    q5 = Val(txt5.Text)
    q6 = Val(txt6.Text)
    q7 = Val(txt7.Text)
    q8 = Val(txt8.Text)
    q9 = Val(txt9.Text)
    q10 = Val(txt10.Text)
   
    quiz(0) = q1
    quiz(1) = q2
    quiz(2) = q3
    quiz(3) = q4
    quiz(4) = q5
    quiz(5) = q6
    quiz(6) = q7
    quiz(7) = q8
    quiz(8) = q9
    quiz(9) = q10
   
    total = Val(txt11.Text)
    cnt = 1
    i = 0
    Do
        Do
            total = total + quiz(i)
            i++
        While i <= 10
        cnt++
    While cnt <= 10
           
End Sub
       
txt11.Text = total
End Sub




This would mean a lot to me, if u look and help me.... Thank you all...



By:
Jaynie

kyndig Dec 17th, 2006 11:43 AM

You cant do i++ in vb.
:


i = i + 1
cnt = c + 1

or use a for loop

for cnt = 0 to 10
  for i = 0 to 10
    total = total + quiz(i)
  next i
next cnt


dsbabyGurl Dec 18th, 2006 8:21 AM

Quote:

Originally Posted by kyndig (Post 121298)
You cant do i++ in vb.
:


i = i + 1
cnt = c + 1

or use a for loop

for cnt = 0 to 10
  for i = 0 to 10
    total = total + quiz(i)
  next i
next cnt




thanks for the help kyndig.... i have to use the Do while loop thou... :( how is it done in a do while loop? :confused:

Arevos Dec 18th, 2006 9:51 AM

A for loop is a specialised loop that counts through a set of numbers. For example:
:

for i = 0 to 10
  [some code]
next i

Should be equivalent to:
:

i = 0
Do
  [some code]
  i = i + 1
While i < 10

Disclaimer: My knowledge of VB is somewhat limited, so watch out for syntax errors in the above code :)

sanscolour Dec 18th, 2006 1:57 PM

Quote:

Originally Posted by kyndig (Post 121298)
You cant do i++ in vb.
:


i = i + 1
cnt = c + 1

or use a for loop

for cnt = 0 to 10
  for i = 0 to 10
    total = total + quiz(i)
  next i
next cnt


As a general point of interest, if any of you choose to move to the dark side (VB .Net), in 2005 the following

i = i + 1

can also be written as

i += 1


All times are GMT -5. The time now is 1:30 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC