473,379 Members | 1,270 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

How to fix overflow error message in for next loop?

21
I am using a straight forward For Next Loop which operates perfectly when I write
Expand|Select|Wrap|Line Numbers
  1. For n = 1 to numOfDigits
  2. 'do something
  3. Next
  4.  
However when I change this to
Expand|Select|Wrap|Line Numbers
  1. For n = numOfDigits to 1 Step -1
  2. 'do the same thing as before
  3. NEXT
  4.  
(where numOfDigits = 8 at this point in the code)
I am getting an error message saying 'overflow' at the For... line of execution.

Anybody know why?? Help gratefully received.

Deekay
Feb 4 '11 #1

✓ answered by TheSmileyCoder

If you change from byte to integer, your set to go.

A byte cannot take on a negative value, as Im guessing thats why its complaining about the negative steps.

5 4103
Stewart Ross
2,545 Expert Mod 2GB
Hi. There is nothing obvious from what you have posted. Could you post the entire code for the sub or function up to the NEXT itself? It is possibly related to the data types you have defined for the variables concerned, but I just can't tell without seeing the actual code.

-Stewart
Feb 4 '11 #2
TheSmileyCoder
2,322 Expert Mod 2GB
I tried this:
Expand|Select|Wrap|Line Numbers
  1. Public Sub Loopie()
  2.  
  3. Dim intNumD As Integer
  4. intNumD = 8
  5. Dim I As Integer
  6. For I = 1 To intNumD
  7.     Debug.Print I
  8. Next
  9.  
  10. For I = intNumD To 1 Step -1
  11.     Debug.Print I
  12. Next
  13. End Sub
and it worked fine. Have you declared numOfDigits?
Feb 4 '11 #3
Deekay
21
Hello Stewart
Thanks for the reply. Here is the code
Expand|Select|Wrap|Line Numbers
  1. Private Function myFunc(numInput as Double) as Double
  2. Dim fstring as String
  3. Dim numOfDigits as Byte, counter as Byte
  4. dim char(8) as String
  5.  
  6. fstring = Str(numInput)
  7.  
  8. For counter = numOfDigits to 1 Step -1
  9. char(counter) = Mid(fstring, counter, 1)
  10. Next
  11.  
  12. 'some more code
  13. End Function
  14.  
Thanks for any thoughts.
Deekay
Feb 4 '11 #4
TheSmileyCoder
2,322 Expert Mod 2GB
If you change from byte to integer, your set to go.

A byte cannot take on a negative value, as Im guessing thats why its complaining about the negative steps.
Feb 4 '11 #5
Deekay
21
Great - it's obvious now you've said this!!! But I was tearing my hair out becuase this part of my code seemed so straight forward.
Thanks a million
Deekay
Feb 4 '11 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: AndrewM | last post by:
Hello, I have a SUB which has input variables. If I run it once its okay, but I need to include it in a for....next loop. Can this be done ? for i=0 to 100 call mySub(arr(0,i)) next
2
by: Patrik | last post by:
Hi, I cannot find the right way to write this code. I keep getting the error : Next without For Here's my code. For Each Choix In RapInd_Code.ItemsSelected S6 =...
8
by: Terry Olsen | last post by:
How do I loop back to the beginning of a for/next loop before getting to the end of it? Isn't there an "iterate" command or something like that? For Each This in That ...code if This = False...
7
by: wandoledzep | last post by:
I'm using Visual Studio .NET 2002 I remember there was a way to do this in C, so there should be a way of doing it in .NET: Instead of: Dim bolSquare1 as Boolean Dim bolSquare2 as Boolean...
11
by: Miro | last post by:
Im using VB2003 and i just pulled an example out of the book that says this: "Note: also that you can decalre the index variable in a For Loop using the optional AS datatype clause, as long as...
2
by: BerkshireGuy | last post by:
I have a routine in Access that loops through an Excel workbook and executes code base on the worksheet name. If the worksheet name contains the word 'Stats' than that is a sheet I want to read...
1
by: Kevin | last post by:
ASP.NET 2.0 I have code that updates a database from a number of textboxes on a web form. I've had to hard coded references to my web form textboxes. I'd like to know how I can reference them...
5
by: Candace | last post by:
I have to write a program to find all Pythagorean triples for a right triangle. I know that the squares of two sides of the triangle must equal the square of the third (longest) side. However, I...
7
by: muddasirmunir | last post by:
i am using vb6 i had make a for next loop which fill data into the table now , some time it may needed that we want to cancel that loop . now what is the code to exit the for next loop i want...
3
by: smileyc | last post by:
I have 5 arrays, named array1 array2 array3 array4 array5. They are integer arrays each with 5 elements in them. I want to access all the elements in all the arrays using a for next loop,the pseudo...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.