VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

String trimming trouble

13 REPLIES 13
Reply
Message 1 of 14
Anonymous
413 Views, 13 Replies

String trimming trouble

Can't figure out why this code does not work on 2 of my user's PC
...
With ThisDrawing.Utility
.GetEntity ent, pickpt, vbCr & "Select an object: "
If ent Is Nothing Then
.Prompt vbCrLf & "Invalid Selection"
Exit Sub
Else
ent.Highlight True
End If

End With

ent.GetXData "", datType, datval
adelekey = Right(datval(0), Len(datval(0)) - 3)
...

The RIght method is where I am getting an error. but I have no trouble with it on 60+ user PC include my own and 2 other test PCs.

Any help would be appreciated.

Vito
13 REPLIES 13
Message 2 of 14
Anonymous
in reply to: Anonymous

Did you debug on that line of code to see what exact value is in datval(0)?
Or simply:

ent.GetXData "", datType, datval

Debug.Print "datval(0)=" & datval(0)
'or
MsgBox "datval(0)=" & datval(0)

adelekey = Right(datval(0), Len(datval(0)) - 3)

After seeing the value of datval(0), you would most likely have the answer.


"Vito" wrote in message news:5977128@discussion.autodesk.com...
Can't figure out why this code does not work on 2 of my user's PC
...
With ThisDrawing.Utility
.GetEntity ent, pickpt, vbCr & "Select an object: "
If ent Is Nothing Then
.Prompt vbCrLf & "Invalid Selection"
Exit Sub
Else
ent.Highlight True
End If

End With

ent.GetXData "", datType, datval
adelekey = Right(datval(0), Len(datval(0)) - 3)
...

The RIght method is where I am getting an error. but I have no trouble with
it on 60+ user PC include my own and 2 other test PCs.

Any help would be appreciated.

Vito
Message 3 of 14
Anonymous
in reply to: Anonymous

try explicitly calling your native VBA functions.
VBA.Right(...)

wrote in message news:5977128@discussion.autodesk.com...
Can't figure out why this code does not work on 2 of my user's PC
...
With ThisDrawing.Utility
.GetEntity ent, pickpt, vbCr & "Select an object: "
If ent Is Nothing Then
.Prompt vbCrLf & "Invalid Selection"
Exit Sub
Else
ent.Highlight True
End If

End With

ent.GetXData "", datType, datval
adelekey = Right(datval(0), Len(datval(0)) - 3)
...

The RIght method is where I am getting an error. but I have no trouble with it on 60+ user PC include my own and 2 other test PCs.

Any help would be appreciated.

Vito
Message 4 of 14
Anonymous
in reply to: Anonymous

that is the other odd part, the code is executed on a button click event and it throws the error as soon as the user clicks the button. It shouldn't be that far along in the code.
Message 5 of 14
rocheey
in reply to: Anonymous

I'd check the actual data TYPE that is being returned. Since you didnt seem to declare datType or datval, they are variants - and can hold just about anything. You might well be returning something other than a string ... like a coordinate, for instance.
Message 6 of 14
Anonymous
in reply to: Anonymous

Ding Ding Ding! We have a winner. That work perfectly. I have been researching DLLs all morning trying to see if the user's pc was out of date.

But by explicitly calling the VBA.Right method, it doubled my project size. No big deal but just curious on why.

Still pretty new at this, LISP is where I grew up.

Thanks a lot for your help
Message 7 of 14
Anonymous
in reply to: Anonymous

Hi Paul,
He said your solution worked but I'm surprised
I've never seen a situation where one had to preface inbuilt functions with
the library name
...unless you had local versions with a different definition

Sub TestRight()
Debug.Print Right("Somestring", 4)
Debug.Print VBA.Right$("Somestring", 4)
End Sub
Function Right(sInput As String, lVal As Long) As String
Right = "Local version"
End Function

but since it worked on many machines and not on one or two that tells me
that's not the case

he didn't specifiy the error but I'd bet it was function undefined or
however that reads
which you get on built-in funcitons (often string functions...usually Left
ro Left$ but also Right etc) when you have a reference missing...
that was my guess any way
which was apparently wrong because in that case adding the lib preface
wouldn't have fixed it....

so why did you think of that and why did it work???

mark


"Paul Richardson" wrote in message
news:5977140@discussion.autodesk.com...
try explicitly calling your native VBA functions.
VBA.Right(...)

wrote in message news:5977128@discussion.autodesk.com...
Can't figure out why this code does not work on 2 of my user's PC
...
With ThisDrawing.Utility
.GetEntity ent, pickpt, vbCr & "Select an object: "
If ent Is Nothing Then
.Prompt vbCrLf & "Invalid Selection"
Exit Sub
Else
ent.Highlight True
End If

End With

ent.GetXData "", datType, datval
adelekey = Right(datval(0), Len(datval(0)) - 3)
...

The RIght method is where I am getting an error. but I have no trouble with
it on 60+ user PC include my own and 2 other test PCs.

Any help would be appreciated.

Vito
Message 8 of 14
Anonymous
in reply to: Anonymous

Mark - I wish I could tell you why but had the same problem with code not running on a few machines
and breaking at the VBA string functions. I didn't have any local functions with the same name so I don't
know what the issue was - just that calling the VBA string functions explicitly solved the problem. I just
call all VBA functions explicitly now.

OP - Don't know why the file size doubled, strange. Must be something out there on the net,
please let us know if you find out.

"MP" wrote in message news:5977509@discussion.autodesk.com...
Hi Paul,
He said your solution worked but I'm surprised
I've never seen a situation where one had to preface inbuilt functions with
the library name
...unless you had local versions with a different definition

Sub TestRight()
Debug.Print Right("Somestring", 4)
Debug.Print VBA.Right$("Somestring", 4)
End Sub
Function Right(sInput As String, lVal As Long) As String
Right = "Local version"
End Function

but since it worked on many machines and not on one or two that tells me
that's not the case

he didn't specifiy the error but I'd bet it was function undefined or
however that reads
which you get on built-in funcitons (often string functions...usually Left
ro Left$ but also Right etc) when you have a reference missing...
that was my guess any way
which was apparently wrong because in that case adding the lib preface
wouldn't have fixed it....

so why did you think of that and why did it work???

mark


"Paul Richardson" wrote in message
news:5977140@discussion.autodesk.com...
try explicitly calling your native VBA functions.
VBA.Right(...)

wrote in message news:5977128@discussion.autodesk.com...
Can't figure out why this code does not work on 2 of my user's PC
...
With ThisDrawing.Utility
.GetEntity ent, pickpt, vbCr & "Select an object: "
If ent Is Nothing Then
.Prompt vbCrLf & "Invalid Selection"
Exit Sub
Else
ent.Highlight True
End If

End With

ent.GetXData "", datType, datval
adelekey = Right(datval(0), Len(datval(0)) - 3)
...

The RIght method is where I am getting an error. but I have no trouble with
it on 60+ user PC include my own and 2 other test PCs.

Any help would be appreciated.

Vito
Message 9 of 14
Anonymous
in reply to: Anonymous

Norman, Been playing with Brep.net? I've got Linq to xml working to serialize the topography
which was pretty easy on solids without curves - working on figuring out curved loops which is not so easy...)

"Norman Yuan" wrote in message news:5977138@discussion.autodesk.com...
Did you debug on that line of code to see what exact value is in datval(0)?
Or simply:

ent.GetXData "", datType, datval

Debug.Print "datval(0)=" & datval(0)
'or
MsgBox "datval(0)=" & datval(0)

adelekey = Right(datval(0), Len(datval(0)) - 3)

After seeing the value of datval(0), you would most likely have the answer.


"Vito" wrote in message news:5977128@discussion.autodesk.com...
Can't figure out why this code does not work on 2 of my user's PC
...
With ThisDrawing.Utility
.GetEntity ent, pickpt, vbCr & "Select an object: "
If ent Is Nothing Then
.Prompt vbCrLf & "Invalid Selection"
Exit Sub
Else
ent.Highlight True
End If

End With

ent.GetXData "", datType, datval
adelekey = Right(datval(0), Len(datval(0)) - 3)
...

The RIght method is where I am getting an error. but I have no trouble with
it on 60+ user PC include my own and 2 other test PCs.

Any help would be appreciated.

Vito
Message 10 of 14
Anonymous
in reply to: Anonymous

No, I do not have Acad2009/Map available, which is one of the consequence of
my office being mergered into a bigger company: it is not easy to get latest
release installed.

"Paul Richardson" wrote in message
news:5977601@discussion.autodesk.com...
Norman, Been playing with Brep.net? I've got Linq to xml working to
serialize the topography
which was pretty easy on solids without curves - working on figuring out
curved loops which is not so easy...)

"Norman Yuan" wrote in message
news:5977138@discussion.autodesk.com...
Did you debug on that line of code to see what exact value is in datval(0)?
Or simply:

ent.GetXData "", datType, datval

Debug.Print "datval(0)=" & datval(0)
'or
MsgBox "datval(0)=" & datval(0)

adelekey = Right(datval(0), Len(datval(0)) - 3)

After seeing the value of datval(0), you would most likely have the answer.


"Vito" wrote in message news:5977128@discussion.autodesk.com...
Can't figure out why this code does not work on 2 of my user's PC
...
With ThisDrawing.Utility
.GetEntity ent, pickpt, vbCr & "Select an object: "
If ent Is Nothing Then
.Prompt vbCrLf & "Invalid Selection"
Exit Sub
Else
ent.Highlight True
End If

End With

ent.GetXData "", datType, datval
adelekey = Right(datval(0), Len(datval(0)) - 3)
...

The RIght method is where I am getting an error. but I have no trouble with
it on 60+ user PC include my own and 2 other test PCs.

Any help would be appreciated.

Vito
Message 11 of 14
Anonymous
in reply to: Anonymous

Hi,

Wen I first started VBA programming I experienced issues with some of
the string commands. By adding "Option Explicit" to all forms and
modules, then running [Debug][Compile] I identified quirks in the code.
Once these were resolved I've never had a problem.


Regards

Laurie

Paul Richardson wrote:
> Mark - I wish I could tell you why but had the same problem with code not running on a few machines
> and breaking at the VBA string functions. I didn't have any local functions with the same name so I don't
> know what the issue was - just that calling the VBA string functions explicitly solved the problem. I just
> call all VBA functions explicitly now.
>
> OP - Don't know why the file size doubled, strange. Must be something out there on the net,
> please let us know if you find out.
>
> "MP" wrote in message news:5977509@discussion.autodesk.com...
> Hi Paul,
> He said your solution worked but I'm surprised
> I've never seen a situation where one had to preface inbuilt functions with
> the library name
> ...unless you had local versions with a different definition
>
> Sub TestRight()
> Debug.Print Right("Somestring", 4)
> Debug.Print VBA.Right$("Somestring", 4)
> End Sub
> Function Right(sInput As String, lVal As Long) As String
> Right = "Local version"
> End Function
>
> but since it worked on many machines and not on one or two that tells me
> that's not the case
>
> he didn't specifiy the error but I'd bet it was function undefined or
> however that reads
> which you get on built-in funcitons (often string functions...usually Left
> ro Left$ but also Right etc) when you have a reference missing...
> that was my guess any way
> which was apparently wrong because in that case adding the lib preface
> wouldn't have fixed it....
>
> so why did you think of that and why did it work???
>
> mark
>
>
> "Paul Richardson" wrote in message
> news:5977140@discussion.autodesk.com...
> try explicitly calling your native VBA functions.
> VBA.Right(...)
>
> wrote in message news:5977128@discussion.autodesk.com...
> Can't figure out why this code does not work on 2 of my user's PC
> ...
> With ThisDrawing.Utility
> .GetEntity ent, pickpt, vbCr & "Select an object: "
> If ent Is Nothing Then
> .Prompt vbCrLf & "Invalid Selection"
> Exit Sub
> Else
> ent.Highlight True
> End If
>
> End With
>
> ent.GetXData "", datType, datval
> adelekey = Right(datval(0), Len(datval(0)) - 3)
> ...
>
> The RIght method is where I am getting an error. but I have no trouble with
> it on 60+ user PC include my own and 2 other test PCs.
>
> Any help would be appreciated.
>
> Vito
Message 12 of 14
Anonymous
in reply to: Anonymous

I have done the Option Explicit and debug compile. I also test all my apps on 5 different PCs from a selected group of users in varies departments prior to deploying my apps. But the error only occurs on maybe 2% of the user base and it is always some kind of string function that throws the compile error.

Here is the oddest part, I have multiple forms using the same string functions and only one of them will blow up. I have spent a lot of time trying to track down the source of the problem but it still eludes me.

I have changed all my code to explicitly call the vba. string functions and had no further issues of this sort...so far.
Message 13 of 14
Anonymous
in reply to: Anonymous

Just a wild guess ... Help states that Acad VBA will be corrupted if MS
Office is installed/re-installed after Acad. Maybe this is part of the
"corruption" in your case?

Gary
Message 14 of 14
rocheey
in reply to: Anonymous

I've occasionally run into those types of 'odd' problems with VBA, especially ACAD VBA, and i remember particularly one time was because of a 'version incomparability' - the code was originally written on a box that had a newer version of acad, AND acad vba, installed... but then when the code was run on another box, that had the newer version of ACAD installed, but did NOT have the newer VBA installed as an option.

You might want to check the VBA references here. MY fix, at the time, was to export the source code to disk, and then re-import the code on a box with the earlier version VBA. The newer version VBA had no trouble running the new 'older' code, it was only the 'old' VBA running the 'newer' code that had given me trouble.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost