Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compile error in background color code in VBA

Status
Not open for further replies.

Charlie

Mechanical
Dec 28, 2015
15
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
 
Replies continue below

Recommended for you

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
 
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.
 
my code is working in V5 R24

Eric N.
indocti discant et ament meminisse periti
 
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

 
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
 
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
 
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
 
color(i) = CDbl(InputBox...) works for me

Eric N.
indocti discant et ament meminisse periti
 
Thanks a Lot guys for your help.It is working and helps me understand a lot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor