I'm working with the interface to a legacy VMS system. Data records are
returned in a string of format "FileChannel & vbNL & RecordData". This
interface can return multiple records per call and each record can
potentially be from a different channel. I need to be able to do the
following:
dim basechannel as somechannel ' SomeChannel is an object that is created
based on the VMS RMS File definition, which I have access to and have a VB 6
cross compiler that generates the .NET VB2005 class object. (RMS allows
overlapping field layouts)
dim haveObjType2 as boolean = false
for each s as string in LegacyInterface.GetData(<VMSChannelStart>,
<lookupcriteria>, <NumberToGet>)
dim channel as string = LegacyInterface.GetChannel(s)
if ChannelType1.Channel = channel and haveObjType2 then
' Process ChannelType1 data only if ChannelType2 data has been found
dim objType1 as new ChannelType1(s)
' Do something with objType1
case ChannelType2.Channel:
dim objType2 as new ChannelType2(s)
haveObjType2 = true
' Do something with it
LegacyInterface.Update(objType2.Channel, objType2.buffer)
case ChannelType3.Channel
' not needed either
end select
next s
Why go through the overhead of creating non-required types. Also, in some
cases, I may have to create objType1 depending on what is returned in
objType2. I didn't design the underlying RMS database structure - it's not
even 1st Normal form. Note that I ALWAYS use Option Strict On and Option
Explicit On. I've had too many experiences where VB 6 didn't pick up a type
cast failure at compile time and the application didn't work as expected. I
want the compiler to tell me when there is a type casting problem.
Here's a sample of the output of the RMS cross compiler:
Option Explicit On
Option Strict On
Option Compare Text
Public Class COMMENT4
' Created with DefToCls v.4.1.10
' Created on #11/11/2005 1:58:33 PM#
' VMS Source File has VBTags
' VMS Source File Header for \\JAGUAR\VMSDEVHOME\def\4COMMENT.DEF
' !
' !TITLE: WA$SOURCE:4COMMENT.DEF
' !
' !22-DEC-95 NSB CREATED NEW DEF
' !31-MAY-96 MVD CHANGE COMMENT_TYPE TO 3 CHAR
' !01-AUG-96 MVD CHANGE COMMENT_TYPE TO 5 CHAR AND MOVE TO KEY
' !07-AUG-96 MVD CHANGE DATE TO 10 CHARACTERS
' !4-MAR-97 NSB ADDED SUB_TYPES VARIANT AND DOCUMENTAION
' !16-JAN-99 NSB MODIFIED TO THE FINAL FORMAT
' !
' ! THE NEW FORMAT
' !
' ! VB_CHANNEL=COMMENT
' ! VB_RECORD_LENGTH=105
' !
' RECORD TYPE$_4COMMENT
Public Const RecSize as Integer = 105
Private buffer As String
Public Sub New()
init
End Sub
Public Sub New(ByVal value As String)
buffer = LSet(value, 105)
End Sub
Public Sub init()
buffer = Space(105)
End Sub
' These two functions are to keep the code later simpler to read
Private Function fetch(ByVal start As Integer, ByVal chars As Integer) As
String
fetch = Mid(buffer, start, chars)
End Function
Private Sub putch(ByRef s As String, ByVal start As Integer, ByVal chars
As Integer)
Mid(buffer, start, chars) = LSet(s, chars)
End Sub
' VAX Channels
Public Const Channel as String = "COMMENT"
'DBServer Key Fields
Public Const VBKey_KEY0 as String = "KEY0"
'Key ACCT_NUM not in .OPN file
Public Const VBKey_ACCT_NUM as String = "ACCT_NUM"
'DBServer Data Fields
Public Property BUF() as String
Get
Return fetch(1, 105)
End Get
Set(ByVal value as string)
putch(value, 1, 105)
End Set
End Property
Public Property KEY0() as String
Get
Return fetch(1, 19)
End Get
Set(ByVal value as string)
putch(value, 1, 19)
End Set
End Property
' Multiple fields cut out - they follow the same code sequence as BUF and
KEY0
'Formatted Print Property
Public Shadows ReadOnly Property ToString(Optional ByVal prefix As String =
"", Optional ByVal indent As Boolean = False) As String
Get
Dim IndentChar As String
If indent Then IndentChar = vbTab Else IndentChar = ""
Dim fp As String = ""
fp &= IndentChar & "KEY0: '" & KEY0 & "'" & vbNewLine
fp &= IndentChar & "OFFICE: '" & OFFICE & "'" & vbNewLine
fp &= IndentChar & "ACCT_NUM: '" & ACCT_NUM & "'" & vbNewLine
fp &= IndentChar & "COMMENT_TYPE: '" & COMMENT_TYPE & "'" &
vbNewLine
fp &= IndentChar & "PRODUCT: '" & PRODUCT & "'" & vbNewLine
fp &= IndentChar & "T_IME: '" & T_IME & "'" & vbNewLine
fp &= IndentChar & "D_ATE: '" & D_ATE & "'" & vbNewLine
fp &= IndentChar & "COLLECTOR: '" & COLLECTOR & "'" & vbNewLine
fp &= IndentChar & "CMMT: '" & CMMT & "'" & vbNewLine
prefix = Trim$(prefix)
If prefix <> "" Then
Dim lines() As String = Split(fp, vbNewLine)
fp = ""
For i As Integer = LBound(lines) To UBound(lines)
If Left(lines(i), Len(IndentChar) + Len(prefix)) =
(IndentChar & prefix) Then fp &= lines(i) & vbNewLine
Next i
End If
Return fp
End Get
End Property
Public Function Clone() As COMMENT4
Return New COMMENT4(buffer)
End Function
End Class
Mike.
"Marina" <so*****@nospam.com> wrote in message
news:uP**************@TK2MSFTNGP14.phx.gbl...
If this is about a constant, how does that help ensure you are working
with the right class? There is no inheritance issue here.
"Michael D. Ober" <obermd.@.alum.mit.edu.nospam> wrote in message
news:OI**************@TK2MSFTNGP10.phx.gbl... There are times when accessing through an instance makes more sense - it
ensures I'm working with the correct object/class type. Other times,
accessing through the class type make more sense - when trying to verify
class type of an unknown string representation of the object. In the
latter
case, class type verification can then be done without the overhead of
creating an object that then gets immediately thrown away.
Mike Ober.
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OA**************@TK2MSFTNGP15.phx.gbl... Marina,
"Marina" <so*****@nospam.com> schrieb:
> If it's a constant, why not always reference it through the type
name? > What do you gain by accessing it through an instance?
What do you loose by accessing it through an instance?
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B URL:http://classicvb.org/petition/