奇怪的VB文件访问故障 [英] Strange VB file access glitch

查看:45
本文介绍了奇怪的VB文件访问故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序使用根据需要读取和写入的数据文件.有问题的文件是数字的顺序列表,使用for循环和write语句保存.这部分正常工作.我已经确认了但是由于某种原因,它偶尔会从文件中读取全零的输入.我不知道为什么.我在记事本中打开文件并查看内容,它已正确保存为正确的数字.但是,当我在for循环中使用Input语句读取它时,它读取并分配了我刚才看过的完全相同的数字,全为零.它甚至可以读取并分配正确的零数,但是文件中的数字不是零.

我不确定为什么会这样.有人遇到过这个错误吗?到底是什么问题?数据文件只有一个副本.我不确定这可能是什么原因或如何解决.任何帮助将不胜感激.

这是正在读取的文件的内容:

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:

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



由于某些原因,这就是Input语句看到的内容:



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

"Default"
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0



请帮忙.谢谢. :-/



Please help. Thanks. :-/

推荐答案

嗯,我终于明白了.原来Write函数将整数存储为字符串而不是整数,因此,当Input函数尝试将值分配给数组时,它只是添加了零,而不是引发类型不匹配错误.

我通过输入到临时字符串数组然后在赋值之前使用Val函数对其进行转换来修复它.问题已解决.
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.


这篇关于奇怪的VB文件访问故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