Discussion Locked

Right and Right$ functions in VB6

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Dim sText As String
Dim sVal As String
sText = "Test Value"
sVal = Right$(sText,4)

The code above blows up at sVal with these messages:
1. Type declaration does not match declared data type and
2. Compile error. Expected array.

Theerror goes away if I substitute Left in place of Right. What am I doing wrong?
An inventory app is blowing up. Please help.

5 replies

by tsl

This code works just fine for me. Are you sure that the problem is in this code? try copy/paste into a new executable project and then run it.

My test enviroment was a standard executable project with the following code in Form1:

Private SubForm_Load()
Dim sText As String
Dim sVal As String
sText = "Test Value"
sVal = Right$(sText, 4)
MsgBox sVal 'just to see if the right function is working
End Sub

This also worked without the message box

by chris.lewis

It's probably a reference issue...

Try this:

sVal = VBA.Right$(sText,4)

This will make sure that you are using the VBA right$ function, and not a function that is in your code, or a method in another reference.

Once that's working, I'd use the object browser (F2) to try and find the bad RIGHT function.

by setivi

Thanks, just what the application was looking for.
It worked fine and solved the pesky problem

This discussion is closed to new replies.