473,395 Members | 1,468 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,395 software developers and data experts.

what is error with this code

kirubagari
158 100+
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdscan_Click()
  2.  
  3. Dim a As Long
  4.  
  5.  a = arrByte(i)
  6.  
  7.  For i = 49 To mFileSize
  8.    If a <> "4" Then
  9.       a = "4"
  10.    End If
  11.     i = i + 5
  12. Next i
  13.  
  14. End Sub

this coding give error msg the subscript out of range.Actually i want to read bytes from 49 to end of file.if the byte 49 is 4 then just leave it abd if the value other than that i would like to change to 4.Using for loop mean every 5th value i would like to do same thing.What is the error with the this coding......
Jul 10 '07 #1
7 1403
r035198x
13,262 8TB
Private Sub cmdscan_Click()

Dim a As Long

a = arrByte(i)

For i = 49 To mFileSize
If a <> "4" Then
a = "4"
End If
i = i + 5
Next i

End Sub


this coding give error msg the subscript out of range.Actually i want to read bytes from 49 to end of file.if the byte 49 is 4 then just leave it abd if the value other than that i would like to change to 4.Using for loop mean every 5th value i would like to do same thing.What is the error with the this coding......
Please do not post questions in the articles section.
Moved to forum
Jul 10 '07 #2
hariharanmca
1,977 1GB
Private Sub cmdscan_Click()

Dim a As Long

a = arrByte(i)

For i = 49 To mFileSize
If a <> "4" Then
a = "4"
End If
i = i + 5
Next i

End Sub


this coding give error msg the subscript out of range.Actually i want to read bytes from 49 to end of file.if the byte 49 is 4 then just leave it abd if the value other than that i would like to change to 4.Using for loop mean every 5th value i would like to do same thing.What is the error with the this coding......






Expand|Select|Wrap|Line Numbers
  1. For i = 49 To mFileSize
  2. i = i + 5
  3. Next i
You are increment the value as 5 steps, so after increase the value it should contain the index number otherwise, can u post where and all you using I value inside for loop.
Jul 10 '07 #3
Killer42
8,435 Expert 8TB
I think people are missing the point here. The line a = arrByte(i) is obviously in the wrong place. As written, this will use whatever value happens to be in variable i when the routine is called. If you don't have Option Explicit at the top of the module, then i may not even exist, in which case VB will simply create it at this point and (I think) assign it the value 0.

Do you have the "require explicit variable declaration" option turned on? If not, I highly recommend you do so. And add Option Explicit at the top of each module, if it isn't there already.

Plus, the loop achieves nothing. Presumably, it is intended to check various occurrences in the byte array. But without that a = line, it's doing nothing useful.
Jul 10 '07 #4
Killer42
8,435 Expert 8TB
P.S. You could have replaced that entire loop with the statement a = 4 to get the same effect. This code has a lot of problems.
Jul 10 '07 #5
Killer42
8,435 Expert 8TB
P.P.S. Sorry to be so negative. I've made a quick attempt at correcting the code. Haven't tested this, but I think it will work.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdscan_Click()
  2.   For i = 49 To mFileSize Step 5
  3.     arrByte(i) = 4
  4.   Next
  5. End Sub
Jul 10 '07 #6
hariharanmca
1,977 1GB
P.P.S. Sorry to be so negative. I've made a quick attempt at correcting the code. Haven't tested this, but I think it will work.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdscan_Click()
  2.   For i = 49 To mFileSize Step 5
  3.     arrByte(i) = 4
  4.   Next
  5. End Sub

thats good Suggestions.
Jul 11 '07 #7
Killer42
8,435 Expert 8TB
thats good Suggestions.
See my post in your other thread for a more complete solution.
Jul 11 '07 #8

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

Similar topics

1
by: kaiwing18 | last post by:
Hi , I have a problem relate to java and database. Could anyone answer me ?Please see the following code. import java.sql.*; public class Result { public static void main(String args) {
3
by: fastwings | last post by:
mm the code //////makemenu.h//// class menu { public: int op; pmenu(int op,int sub = 0) { switch op {
72
by: E. Robert Tisdale | last post by:
What makes a good C/C++ programmer? Would you be surprised if I told you that it has almost nothing to do with your knowledge of C or C++? There isn't much difference in productivity, for...
8
by: aling | last post by:
Given the bit field struct: int main() { union { struct { unsigned short s1 : 4; unsigned short s2 : 3;
51
by: WindAndWaves | last post by:
Can anyone tell me what is wrong with the goto command. I noticed it is one of those NEVER USE. I can understand that it may lead to confusing code, but I often use it like this: is this...
4
by: atv | last post by:
Whatis the proper way to handle errors from function calls? For example, i normally have a main function, with calls to mine or c functions. Should i check for errors in the functions called...
46
by: Keith K | last post by:
Having developed with VB since 1992, I am now VERY interested in C#. I've written several applications with C# and I do enjoy the language. What C# Needs: There are a few things that I do...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
10
by: Protoman | last post by:
Could you tell me what's wrong with this program, it doesn't compile: #include <iostream> #include <cstdlib> using namespace std; class Everything { public: static Everything* Instance()
5
by: =?GB2312?B?17/HvyBaaHVvLCBRaWFuZw==?= | last post by:
Hi, I would like to have someone comments on what's the best practice defining error codes in C. Here's what I think: solution A: using enum pros: type safe. better for debug (some debugger...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.