×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Compile error in background color code in VBA

Compile error in background color code in VBA

Compile error in background color code in VBA

(OP)
I have made this program in VBA and i am getting color value of background but it showing compile error there that"Function or interface marked as restricted or the function uses an automation type not supported in visual basic".Can you give the reason of error??

This is working in CATScript but giving error in VBA
My program is as below

Sub CATMain()

Dim backgroundview As Viewer3D
Set backgroundview = CATIA.ActiveWindow.ActiveViewer


'get the value of background color
Dim color(2)
backgroundview.GetBackgroundColor (color)

MsgBox color(0)
MsgBox color(1)
MsgBox color(2)

End Sub

RE: Compile error in background color code in VBA

I usually trick the system with:

dim mycatia
set mycatia = CATIA

then I can do

dim color (2)
mycatia.ActiveWindow.ActiveViewer.GetBackgroundColor color



Eric N.
indocti discant et ament meminisse periti

RE: Compile error in background color code in VBA

(OP)
you are creating object for CATIA application object and i am using directly . what effect does it make on error.
Error remains same. One more thing error comes on line 1 i.e. Sub CATMain().
if it is showing error on sub function how it will execute statements inside function.

RE: Compile error in background color code in VBA

my code is working in V5 R24

Eric N.
indocti discant et ament meminisse periti

RE: Compile error in background color code in VBA

hey deepakmangal.... you are getting error because color array is passed as CATSafeArrayVariant, which is not available in VBA. so you are using it as normal array type.

to run code remove defined type from the definition of viewer3d..
below code will run, please check

Sub CATMain()


Dim backgroundview
Set backgroundview = CATIA.ActiveWindow.ActiveViewer


'get the value of background color
Dim color(2)
backgroundview.GetBackgroundColor color

MsgBox color(0)
MsgBox color(1)
MsgBox color(2)

End Sub

RE: Compile error in background color code in VBA

(OP)
It is working But
if i want to enter the value of color array from user then it is taking in as string even when you enter number so give a error 'type mismatch'. if I make color as double function Putbackground color will give error. how can this be solved.

My program is as below:

Sub CATMain()

Dim i As Integer
Dim color(2)
Dim backgroundview
Set backgroundview = CATIA.ActiveWindow.ActiveViewer
For i = 0 To 2 Step 1
color(i) = InputBox("Enter RGB value for color between 0 and 1:" & (i + 1), "Enter you value:")
If ((color(i) < 0) Or (color(i) > 1)) Then
MsgBox ("Enter valid value between 0 & 1 !!!")
i = i - 1
End If
Next
MsgBox color(0) & " " & color(1) & " " & color(2)
MsgBox TypeName(color(0))
backgroundview.PutBackgroundColor color
End Sub

RE: Compile error in background color code in VBA

use below code to set value....
you have to pass integer array.



Sub CATMain()

Dim i As Integer
Dim color(2)
Dim backgroundview
Set backgroundview = CATIA.ActiveWindow.ActiveViewer
For i = 0 To 2 Step 1
color(i) = InputBox("Enter RGB value for color between 0 and 1:" & (i + 1), "Enter you value:")
If ((color(i) < 0) Or (color(i) > 1)) Then
MsgBox ("Enter valid value between 0 & 1 !!!")
i = i - 1
End If
Next
MsgBox color(0) & " " & color(1) & " " & color(2)
MsgBox TypeName(color(0))
backgroundview.PutBackgroundColor Array(CInt(color(0)), CInt(color(0)), CInt(color(0)))
End Sub

RE: Compile error in background color code in VBA

above code is not visible... check this

Sub CATMain()

Dim i As Integer
Dim color(2)
Dim backgroundview
Set backgroundview = CATIA.ActiveWindow.ActiveViewer
For i = 0 To 2 Step 1
color(i) = InputBox("Enter RGB value for color between 0 and 1:" & (i + 1), "Enter you value:")
If ((color(i) < 0) Or (color(i) > 1)) Then
MsgBox ("Enter valid value between 0 & 1 !!!")
i = i - 1
End If
Next
MsgBox color(0) & " " & color(1) & " " & color(2)
MsgBox TypeName(color(0))
backgroundview.PutBackgroundColor Array(CInt(color(0)), CInt(color(0)), CInt(color(0)))
End Sub

RE: Compile error in background color code in VBA

color(i) = CDbl(InputBox...) works for me

Eric N.
indocti discant et ament meminisse periti

RE: Compile error in background color code in VBA

(OP)
Thanks a Lot guys for your help.It is working and helps me understand a lot.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources