Reference Error problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robin

    Reference Error problem

    H

    I am trying to use the FileOpen method to read a Random Access file. I first created a structure that looked like this (not completed

    Public Structure ModelInf
    Implements ICompare

    Public intModel As Intege
    Public dblPrice As Doubl

    Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements System.Collecti ons.IComparer.C ompar

    End Functio

    Public Overrides Function ToString() As Strin
    Return "Model: " & intModel & ", Price: " & Format(CStr(dbl Price), "$#,##0"
    End Functio
    End Structur

    and am trying to use it to access data in a random access file which has two columns and is delimited by a comm

    using the below cod

    Dim intCount As Integer = 1 ' Counter Variabl
    Dim objModel As ModelInf

    ' Get File and Path info from Configuration Fil
    strPath = System.Configur ation.Configura tionSettings.Ap pSettings("PATH "
    strFile = System.Configur ation.Configura tionSettings.Ap pSettings("FILE "


    'Add any initialization after the InitializeCompo nent() cal
    FileOpen(1, strPath & strFile, OpenMode.Random , OpenAccess.Read Write,
    OpenShare.Share d


    ' Load Listbo
    Do While Not EOF(1
    FileGet(1, objModel, intCount

    intCount +=
    Loo

    and I am getting an error message. I know a struct is a value type and the sub wants a reference type. I am confused because the example in the book isn't seemingly all that different syntactically from what I wish to achieve. Can anyone tell me what I am doing wrong

    Thank you.
  • One Handed Man \( OHM#\)

    #2
    Re: Reference Error problem

    Then make it a class instead of a structure


    "Robin" <anonymous@disc ussions.microso ft.com> wrote in message
    news:7BEB871A-00A2-4224-8E6B-263C231C4B48@mi crosoft.com...[color=blue]
    > Hi
    >
    > I am trying to use the FileOpen method to read a Random Access file. I[/color]
    first created a structure that looked like this (not completed)[color=blue]
    >
    > Public Structure ModelInfo
    > Implements IComparer
    >
    > Public intModel As Integer
    > Public dblPrice As Double
    >
    > Public Function Compare(ByVal x As Object, ByVal y As Object) As[/color]
    Integer Implements System.Collecti ons.IComparer.C ompare[color=blue]
    >
    > End Function
    >
    > Public Overrides Function ToString() As String
    > Return "Model: " & intModel & ", Price: " & Format(CStr(dbl Price),[/color]
    "$#,##0")[color=blue]
    > End Function
    > End Structure
    >
    > and am trying to use it to access data in a random access file which has[/color]
    two columns and is delimited by a comma[color=blue]
    >
    > using the below code
    >
    > Dim intCount As Integer = 1 ' Counter Variable
    > Dim objModel As ModelInfo
    >
    > ' Get File and Path info from Configuration File
    > strPath =[/color]
    System.Configur ation.Configura tionSettings.Ap pSettings("PATH ")[color=blue]
    > strFile =[/color]
    System.Configur ation.Configura tionSettings.Ap pSettings("FILE ")[color=blue]
    >
    >
    >
    > 'Add any initialization after the InitializeCompo nent() call
    > FileOpen(1, strPath & strFile, OpenMode.Random ,[/color]
    OpenAccess.Read Write, _[color=blue]
    > OpenShare.Share d)
    >
    >
    >
    > ' Load Listbox
    > Do While Not EOF(1)
    > FileGet(1, objModel, intCount)
    >
    > intCount += 1
    > Loop
    >
    > and I am getting an error message. I know a struct is a value type and[/color]
    the sub wants a reference type. I am confused because the example in the
    book isn't seemingly all that different syntactically from what I wish to
    achieve. Can anyone tell me what I am doing wrong?[color=blue]
    >
    > Thank you.[/color]


    Comment

    • Robin

      #3
      Re: Reference Error problem

      I thought of that but the reason I was making it a Structure is because that way it mirrors my file layout and behaves exactly like a UDT does in VB6. What I need to do is to be able to pull the values into something like the UDT so I can write them out again in one step rather than reassembling them like I would using the stream reader/writer classes and managing the data in an object like a collection of classes. According to the book I should be able to do this but I am getting a funky error.

      Comment

      Working...