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
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
dim mycatia
set mycatia = CATIA
then I can do
dim color (2)
mycatia.ActiveWindow.ActiveViewer.GetBackgroundColor color
indocti discant et ament meminisse periti
RE: Compile error in background color code in VBA
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
indocti discant et ament meminisse periti
RE: Compile error in background color code in VBA
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
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
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
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
indocti discant et ament meminisse periti
RE: Compile error in background color code in VBA