Reference Error problem

G

Guest

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.Collections.IComparer.Compar

End Functio

Public Overrides Function ToString() As Strin
Return "Model: " & intModel & ", Price: " & Format(CStr(dblPrice), "$#,##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.Configuration.ConfigurationSettings.AppSettings("PATH"
strFile = System.Configuration.ConfigurationSettings.AppSettings("FILE"


'Add any initialization after the InitializeComponent() cal
FileOpen(1, strPath & strFile, OpenMode.Random, OpenAccess.ReadWrite,
OpenShare.Shared


' 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.
 
O

One Handed Man \( OHM#\)

Then make it a class instead of a structure


Robin said:
Hi

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 ModelInfo
Implements IComparer

Public intModel As Integer
Public dblPrice As Double

Public Function Compare(ByVal x As Object, ByVal y As Object) As
Integer Implements System.Collections.IComparer.Compare
End Function

Public Overrides Function ToString() As String
Return "Model: " & intModel & ", Price: " & Format(CStr(dblPrice), "$#,##0")
End Function
End Structure

and am trying to use it to access data in a random access file which has
two columns and is delimited by a comma
using the below code

Dim intCount As Integer = 1 ' Counter Variable
Dim objModel As ModelInfo

' Get File and Path info from Configuration File
strPath = System.Configuration.ConfigurationSettings.AppSettings("PATH")
strFile = System.Configuration.ConfigurationSettings.AppSettings("FILE")



'Add any initialization after the InitializeComponent() call
FileOpen(1, strPath & strFile, OpenMode.Random, OpenAccess.ReadWrite, _
OpenShare.Shared)



' 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
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?
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top