x
This website is using cookies. We use cookies to ensure that we give you the best experience on our website. More info. That's Fine
HPC:Factor Logo 
 
Latest Forum Activity

eVB - left() returns "object not a collection, but right() doesn't

I dunk for bananas Page Icon Posted 2024-01-13 11:48 AM
#
Avatar image of I dunk for bananas
H/PC Elite

Posts:
667
Location:
Europe
Status:
For the program I'm writing, I need to isolate the first two characters of a string, so I'm trying to use Left() to do so.
This is what I'm trying to do:

MsgBox (Left("test", 1))
This returns "Object not a collection".

MsgBox (Right("test", 1))

This code, on the other hand, returns "t".

How is this possible? Is there another way I can isolate the first two characters of my string?

edit:
MsgBox (Mid("test", 1, 2))
works. I guess it's just a bug within eVB itself?

Edited by I dunk for bananas 2024-01-13 11:55 AM
 Top of the page
C:Amie Page Icon Posted 2024-01-13 1:39 PM
#
Avatar image of C:Amie
Administrator
H/PC Oracle

Posts:
17,925
Location:
United Kingdom
Status:
Mid is slower than Left() so if you are iterating this, you might want to try and fix this.

Couple of things springs to check:

Are you using Option Explicit? If not add Option Explicit (project menu > Properties > Compile > Set Option Explicit to On)

Are you 100% certain that the line number in the exception was the line number for MsgBox (Left("test", 1))

Is collection error coming from Left or from MsgBox

This will trap the correct line number and ascertain if it is left or msgbox - or if it is a string literal error, accidental use of non-ASCII quotation marks:
Dim str1 as String 
Dim str2 as String  
str1 = "test"
str2 = Left(str1, 1)
msgbox(str2)
 Top of the page
WinCEDev Page Icon Posted 2024-01-13 4:26 PM
#
Avatar image of WinCEDev
Factor Fanatic

Posts:
62
Location:
Europe
Status:
Unfortunately this is a bug in eVB, it is interpreting "Left" as a property of the form (e.g. Me.Left) instead of the string manipulation function. This only happens with code inside forms, Left works fine from a module.

You've already found the best way to work around it which is to use Mid, or alternatively you could move the affected code to a module.

Microsoft used to have a KB article about this: Q180455.

As an aside, eVB is throwing the rather confusing "Object not a collection" error because the value of Left (the property) is a number. VB interprets the parentheses as trying to access an array index, but the value isn't an array or a type of collection object.

Once I have some time I'll collect all the eVB issues I know about and make a post about it, fortunately most of them can be worked around.
 Top of the page
C:Amie Page Icon Posted 2024-01-13 4:35 PM
#
Avatar image of C:Amie
Administrator
H/PC Oracle

Posts:
17,925
Location:
United Kingdom
Status:
Yikes Microsoft, that's beautiful....
 Top of the page
Jump to forum:
Seconds to generate: 0.140 - Cached queries : 61 - Executed queries : 9