Solved

incorrect reference for VBA in VB6

Posted on 2002-07-08
16
596 Views
Last Modified: 2010-05-18
I wrote a vb6 app in a win2k environment and am now trying to transfer it over to a new winXP machine.  Somehow, the wrong VBA reference was selected.  Unfortunately there is no way to unselect it and select the correct one according to the help that pops up from msdn.  Is that really the case?  To be more specific I am unable to use all the string functions included in VBA, or at least not by the normal names, for example: right, space, etc.  Can i find out what the names are for the vba dll that is checked?

thanks
0
Comment
Question by:carpachio
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 3
  • +2
16 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7138973
hearing... (that's one of things that i hate from Microsoft)
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 7138992
If I understand you correctly, you're wondering how to access functions such as right[$], space[$], etc.?

These are intrinsic functions and are included in the virtual machine: MSVBVM60.dll

I haven't tried any VB6 on XP yet, so I'm not sure of all the issues, but would be surprised if this aspect changes.

Can you describe your project?  Have you tried a simple test:

Create a form, add a button and a textbox and this code:

Private Sub Command1_Click()
  dim strX as string

  strX="This is a test"
  text1.text = right$(strX,4) & space$(3) & left$(strX,4)
end sub

Run and click the button to see if "test   This" appears in the textbox.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7139007
rspahitz, AFAIK, all string manipulations are done with fucntions exported by Visual Basic for Applications. (Check your Object Browser with F2, under string class)
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7139009
carpachio, how did you do the project's "transfer"?
0
 

Author Comment

by:carpachio
ID: 7139019
to clarify

I'm not using:
text1.text = right$(strX,4) & space$(3) & left$(strX,4)

I'm using:
text1.text = right(strX,4) & space(3) & left(strX,4)

I think that there are a couple of different dll files which contain the vba functions like these, and possibly the one which is selected currently uses the "right$" command as opposed to just simply "right".  Also, I didn't really transfer the project at all, rather I'm just trying to get it to run under XP.  Hopefully this makes sense.  Essentially, what I need to find out is how to unselect the reference to VBA which is currently selected in the projects references and select a different VBA reference.

thanks
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 7139027
Richie, if I go to the object browser and find the "strings" class, I see it is a member of the VBA library which is the VBA libarary:

"Function String(Number As Long, Character)
"    Member of VBA.Strings
"    Returns a repeating character string of the length specified"

"Module Strings
"    Member of VBA
"    Procedures used to perform string operations"

"Library VBA
"    C:\WINNT\SYSTEM32\MSVBVM60.dll
"    Visual Basic For Applications"

I don't know that this specifically helps, but it at least shows that this class is embedded in the VB6 virtual machine.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7139047
OK. But as you use VBA in office apps, it doesn't references to MSVBVM60.dll.
To me, Virtual Machine get those from vba6.dll and exports them to VB IDE, but maybe i am wrong.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7139050
carpachio, right returns a variant data type, right$ returns a "pure" string.
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 7139177
...and I don't know of any way to unreference the VBA engine from VB...

Going back to your original question: "...the wrong VBA reference was selected..."

How was this selected?  As far as I know, VB6 selects this automatically when you open a new project, and it is an integral part of the project.

--
Richie, after re-reading the Q, I think we're both a bit confused by the VBA reference.  Since carpachio stated, "I wrote a vb6 app," I'm suspecting that the VBA issue is related to the VBA entry that appears when you examine a VB6 project's references.
0
 

Author Comment

by:carpachio
ID: 7139181
rspahitz-

would opening a project in a different OS environment affect which VBA entry is selected?  
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 7139191
I've tried it in Win98, WinNT, and Win2000, and they all bring up MSVBVM60.dll, but I think they have slight variations (possibly depending on the service pack.)

On my Win2000/VB6SP3 install (C:\WINNT\system32), my file is 1,356K, 8/23/2001 6:00am.  What does yours show?  It may be worth while to go to the Microsoft website and see what they have for this under their download section.

0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 200 total points
ID: 7139229
I have met this situation a couple of time (Mid, Left, Right, ... function not recognized). Use "VBA." in fromt of all your function and it will work.
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 7140413
as for the problem of Right, Left etc not being "found", that USUALLY is the signature of a MISSING REFERENCE elsewhere in the Project/References choices.  Look for other references that are marked as MISSING.

Carpachio: on antoher note, when you say
"I'm not using:
text1.text = right$(strX,4) & space$(3) & left$(strX,4)

I'm using:
text1.text = right(strX,4) & space(3) & left(strX,4)"

those are the WRONG versions of the functions to be using.  You should be using Right$, Left$ and Space$

as they will return STRING values (you are concatenating the values and then assigning the result to Text1.Text, which is a STRING.

As you are currently writing the code, the values are combined as VARIANTs, and the reuslting VARIANT is then CONVERTED to a STRING before it is assigned to Text1.Text - This requires additional processing time, and is generally NOT a godd idea.

Arthur Wood
0
 

Author Comment

by:carpachio
ID: 7140811
thanks Arthur and emoreau for your answers.  I didn't know the difference between right$ and right, and the "VBA." in front worked.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 7140936
right returns a variant
right$ returns a string
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7142021
emoreau, thanks for your last clarification :))
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question