Weird integer behaviour

  • Thread starter Thread starter Jethro
  • Start date Start date
J

Jethro

Having upgraded my VB6 project ....

This doesn't work

dim i as integer

For i = 0 to 8
MyRecordset.Fields(i).Value = "Test" <---------- Error thrown here
"item or variable not found in collection'
next i


This does :

dim i as integer

For i = 0 to 8
MyRecordset.Fields(CInt(i)).Value = "Test"
next i


Weird huh ? I could understand it if i was an object, but not a primitve
(althought I notice that even primitives have inbuilt methods now)
 
Jethro said:
Having upgraded my VB6 project ....

This doesn't work

dim i as integer

For i = 0 to 8
MyRecordset.Fields(i).Value = "Test" <---------- Error thrown
here
"item or variable not found in collection'
next i


This does :

dim i as integer

For i = 0 to 8
MyRecordset.Fields(CInt(i)).Value = "Test"
next i


Weird huh ? I could understand it if i was an object, but not a
primitve (althought I notice that even primitives have inbuilt
methods now)

Are you *sure* this is the real code? It's obvious that you didn't copy it
from VB. Can you post the real code, including the declarations? I don't
believe that the difference comes from CInt.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
if you cursor over the variable i in MyRecordset.Fields(i).Value = "Test
what does VS show the type to be

guy
 
Back
Top