Type(s) 
Author Message
 Type(s)

Hi

I wonder if anyone can help will a coding problem I have.

In my Module I have 3 TYPE(s) declared.

In the form I can refer to these as:

Dim Fred1 as TYPE1
Dim Fred2 as TYPE2
Dim Fred3 as TYPE3

What I would like to do (and VB6 doesn't seem to want to let me) is to use
some code to address each of the 3 different types without having to code
for each type, for example:

if fred1.s1 = 2 then
 ............
end if

where s1 is common to all 3 types.

What I don't want to do is code for each of the differing types and then do
something like:

if fred1.s1 = 2 then

end if
if fred2.s1 = 2 then

end if
if fred3.s1 = 2 then

end if

What I would really like to is something like

if a=1 then
dim fred as type1
end if
if a=2 then
dim fred as type2
end if

etc but of course it won't let me do this as it says there are duplicate
declarions.

The Redim also doesn't work (at least the way I've tried it) as it just
gives a syntax error.



Sat, 30 Jul 2005 19:39:19 GMT  
 Type(s)
How about nesting the UDTs in one 'meta-UDT'

And just filling in the bits that you know about

Alternatively you could front the UDTs with Classes, and use
IMPLEMENTS so that common properties are exposed
- probably too messy

What are these UDTs ?
Perhaps 'packets' of data ?

On Tue, 11 Feb 2003 11:39:19 -0000, "john dingley"

Quote:

>Hi

>I wonder if anyone can help will a coding problem I have.

>In my Module I have 3 TYPE(s) declared.

>In the form I can refer to these as:

>Dim Fred1 as TYPE1
>Dim Fred2 as TYPE2
>Dim Fred3 as TYPE3

>What I would like to do (and VB6 doesn't seem to want to let me) is to use
>some code to address each of the 3 different types without having to code
>for each type, for example:

>if fred1.s1 = 2 then
> ............
>end if

>where s1 is common to all 3 types.

>What I don't want to do is code for each of the differing types and then do
>something like:

>if fred1.s1 = 2 then

>end if
>if fred2.s1 = 2 then

>end if
>if fred3.s1 = 2 then

>end if

>What I would really like to is something like

>if a=1 then
>dim fred as type1
>end if
>if a=2 then
>dim fred as type2
>end if

>etc but of course it won't let me do this as it says there are duplicate
>declarions.

>The Redim also doesn't work (at least the way I've tried it) as it just
>gives a syntax error.



Sat, 30 Jul 2005 20:59:17 GMT  
 Type(s)
