Duplicate Declaration Alert

Duplicate Declaration Alert

Anonymous
Not applicable
592 Views
7 Replies
Message 1 of 8

Duplicate Declaration Alert

Anonymous
Not applicable
I am trying to make my schedule program more streamline but I am having a
problem Declaring a variable when it comes to the different Objects.

since there are several types of objects that can have Schedule data, in
Arch Desktop, I want
this code to work for all.

If TypeOf obj Is AecDoor Or TypeOf obj Is AecSpace Then
If TypeOf obj Is AecDoor Then
Dim AecObj As AecDoor
End If
If TypeOf obj Is AecSpace Then
Dim AecObj As AecSpace
End If

When I try this I get a Duplicate Declaration Alert. How can I simplify
this so I can dim the AecObj as whatever Object was selected?

Additionally is there a way to do somthing like this.

dim AecObj as TypeOf Obj

this would be so that AecObj would be declared as the TypeOf object
selected. I tried this code and it will not allow it.

Thanks

--
Rob Starz
rob@stardsign.com
Plogv 3.0 & 2000 (plot logging) for r14 & 2000
***Enhancement Tools for Arch. Desktop FREE!!!!*****
http://www.stardsign.com/main.htm
StarDsign cad solution
0 Likes
593 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable
Hi Rob,
You can 't do that! Dim statements are compiled BEFORE the code runs, no
matter where they are located in the code,
and you can't declare the same variable twice.
But you could do this...

Public Sub TestTheMoJo()
Dim varPnt As Variant
Dim objEnt As AcadEntity
Dim objText As Variant
Dim strPrmt As String
On Error GoTo Err_Control
strPrmt = vbCrLf & "select an MText or Text entity: "
ThisDrawing.Utility.GetEntity objEnt, varPnt, strPrmt
If TypeOf objEnt Is AcadMText Then
ReDim objText(0) As AcadMText
Set objText(0) = objEnt
MsgBox objText(0).TextString
ElseIf TypeOf objEnt Is AcadText Then
ReDim objText(0) As AcadText
Set objText(0) = objEnt
MsgBox objText(0).TextString
Else
MsgBox "You didn't read the prompt!" & vbCr & _
"Select TEXT or MTEXT only!"
End If
Exit_Here:
Exit Sub
Err_Control:
'Just dump out for this example
Err.Clear
Resume Exit_Here
End Sub

Randall Rath
VB Design
http://www.vbdesign.net/cadpages
Home of the Wonder Llama
Who is Randall Rath?
Randall Rath is a former Tibetan Monk who, due to his obsession with
the number 42, decided to retire from the peace and quite of the Order.
To quantify his calling in life, he decided to devote the hours between
4:42 a.m. and 14:42 p.m. to the study of Visual Basic and AutoCAD.
Randall publishes a daily Newsletter entitled 'Acad - A Code a Day'
in which he explains some of the intracies of VB and AutoCAD.
He has very kindly allowed me (after the threat of deadly force) to publish
a
selection of his Newsletters on this site.
o--- Kenny Ramage, Afralisp http://afralisp.hypermart.net
0 Likes
Message 3 of 8

Anonymous
Not applicable
I will give this a try. Is there anywhat to get the TypeOf variable to a
string...like

Dim ObjType as string
ObjType = TypeOf Obj

This would be the easiest because I need to set variables withing a function
without going through all the additional code.

Thanks for th info.

--
Rob Starz
rob@stardsign.com
Plogv 3.0 & 2000 (plot logging) for r14 & 2000
***Enhancement Tools for Arch. Desktop FREE!!!!*****
http://www.stardsign.com/main.htm
StarDsign cad solution
"Randall Rath" wrote in message
news:ECF967E36667C0B274EA8367898B802D@in.WebX.maYIadrTaRb...
> Hi Rob,
> You can 't do that! Dim statements are compiled BEFORE the code runs, no
> matter where they are located in the code,
> and you can't declare the same variable twice.
> But you could do this...
>
> Public Sub TestTheMoJo()
> Dim varPnt As Variant
> Dim objEnt As AcadEntity
> Dim objText As Variant
> Dim strPrmt As String
> On Error GoTo Err_Control
> strPrmt = vbCrLf & "select an MText or Text entity: "
> ThisDrawing.Utility.GetEntity objEnt, varPnt, strPrmt
> If TypeOf objEnt Is AcadMText Then
> ReDim objText(0) As AcadMText
> Set objText(0) = objEnt
> MsgBox objText(0).TextString
> ElseIf TypeOf objEnt Is AcadText Then
> ReDim objText(0) As AcadText
> Set objText(0) = objEnt
> MsgBox objText(0).TextString
> Else
> MsgBox "You didn't read the prompt!" & vbCr & _
> "Select TEXT or MTEXT only!"
> End If
> Exit_Here:
> Exit Sub
> Err_Control:
> 'Just dump out for this example
> Err.Clear
> Resume Exit_Here
> End Sub
>
> Randall Rath
> VB Design
> http://www.vbdesign.net/cadpages
> Home of the Wonder Llama
> Who is Randall Rath?
> Randall Rath is a former Tibetan Monk who, due to his obsession with
> the number 42, decided to retire from the peace and quite of the Order.
> To quantify his calling in life, he decided to devote the hours between
> 4:42 a.m. and 14:42 p.m. to the study of Visual Basic and AutoCAD.
> Randall publishes a daily Newsletter entitled 'Acad - A Code a Day'
> in which he explains some of the intracies of VB and AutoCAD.
> He has very kindly allowed me (after the threat of deadly force) to
publish
> a
> selection of his Newsletters on this site.
> o--- Kenny Ramage, Afralisp http://afralisp.hypermart.net
>
0 Likes
Message 4 of 8

Anonymous
Not applicable
From VBA Help: Select Case may be more useful when evaluating a single
expression that has several possible actions. However, the TypeOf objectname
Is objecttype clause can't be used with the Select Case statement.

You really don't have to do all that, simply declare As Object. The downside
to this is that within the development environment; once you've typed the
variable name and '.' the properties won't automatically display for you.
They are all still available, though.

You could also write a function with a huge gob of 'If Typeof obj is ...'
statements to return the string you want.

John Pullen

"Rob Starz" wrote in message
news:4EFA1CD8F84B22328857F4B7BCBAA96C@in.WebX.maYIadrTaRb...
> I will give this a try. Is there anywhat to get the TypeOf variable to a
> string...like
>
> Dim ObjType as string
> ObjType = TypeOf Obj
>
> This would be the easiest because I need to set variables withing a
function
> without going through all the additional code.
>
> Thanks for th info.
>
> --
> Rob Starz
> rob@stardsign.com
> Plogv 3.0 & 2000 (plot logging) for r14 & 2000
> ***Enhancement Tools for Arch. Desktop FREE!!!!*****
> http://www.stardsign.com/main.htm
> StarDsign cad solution
> "Randall Rath" wrote in message
> news:ECF967E36667C0B274EA8367898B802D@in.WebX.maYIadrTaRb...
> > Hi Rob,
> > You can 't do that! Dim statements are compiled BEFORE the code runs, no
> > matter where they are located in the code,
> > and you can't declare the same variable twice.
> > But you could do this...
> >
> > Public Sub TestTheMoJo()
> > Dim varPnt As Variant
> > Dim objEnt As AcadEntity
> > Dim objText As Variant
> > Dim strPrmt As String
> > On Error GoTo Err_Control
> > strPrmt = vbCrLf & "select an MText or Text entity: "
> > ThisDrawing.Utility.GetEntity objEnt, varPnt, strPrmt
> > If TypeOf objEnt Is AcadMText Then
> > ReDim objText(0) As AcadMText
> > Set objText(0) = objEnt
> > MsgBox objText(0).TextString
> > ElseIf TypeOf objEnt Is AcadText Then
> > ReDim objText(0) As AcadText
> > Set objText(0) = objEnt
> > MsgBox objText(0).TextString
> > Else
> > MsgBox "You didn't read the prompt!" & vbCr & _
> > "Select TEXT or MTEXT only!"
> > End If
> > Exit_Here:
> > Exit Sub
> > Err_Control:
> > 'Just dump out for this example
> > Err.Clear
> > Resume Exit_Here
> > End Sub
> >
> > Randall Rath
> > VB Design
> > http://www.vbdesign.net/cadpages
> > Home of the Wonder Llama
> > Who is Randall Rath?
> > Randall Rath is a former Tibetan Monk who, due to his obsession with
> > the number 42, decided to retire from the peace and quite of the Order.
> > To quantify his calling in life, he decided to devote the hours between
> > 4:42 a.m. and 14:42 p.m. to the study of Visual Basic and AutoCAD.
> > Randall publishes a daily Newsletter entitled 'Acad - A Code a Day'
> > in which he explains some of the intracies of VB and AutoCAD.
> > He has very kindly allowed me (after the threat of deadly force) to
> publish
> > a
> > selection of his Newsletters on this site.
> > o--- Kenny Ramage, Afralisp http://afralisp.hypermart.net
> >
>
0 Likes
Message 5 of 8

Anonymous
Not applicable
Does anyone know how to accomplish this without getting the "duplicate
declaration in current scope" error message.

If fl_BeadType = dyOvalo Then
Dim lo_TDL As New
clsTDL_Ovalo
ElseIf fl_BeadType = dyOgee Then
Dim lo_TDL As New
clsTDL_Ogee
ElseIf fl_BeadType = dyStandard Then
Dim lo_TDL As New clsTDL_Std
End If

It would save me a heck of alot of space in my app.

Thanks,

Dale
0 Likes
Message 6 of 8

Anonymous
Not applicable
Hey! Does anyone know why the subject to my original post would have a Re:
in front of it when it is a first post. The subject I typed was "Duplicate
Declaration", not "Duplicate Declaration Alert".

Just curious,

Dale
0 Likes
Message 7 of 8

Anonymous
Not applicable
Thanks anyway, I got it.

Dale
0 Likes
Message 8 of 8

Anonymous
Not applicable
Hi Dale,
Assuming that you placed the declaration one time at the beginning of the
sub to fix the problem, I'll add a little - It's Friday, things are slow 😉
You can also increase the scope of the variable by placing it at the top
of the code window, which will allow you to use it in every sub wihtin
that window:

dim myvariable as variant

sub thisSub()

end sub

sub thatSub()

end sub

Or if you really want to save space, create a standard module and declare
it as public. Then you can use it anywhere in the project, in any form
or module, and it retains it's value (it becomes static) until the
project is unloaded:

public myvariable as variant 'can be used anywhere

And finally, you can just not declare it. SSHhhhh!!!! Don't tell anyone I
said that 🙂 As long as there's not an "option explicit" statement at
the top of your code window, you don't need to declare variables in vb.
But you will lose the benefit of catching typos at run time:

sub noDefinition()
myvariable = 10
msgbox myvarable
end sub

The sub above will return an empty msgbox because "myvariable" was set to
10, but the typo "myvarable" creates a new variable that has not had a
value assigned to it.

Better late than never,
-Josh


Dale Levesque wrote:

> Thanks anyway, I got it.
>
> Dale
>
>
>
0 Likes