Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
My program uses data files which it reads and writes as needed. The file in question is a sequential list of numbers, saved using a for loop and a write statement. This part works correctly. I've confirmed it. But for some reason, it occasionally reads the input from the file as all zeros. I can't figure out why. I open the file in notepad and look at the contents, and it's been save properly as the correct numbers. But when I go to read it with an Input statement in a for loop, it reads and assigns the exact same numbers I just looked at as all zeros. It even reads and assigns the correct number of zeros, but the numbers in the files are not zeros.

I'm not sure why this would be. Has anybody ever had this error? What was the issue? There's only one copy of the data file. I'm not sure what could be causing this or how to fix it. Any help would be greatly appreciated.

Here's the contents of the file being read:

VB
"Default"
9928
12654
11840
9378
4206
4071
13659
2282
1110
9599
1212
7483
5779
5967
10064
13163
12525


And here's what the Input statement is seeing for some reason:

VB
"Default"
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0


Please help. Thanks. :-/
Posted
Updated 6-Dec-11 8:18am
v2
Comments
#realJSOP 6-Dec-11 14:31pm    
We can't possibly help you without seeing the code in question.
Prerak Patel 6-Dec-11 22:26pm    
Share your code.

1 solution

Well, I finally figured it out. Turns out the Write function was storing the integers as strings instead of integers, so when the Input function tried to assign the value to the array, it just added zero instead of throwing a type mismatch error.

I fixed it by inputting to a temp string array and then converting it with the Val function before the assignment. Problem solved.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900