General discussion

Locked

Right and Right$ functions in VB6

By setivi ·
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.

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Right and Right$ functions in VB6

by TSL In reply to Right and Right$ function ...

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

Collapse -

Right and Right$ functions in VB6

by setivi In reply to Right and Right$ function ...

Answer # 2 solved the problem for me:
sVal = VBA.Right$(sText,4)

Collapse -

Right and Right$ functions in VB6

by Chris.Lewis In reply to Right and Right$ function ...

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.

Collapse -

Right and Right$ functions in VB6

by setivi In reply to Right and Right$ function ...

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

Collapse -

Right and Right$ functions in VB6

by setivi In reply to Right and Right$ function ...

This question was closed by the author

Back to Web Development Forum
5 total posts (Page 1 of 1)  

Related Discussions

Related Forums