Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 17th, 2006, 9:38 AM   #1
dsbabyGurl
Newbie
 
dsbabyGurl's Avatar
 
Join Date: Oct 2006
Location: Philippines
Posts: 13
Rep Power: 0 dsbabyGurl is on a distinguished road
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
dsbabyGurl is offline   Reply With Quote
Old Dec 17th, 2006, 10:43 AM   #2
kyndig
Newbie
 
Join Date: Jan 2006
Posts: 7
Rep Power: 0 kyndig is on a distinguished road
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
kyndig is offline   Reply With Quote
Old Dec 18th, 2006, 7:21 AM   #3
dsbabyGurl
Newbie
 
dsbabyGurl's Avatar
 
Join Date: Oct 2006
Location: Philippines
Posts: 13
Rep Power: 0 dsbabyGurl is on a distinguished road
Quote:
Originally Posted by kyndig View Post
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?
dsbabyGurl is offline   Reply With Quote
Old Dec 18th, 2006, 8:51 AM   #4
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
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
Arevos is offline   Reply With Quote
Old Dec 18th, 2006, 12:57 PM   #5
sanscolour
Newbie
 
Join Date: Dec 2006
Posts: 1
Rep Power: 0 sanscolour is on a distinguished road
Quote:
Originally Posted by kyndig View Post
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
sanscolour is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Bizarre TI-89 matrix algebra error (not language specific) Generic Other Scripting Languages 0 Sep 7th, 2005 8:16 PM
Prog hangs when entering new loop... layer C++ 1 May 6th, 2005 6:59 AM
ASCII conversion loop difficulty crmpicco Visual Basic 2 May 3rd, 2005 1:55 PM
WinSock accept() hangs program in Do loop... layer C++ 5 Apr 29th, 2005 11:28 AM
Type Mismatch Error = 13 Benjizzle Visual Basic 5 Mar 15th, 2005 5:23 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:28 AM.

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