I wish I knew what you are talking about :-(

Either you haven't understood the nature of Type declarations, or I haven't
understood your question (or perhaps both!). Post again saying *exactly*
what you wish to accomplish in your code (there may well be other ways of
doing it) and preferably include in your posting the relevant parts of your
existing code so that we can look at it.

Mike


Quote:
> Hi

> I wonder if anyone can help will a coding problem I have.

> In my Module I have 3 TYPE(s) declared.

> In the form I can refer to these as:

> Dim Fred1 as TYPE1
> Dim Fred2 as TYPE2
> Dim Fred3 as TYPE3

> What I would like to do (and VB6 doesn't seem to want to let me) is to use
> some code to address each of the 3 different types without having to code
> for each type, for example:

> if fred1.s1 = 2 then
>  ............
> end if

> where s1 is common to all 3 types.

> What I don't want to do is code for each of the differing types and then
do
> something like:

> if fred1.s1 = 2 then

> end if
> if fred2.s1 = 2 then

> end if
> if fred3.s1 = 2 then

> end if

> What I would really like to is something like

> if a=1 then
> dim fred as type1
> end if
> if a=2 then
> dim fred as type2
> end if

> etc but of course it won't let me do this as it says there are duplicate
> declarions.

> The Redim also doesn't work (at least the way I've tried it) as it just
> gives a syntax error.



Sat, 30 Jul 2005 22:36:27 GMT  
 Type(s)



Quote:
> Hi

> I wonder if anyone can help will a coding problem I have.

> In my Module I have 3 TYPE(s) declared.

> In the form I can refer to these as:

> Dim Fred1 as TYPE1
> Dim Fred2 as TYPE2
> Dim Fred3 as TYPE3

> What I would like to do (and VB6 doesn't seem to want to let me) is to use
> some code to address each of the 3 different types without having to code
> for each type, for example:

> if fred1.s1 = 2 then
>  ............
> end if

> where s1 is common to all 3 types.

> What I don't want to do is code for each of the differing types and then
do
> something like:

> if fred1.s1 = 2 then

> end if
> if fred2.s1 = 2 then

> end if
> if fred3.s1 = 2 then

> end if

> What I would really like to is something like

> if a=1 then
> dim fred as type1
> end if
> if a=2 then
> dim fred as type2
> end if

> etc but of course it won't let me do this as it says there are duplicate
> declarions.

> The Redim also doesn't work (at least the way I've tried it) as it just
> gives a syntax error.

Will it work with
If a = 1 Then
    Dim fred As Type1
ElseIf a = 2 Then
    Dim fred As Type2
ElseIf a = 3 Then
    Dim fred As Type3
End If
Haven't tested ;(
/Henning


Sat, 30 Jul 2005 23:19:06 GMT  
 Type(s)

Quote:



> > Hi

> > I wonder if anyone can help will a coding problem I have.

> > In my Module I have 3 TYPE(s) declared.

> > In the form I can refer to these as:

> > Dim Fred1 as TYPE1
> > Dim Fred2 as TYPE2
> > Dim Fred3 as TYPE3

> > What I would like to do (and VB6 doesn't seem to want to let me) is to use
> > some code to address each of the 3 different types without having to code
> > for each type, for example:

> > if fred1.s1 = 2 then
> >  ............
> > end if

> > where s1 is common to all 3 types.

> > What I don't want to do is code for each of the differing types and then
> do
> > something like:

> > if fred1.s1 = 2 then

> > end if
> > if fred2.s1 = 2 then

> > end if
> > if fred3.s1 = 2 then

> > end if

> > What I would really like to is something like

> > if a=1 then
> > dim fred as type1
> > end if
> > if a=2 then
> > dim fred as type2
> > end if

> > etc but of course it won't let me do this as it says there are duplicate
> > declarions.

> > The Redim also doesn't work (at least the way I've tried it) as it just
> > gives a syntax error.

> Will it work with
> If a = 1 Then
>     Dim fred As Type1
> ElseIf a = 2 Then
>     Dim fred As Type2
> ElseIf a = 3 Then
>     Dim fred As Type3
> End If

No, because allocation statements are <all> compiled before execution,
so this construction (as well as John's attempt) is that same as if
you'd written--

Dim fred As Type1
Dim fred As Type2
Dim fred As Type3
.
.
.
If a = 1 Then
ElseIf a = 2 Then
ElseIf a = 3 Then
End If

And this is obviously not allowed--

I think best is JFrench's suggestion to consolidate the Types into one
Mega-Type or to provide more incentive for what is <really> trying to
accomplish per Mike's suggestion...



Sat, 30 Jul 2005 23:31:58 GMT  
 Type(s)



Quote:




> > > Hi

> > > I wonder if anyone can help will a coding problem I have.

> > > In my Module I have 3 TYPE(s) declared.

> > > In the form I can refer to these as:

> > > Dim Fred1 as TYPE1
> > > Dim Fred2 as TYPE2
> > > Dim Fred3 as TYPE3

> > > What I would like to do (and VB6 doesn't seem to want to let me) is to
use
> > > some code to address each of the 3 different types without having to
code
> > > for each type, for example:

> > > if fred1.s1 = 2 then
> > >  ............
> > > end if

> > > where s1 is common to all 3 types.

> > > What I don't want to do is code for each of the differing types and
then
> > do
> > > something like:

> > > if fred1.s1 = 2 then

> > > end if
> > > if fred2.s1 = 2 then

> > > end if
> > > if fred3.s1 = 2 then

> > > end if

> > > What I would really like to is something like

> > > if a=1 then
> > > dim fred as type1
> > > end if
> > > if a=2 then
> > > dim fred as type2
> > > end if

> > > etc but of course it won't let me do this as it says there are
duplicate
> > > declarions.

> > > The Redim also doesn't work (at least the way I've tried it) as it
just
> > > gives a syntax error.

> > Will it work with
> > If a = 1 Then
> >     Dim fred As Type1
> > ElseIf a = 2 Then
> >     Dim fred As Type2
> > ElseIf a = 3 Then
> >     Dim fred As Type3
> > End If

> No, because allocation statements are <all> compiled before execution,
> so this construction (as well as John's attempt) is that same as if
> you'd written--

> Dim fred As Type1
> Dim fred As Type2
> Dim fred As Type3
> .
> .
> .
> If a = 1 Then
> ElseIf a = 2 Then
> ElseIf a = 3 Then
> End If

> And this is obviously not allowed--

> I think best is JFrench's suggestion to consolidate the Types into one
> Mega-Type or to provide more incentive for what is <really> trying to
> accomplish per Mike's suggestion...

As expected;(
He can also depending on a's value call three different subs/funcs. But as U
say it depends on...
/Henning


Sat, 30 Jul 2005 23:43:17 GMT  
 Type(s)

Quote:






> > > > Hi

> > > > I wonder if anyone can help will a coding problem I have.

> > > > In my Module I have 3 TYPE(s) declared.

> > > > In the form I can refer to these as:

> > > > Dim Fred1 as TYPE1
> > > > Dim Fred2 as TYPE2
> > > > Dim Fred3 as TYPE3

> > > > What I would like to do (and VB6 doesn't seem to want to let me) is to
> use
> > > > some code to address each of the 3 different types without having to
> code
> > > > for each type, for example:

> > > > if fred1.s1 = 2 then
> > > >  ............
> > > > end if

> > > > where s1 is common to all 3 types.

> > > > What I don't want to do is code for each of the differing types and
> then
> > > do
> > > > something like:

> > > > if fred1.s1 = 2 then

> > > > end if
> > > > if fred2.s1 = 2 then

> > > > end if
> > > > if fred3.s1 = 2 then

> > > > end if

> > > > What I would really like to is something like

> > > > if a=1 then
> > > > dim fred as type1
> > > > end if
> > > > if a=2 then
> > > > dim fred as type2
> > > > end if

> > > > etc but of course it won't let me do this as it says there are
> duplicate
> > > > declarions.

> > > > The Redim also doesn't work (at least the way I've tried it) as it
> just
> > > > gives a syntax error.

> > > Will it work with
> > > If a = 1 Then
> > >     Dim fred As Type1
> > > ElseIf a = 2 Then
> > >     Dim fred As Type2
> > > ElseIf a = 3 Then
> > >     Dim fred As Type3
> > > End If

> > No, because allocation statements are <all> compiled before execution,
> > so this construction (as well as John's attempt) is that same as if
> > you'd written--

> > Dim fred As Type1
> > Dim fred As Type2
> > Dim fred As Type3
> > .
> > .
> > .
> > If a = 1 Then
> > ElseIf a = 2 Then
> > ElseIf a = 3 Then
> > End If

> > And this is obviously not allowed--

> > I think best is JFrench's suggestion to consolidate the Types into one
> > Mega-Type or to provide more incentive for what is <really> trying to
> > accomplish per Mike's suggestion...

> As expected;(
> He can also depending on a's value call three different subs/funcs. But as U
> say it depends on...

Henning,
Yeah, I started to put that in as an option too, but decided it wasn't
worth it unless knew more...

Subject Switch/

You get anywhere on the time synch problem/issue?  I'm going to do some
looking for a good time server/client for WinXX today to solve my
problem wrt migration to NT from OS/2...I'm assuming they're out there,
you interested for your case if I come across something interesting?



Sat, 30 Jul 2005 23:54:34 GMT  
 Type(s)
This is a classic example of what "polymorphism"
in OO is all about

PseudoCode:

Public Interface SuperType {

    protected abstract string getS1();
    protected abstract void setS1(string s);

Quote:
}

public class Type1 implements SuperType {
    private string s1;

    protected string getS1()
    {
        return s1;
    }

    protected void setS1(string s){
    {
        s1 = s;
    }

Quote:
}

public class Type2 implements SuperType {
    private string s1;

    protected string getS1()
    {
        return s1;
    }

    protected void setS1(string s){
    {
        s1 = doSomethingWithInput(s);
    }

Quote:
}

// App code:
    if(a==2)
        Type2 fred = new Type2();
    else
        Type1 fred = new Type1();
    ...

    fred.setS1("Jalla");

--
Dag.

PS!
    Sorry for the Java-style, but thats what I
    *think*...


Quote:
> Hi

> I wonder if anyone can help will a coding problem I have.

> In my Module I have 3 TYPE(s) declared.

> In the form I can refer to these as:

> Dim Fred1 as TYPE1
> Dim Fred2 as TYPE2
> Dim Fred3 as TYPE3

> What I would like to do (and VB6 doesn't seem to want to let me) is to use
> some code to address each of the 3 different types without having to code
> for each type, for example:

> if fred1.s1 = 2 then
>  ............
> end if

> where s1 is common to all 3 types.

> What I don't want to do is code for each of the differing types and then
do
> something like:

> if fred1.s1 = 2 then

> end if
> if fred2.s1 = 2 then

> end if
> if fred3.s1 = 2 then

> end if

> What I would really like to is something like

> if a=1 then
> dim fred as type1
> end if
> if a=2 then
> dim fred as type2
> end if

> etc but of course it won't let me do this as it says there are duplicate
> declarions.

> The Redim also doesn't work (at least the way I've tried it) as it just
> gives a syntax error.



Sun, 31 Jul 2005 01:53:00 GMT  
 Type(s)
Its difficult to explain

Project A has 3 distinct UDTs that differ but have certain things in common,
eg

TYPEA
  fred as string
  bill as integer
END TYPE

TYPEB
  fred as string
  bill as integer
  ginger as string
END TYPE

TYPEC
  fred as string
  bill as integer
  tom as boolean
END TYPE
--------------------------------------------------------------
I want to use code from Project B which goes something like

if X.fred = "YM" then
 if X.bill=1 then
..................................
 end if
end if .........................hundreds of lines of code that uses the type

My problem is, I don't want to spend days having to modify code for all
three types if I can get away with

If a=1 then
  Dim X as TYPEA
end if
If a=2 then
  Dim X as TYPEB
end if
If a=3 then
  Dim X as TYPEC
end if

Then

if X.fred = "YM" then
 if X.bill=1 then
..................................
 end if
end if

would work. But of course I cannot do that.


Quote:







> > > > > Hi

> > > > > I wonder if anyone can help will a coding problem I have.

> > > > > In my Module I have 3 TYPE(s) declared.

> > > > > In the form I can refer to these as:

> > > > > Dim Fred1 as TYPE1
> > > > > Dim Fred2 as TYPE2
> > > > > Dim Fred3 as TYPE3

> > > > > What I would like to do (and VB6 doesn't seem to want to let me)
is to
> > use
> > > > > some code to address each of the 3 different types without having
to
> > code
> > > > > for each type, for example:

> > > > > if fred1.s1 = 2 then
> > > > >  ............
> > > > > end if

> > > > > where s1 is common to all 3 types.

> > > > > What I don't want to do is code for each of the differing types
and
> > then
> > > > do
> > > > > something like:

> > > > > if fred1.s1 = 2 then

> > > > > end if
> > > > > if fred2.s1 = 2 then

> > > > > end if
> > > > > if fred3.s1 = 2 then

> > > > > end if

> > > > > What I would really like to is something like

> > > > > if a=1 then
> > > > > dim fred as type1
> > > > > end if
> > > > > if a=2 then
> > > > > dim fred as type2
> > > > > end if

> > > > > etc but of course it won't let me do this as it says there are
> > duplicate
> > > > > declarions.

> > > > > The Redim also doesn't work (at least the way I've tried it) as it
> > just
> > > > > gives a syntax error.

> > > > Will it work with
> > > > If a = 1 Then
> > > >     Dim fred As Type1
> > > > ElseIf a = 2 Then
> > > >     Dim fred As Type2
> > > > ElseIf a = 3 Then
> > > >     Dim fred As Type3
> > > > End If

> > > No, because allocation statements are <all> compiled before execution,
> > > so this construction (as well as John's attempt) is that same as if
> > > you'd written--

> > > Dim fred As Type1
> > > Dim fred As Type2
> > > Dim fred As Type3
> > > .
> > > .
> > > .
> > > If a = 1 Then
> > > ElseIf a = 2 Then
> > > ElseIf a = 3 Then
> > > End If

> > > And this is obviously not allowed--

> > > I think best is JFrench's suggestion to consolidate the Types into one
> > > Mega-Type or to provide more incentive for what is <really> trying to
> > > accomplish per Mike's suggestion...

> > As expected;(
> > He can also depending on a's value call three different subs/funcs. But
as U
> > say it depends on...

> Henning,
> Yeah, I started to put that in as an option too, but decided it wasn't
> worth it unless knew more...

> Subject Switch/

> You get anywhere on the time synch problem/issue?  I'm going to do some
> looking for a good time server/client for WinXX today to solve my
> problem wrt migration to NT from OS/2...I'm assuming they're out there,
> you interested for your case if I come across something interesting?



Sun, 31 Jul 2005 03:03:13 GMT  
 Type(s)
One other thing - I cannot change the 3 type statements as they are
currently used to pass records between machines over the internet to a
programs expecting the data in a certain format. Otherwise my problem would
be easily sorted my combining all the elements into one type statement.

I just want to use some code written for something else without the need for
a massive editing excersise.


Quote:
> Its difficult to explain

> Project A has 3 distinct UDTs that differ but have certain things in
common,
> eg

> TYPEA
>   fred as string
>   bill as integer
> END TYPE

> TYPEB
>   fred as string
>   bill as integer
>   ginger as string
> END TYPE

> TYPEC
>   fred as string
>   bill as integer
>   tom as boolean
> END TYPE
> --------------------------------------------------------------
> I want to use code from Project B which goes something like

> if X.fred = "YM" then
>  if X.bill=1 then
> ..................................
>  end if
> end if .........................hundreds of lines of code that uses the
type

> My problem is, I don't want to spend days having to modify code for all
> three types if I can get away with

> If a=1 then
>   Dim X as TYPEA
> end if
> If a=2 then
>   Dim X as TYPEB
> end if
> If a=3 then
>   Dim X as TYPEC
> end if

> Then

> if X.fred = "YM" then
>  if X.bill=1 then
> ..................................
>  end if
> end if

> would work. But of course I cannot do that.









> > > > > > Hi

> > > > > > I wonder if anyone can help will a coding problem I have.

> > > > > > In my Module I have 3 TYPE(s) declared.

> > > > > > In the form I can refer to these as:

> > > > > > Dim Fred1 as TYPE1
> > > > > > Dim Fred2 as TYPE2
> > > > > > Dim Fred3 as TYPE3

> > > > > > What I would like to do (and VB6 doesn't seem to want to let me)
> is to
> > > use
> > > > > > some code to address each of the 3 different types without
having
> to
> > > code
> > > > > > for each type, for example:

> > > > > > if fred1.s1 = 2 then
> > > > > >  ............
> > > > > > end if

> > > > > > where s1 is common to all 3 types.

> > > > > > What I don't want to do is code for each of the differing types
> and
> > > then
> > > > > do
> > > > > > something like:

> > > > > > if fred1.s1 = 2 then

> > > > > > end if
> > > > > > if fred2.s1 = 2 then

> > > > > > end if
> > > > > > if fred3.s1 = 2 then

> > > > > > end if

> > > > > > What I would really like to is something like

> > > > > > if a=1 then
> > > > > > dim fred as type1
> > > > > > end if
> > > > > > if a=2 then
> > > > > > dim fred as type2
> > > > > > end if

> > > > > > etc but of course it won't let me do this as it says there are
> > > duplicate
> > > > > > declarions.

> > > > > > The Redim also doesn't work (at least the way I've tried it) as
it
> > > just
> > > > > > gives a syntax error.

> > > > > Will it work with
> > > > > If a = 1 Then
> > > > >     Dim fred As Type1
> > > > > ElseIf a = 2 Then
> > > > >     Dim fred As Type2
> > > > > ElseIf a = 3 Then
> > > > >     Dim fred As Type3
> > > > > End If

> > > > No, because allocation statements are <all> compiled before
execution,
> > > > so this construction (as well as John's attempt) is that same as if
> > > > you'd written--

> > > > Dim fred As Type1
> > > > Dim fred As Type2
> > > > Dim fred As Type3
> > > > .
> > > > .
> > > > .
> > > > If a = 1 Then
> > > > ElseIf a = 2 Then
> > > > ElseIf a = 3 Then
> > > > End If

> > > > And this is obviously not allowed--

> > > > I think best is JFrench's suggestion to consolidate the Types into
one
> > > > Mega-Type or to provide more incentive for what is <really> trying
to
> > > > accomplish per Mike's suggestion...

> > > As expected;(
> > > He can also depending on a's value call three different subs/funcs.
But
> as U
> > > say it depends on...

> > Henning,
> > Yeah, I started to put that in as an option too, but decided it wasn't
> > worth it unless knew more...

> > Subject Switch/

> > You get anywhere on the time synch problem/issue?  I'm going to do some
> > looking for a good time server/client for WinXX today to solve my
> > problem wrt migration to NT from OS/2...I'm assuming they're out there,
> > you interested for your case if I come across something interesting?



Sun, 31 Jul 2005 03:16:12 GMT  
 Type(s)
A better way, John, is to define three classes, rather than three user
defined types. Then you can use the Set statement to create an instance of
the appropriate class, with only a single Dim statement.

Dim fred as Object

If myVariable = 2 then
Set fred = New fred1
Else
Set fred = New fred2
End If

I don't use types, so don't know if the above will work with them. It might.

The code above uses late binding, which is less efficient - VB doesn't know
until the moment of creation what type of object fred is going to be. But
there are times when it's better than any of the alternatives. I use late
binding, for example, when generating one of tens of possible user-created
reports.

Nevertheless, and depending on the exact nature of what you're doing, I
agree that the idea of combining the similar types into a single type (or
class) is the best approach of all. That's the way I'd tackle it, almost
without thinking. Remember, you don't have to provide values for all the
properties of a type or class - only those that apply to a given instance of
it.


Quote:
> Hi

> I wonder if anyone can help will a coding problem I have.

> In my Module I have 3 TYPE(s) declared.

> In the form I can refer to these as:

> Dim Fred1 as TYPE1
> Dim Fred2 as TYPE2
> Dim Fred3 as TYPE3

> What I would like to do (and VB6 doesn't seem to want to let me) is to use
> some code to address each of the 3 different types without having to code
> for each type, for example:

> if fred1.s1 = 2 then
>  ............
> end if

> where s1 is common to all 3 types.

> What I don't want to do is code for each of the differing types and then
do
> something like:

> if fred1.s1 = 2 then

> end if
> if fred2.s1 = 2 then

> end if
> if fred3.s1 = 2 then

> end if

> What I would really like to is something like

> if a=1 then
> dim fred as type1
> end if
> if a=2 then
> dim fred as type2
> end if

> etc but of course it won't let me do this as it says there are duplicate
> declarions.

> The Redim also doesn't work (at least the way I've tried it) as it just
> gives a syntax error.



Sun, 31 Jul 2005 03:22:14 GMT  
 Type(s)
Unless you can somehow factor the code to call it as a subroutine with
the proper structure passed in, I don't think you can avoid recoding
it--at that point it's probably worth looking at restructuring the UDTs
to consolidate them to a more appropriate canonical form.

Well, I've been looking around and found that since UDTs can <not> be
assigned to Variants I don't see any "clever" way around it (in pure
VB).  I guess you <could> write a set of "wrappers" in C that
manipulated the actual object itself, but that's probably more effort
than rewriting the references as above...

Quote:

> Its difficult to explain

> Project A has 3 distinct UDTs that differ but have certain things in common,
> eg

> TYPEA
>   fred as string
>   bill as integer
> END TYPE

> TYPEB
>   fred as string
>   bill as integer
>   ginger as string
> END TYPE

> TYPEC
>   fred as string
>   bill as integer
>   tom as boolean
> END TYPE
> --------------------------------------------------------------
> I want to use code from Project B which goes something like

> if X.fred = "YM" then
>  if X.bill=1 then
> ..................................
>  end if
> end if .........................hundreds of lines of code that uses the type

> My problem is, I don't want to spend days having to modify code for all
> three types if I can get away with

> If a=1 then
>   Dim X as TYPEA
> end if
> If a=2 then
>   Dim X as TYPEB
> end if
> If a=3 then
>   Dim X as TYPEC
> end if

> Then

> if X.fred = "YM" then
>  if X.bill=1 then
> ..................................
>  end if
> end if

> would work. But of course I cannot do that.









> > > > > > Hi

> > > > > > I wonder if anyone can help will a coding problem I have.

> > > > > > In my Module I have 3 TYPE(s) declared.

> > > > > > In the form I can refer to these as:

> > > > > > Dim Fred1 as TYPE1
> > > > > > Dim Fred2 as TYPE2
> > > > > > Dim Fred3 as TYPE3

> > > > > > What I would like to do (and VB6 doesn't seem to want to let me)
> is to
> > > use
> > > > > > some code to address each of the 3 different types without having
> to
> > > code
> > > > > > for each type, for example:

> > > > > > if fred1.s1 = 2 then
> > > > > >  ............
> > > > > > end if

> > > > > > where s1 is common to all 3 types.

> > > > > > What I don't want to do is code for each of the differing types
> and
> > > then
> > > > > do
> > > > > > something like:

> > > > > > if fred1.s1 = 2 then

> > > > > > end if
> > > > > > if fred2.s1 = 2 then

> > > > > > end if
> > > > > > if fred3.s1 = 2 then

> > > > > > end if

> > > > > > What I would really like to is something like

> > > > > > if a=1 then
> > > > > > dim fred as type1
> > > > > > end if
> > > > > > if a=2 then
> > > > > > dim fred as type2
> > > > > > end if

> > > > > > etc but of course it won't let me do this as it says there are
> > > duplicate
> > > > > > declarions.

> > > > > > The Redim also doesn't work (at least the way I've tried it) as it
> > > just
> > > > > > gives a syntax error.

> > > > > Will it work with
> > > > > If a = 1 Then
> > > > >     Dim fred As Type1
> > > > > ElseIf a = 2 Then
> > > > >     Dim fred As Type2
> > > > > ElseIf a = 3 Then
> > > > >     Dim fred As Type3
> > > > > End If

> > > > No, because allocation statements are <all> compiled before execution,
> > > > so this construction (as well as John's attempt) is that same as if
> > > > you'd written--

> > > > Dim fred As Type1
> > > > Dim fred As Type2
> > > > Dim fred As Type3
> > > > .
> > > > .
> > > > .
> > > > If a = 1 Then
> > > > ElseIf a = 2 Then
> > > > ElseIf a = 3 Then
> > > > End If

> > > > And this is obviously not allowed--

> > > > I think best is JFrench's suggestion to consolidate the Types into one
> > > > Mega-Type or to provide more incentive for what is <really> trying to
> > > > accomplish per Mike's suggestion...

> > > As expected;(
> > > He can also depending on a's value call three different subs/funcs. But
> as U
> > > say it depends on...

> > Henning,
> > Yeah, I started to put that in as an option too, but decided it wasn't
> > worth it unless knew more...

> > Subject Switch/

> > You get anywhere on the time synch problem/issue?  I'm going to do some
> > looking for a good time server/client for WinXX today to solve my
> > problem wrt migration to NT from OS/2...I'm assuming they're out there,
> > you interested for your case if I come across something interesting?



Sun, 31 Jul 2005 03:50:19 GMT  
 Type(s)
Even here, John, you could still use a single type, and incorporate a
property called SubType or whatever. When sending the data, use the Subtype
property value to determine how to format.

Select Case fred.SubType
    Case 1
    ' Format data one way
    Case 2
    ' Format data another way
    ' etc
    End Select

It really depends how similar the three types are in other respects, but if
the answer is 'very' then that's the way I'd go.

See my previous post for an alternative but less efficient solution if
you're still not convinced.


Quote:
> One other thing - I cannot change the 3 type statements as they are
> currently used to pass records between machines over the internet to a
> programs expecting the data in a certain format. Otherwise my problem
would
> be easily sorted my combining all the elements into one type statement.

> I just want to use some code written for something else without the need
for
> a massive editing excersise.



> > Its difficult to explain

> > Project A has 3 distinct UDTs that differ but have certain things in
> common,
> > eg

> > TYPEA
> >   fred as string
> >   bill as integer
> > END TYPE

> > TYPEB
> >   fred as string
> >   bill as integer
> >   ginger as string
> > END TYPE

> > TYPEC
> >   fred as string
> >   bill as integer
> >   tom as boolean
> > END TYPE
> > --------------------------------------------------------------
> > I want to use code from Project B which goes something like

> > if X.fred = "YM" then
> >  if X.bill=1 then
> > ..................................
> >  end if
> > end if .........................hundreds of lines of code that uses the
> type

> > My problem is, I don't want to spend days having to modify code for all
> > three types if I can get away with

> > If a=1 then
> >   Dim X as TYPEA
> > end if
> > If a=2 then
> >   Dim X as TYPEB
> > end if
> > If a=3 then
> >   Dim X as TYPEC
> > end if

> > Then

> > if X.fred = "YM" then
> >  if X.bill=1 then
> > ..................................
> >  end if
> > end if

> > would work. But of course I cannot do that.









> > > > > > > Hi

> > > > > > > I wonder if anyone can help will a coding problem I have.

> > > > > > > In my Module I have 3 TYPE(s) declared.

> > > > > > > In the form I can refer to these as:

> > > > > > > Dim Fred1 as TYPE1
> > > > > > > Dim Fred2 as TYPE2
> > > > > > > Dim Fred3 as TYPE3

> > > > > > > What I would like to do (and VB6 doesn't seem to want to let
me)
> > is to
> > > > use
> > > > > > > some code to address each of the 3 different types without
> having
> > to
> > > > code
> > > > > > > for each type, for example:

> > > > > > > if fred1.s1 = 2 then
> > > > > > >  ............
> > > > > > > end if

> > > > > > > where s1 is common to all 3 types.

> > > > > > > What I don't want to do is code for each of the differing
types
> > and
> > > > then
> > > > > > do
> > > > > > > something like:

> > > > > > > if fred1.s1 = 2 then

> > > > > > > end if
> > > > > > > if fred2.s1 = 2 then

> > > > > > > end if
> > > > > > > if fred3.s1 = 2 then

> > > > > > > end if

> > > > > > > What I would really like to is something like

> > > > > > > if a=1 then
> > > > > > > dim fred as type1
> > > > > > > end if
> > > > > > > if a=2 then
> > > > > > > dim fred as type2
> > > > > > > end if

> > > > > > > etc but of course it won't let me do this as it says there are
> > > > duplicate
> > > > > > > declarions.

> > > > > > > The Redim also doesn't work (at least the way I've tried it)
as
> it
> > > > just
> > > > > > > gives a syntax error.

> > > > > > Will it work with
> > > > > > If a = 1 Then
> > > > > >     Dim fred As Type1
> > > > > > ElseIf a = 2 Then
> > > > > >     Dim fred As Type2
> > > > > > ElseIf a = 3 Then
> > > > > >     Dim fred As Type3
> > > > > > End If

> > > > > No, because allocation statements are <all> compiled before
> execution,
> > > > > so this construction (as well as John's attempt) is that same as
if
> > > > > you'd written--

> > > > > Dim fred As Type1
> > > > > Dim fred As Type2
> > > > > Dim fred As Type3
> > > > > .
> > > > > .
> > > > > .
> > > > > If a = 1 Then
> > > > > ElseIf a = 2 Then
> > > > > ElseIf a = 3 Then
> > > > > End If

> > > > > And this is obviously not allowed--

> > > > > I think best is JFrench's suggestion to consolidate the Types into
> one
> > > > > Mega-Type or to provide more incentive for what is <really> trying
> to
> > > > > accomplish per Mike's suggestion...

> > > > As expected;(
> > > > He can also depending on a's value call three different subs/funcs.
> But
> > as U
> > > > say it depends on...

> > > Henning,
> > > Yeah, I started to put that in as an option too, but decided it wasn't
> > > worth it unless knew more...

> > > Subject Switch/

> > > You get anywhere on the time synch problem/issue?  I'm going to do
some
> > > looking for a good time server/client for WinXX today to solve my
> > > problem wrt migration to NT from OS/2...I'm assuming they're out
there,
> > > you interested for your case if I come across something interesting?



Sun, 31 Jul 2005 03:58:07 GMT  
 Type(s)

OO..h brother... let me play too then.

This is a classic example of what C without OO is all about.
PseudoCode too :)      

void handleanything (void* f, long iType )
{
        void *ff;

        switch(iType)
        {
                case 1 :
                        ff = (FRED1*) f;
                        strcpy(ff->s, "boo");
                case 2:
                        ff = (FRED2*) f;
                        ff->s = 100;
                case 3:
                        ff = (FRED3*) f;
                etc..
        }

Quote:
}

Sowwy,  Joe's cats attacked my keyboard. ;-p

Quote:
>This is a classic example of what "polymorphism"
>in OO is all about

>PseudoCode:

>Public Interface SuperType {

>    protected abstract string getS1();
>    protected abstract void setS1(string s);
>}

>public class Type1 implements SuperType {
>    private string s1;

>    protected string getS1()
>    {
>        return s1;
>    }

>    protected void setS1(string s){
>    {
>        s1 = s;
>    }
>}

>public class Type2 implements SuperType {
>    private string s1;

>    protected string getS1()
>    {
>        return s1;
>    }

>    protected void setS1(string s){
>    {
>        s1 = doSomethingWithInput(s);
>    }
>}

>// App code:
>    if(a==2)
>        Type2 fred = new Type2();
>    else
>        Type1 fred = new Type1();
>    ...

>    fred.setS1("Jalla");

>--
>Dag.

>PS!
>    Sorry for the Java-style, but thats what I
>    *think*...



>> Hi

>> I wonder if anyone can help will a coding problem I have.

>> In my Module I have 3 TYPE(s) declared.

>> In the form I can refer to these as:

>> Dim Fred1 as TYPE1
>> Dim Fred2 as TYPE2
>> Dim Fred3 as TYPE3

>> What I would like to do (and VB6 doesn't seem to want to let me) is to use
>> some code to address each of the 3 different types without having to code
>> for each type, for example:

>> if fred1.s1 = 2 then
>>  ............
>> end if

>> where s1 is common to all 3 types.

>> What I don't want to do is code for each of the differing types and then
>do
>> something like:

>> if fred1.s1 = 2 then

>> end if
>> if fred2.s1 = 2 then

>> end if
>> if fred3.s1 = 2 then

>> end if

>> What I would really like to is something like

>> if a=1 then
>> dim fred as type1
>> end if
>> if a=2 then
>> dim fred as type2
>> end if

>> etc but of course it won't let me do this as it says there are duplicate
>> declarions.

>> The Redim also doesn't work (at least the way I've tried it) as it just
>> gives a syntax error.

--

Regards, Frank



Sun, 31 Jul 2005 04:04:50 GMT  
 Type(s)


Quote:
> Unless you can somehow factor the code to call it as a subroutine with
> the proper structure passed in, I don't think you can avoid recoding
> it--at that point it's probably worth looking at restructuring the UDTs
> to consolidate them to a more appropriate canonical form.

> Well, I've been looking around and found that since UDTs can <not> be
> assigned to Variants

Actually, I think they can if they are defined in a public class module...
To clarify that means the UDT must be defined in a class module in a DLL, AX
Exe, UserControl, that is defined with public instancing....

Tom Shelton



Sun, 31 Jul 2005 04:13:23 GMT  
 
 [ 22 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Prob. w\ TYPE data type: err:Type Mismatch

2. object is not valid for type textbox and type textbox

3. Getting the basic [Type] of an array [Type[]]

4. Using types in a different assembly given that the type may be used or not used

5. object type cannot be converted to target type

6. Convert array of value type to array of reference type

7. object type cannot be converted to target type

8. how to convert INT type to UINT16 type?

9. Inheritance and Converting base types to child types

10. How to read Excel cells data types without Variant types

11. Get error: Disallowed implicit conversion from data type varchar to data type money

12. MBF vs TYPE...END TYPE problems

 

 
Powered by phpBB® Forum Software