Option Strict and FileGet

  • Thread starter Thread starter makai
  • Start date Start date
M

makai

Guest
the following code works just fine:
Code:
Public Class Form1
    Inherits System.Windows.Forms.Form

    Structure x
        Dim j As Short
    End Structure

    Private Sub Button1_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button1.Click

        Dim y As x
        FileOpen(1, "c:\t1.txt", OpenMode.Random, , , Len(y))
        FileGet(1, y, 1)
        FileClose(1)

        MsgBox(y.j)
    End Sub
End Class

but if I put in
Option Strict On

the line
FileGet(1, y, 1)

will not compile due to the fact that y is not in the overloaded parameter list


1. Does anyone know the correct conversion code?

2. I like the idea of sticking with Strict On - is this not a good idea?
 
Last edited by a moderator:
The best answer is, dont use FileOpen etc. They are pretty poor methods supplied by the VisualBasic runtime of accessing files, and there are much better methods present under the System.IO namespace.

Im not sure how youd solve your problem if you remained using the VB methods, possibly just read in a Short (which there is an overload for) and put it in the structure.

And yeah, you should always have Option Strict on.
 
funny everyone heavily derides my use of these File functions - but it is the only way I can access the data

I am willing to bet that no one has tried Random Access of data into Structures with fixed length strings (or fixed arrays) - that would make a great tutorial if someone can do it with any kind of elegance


I have built a class to do sequential access using FileStream but to me it looks so crazy to reinvent something that is already intrinsic (and simpler) already in the language

everyone points to speed - but it is a nonissue - it is already 100 times faster than I require
 
if anyone reads this thread this is the answer:

Dim temp As ValueType = CType(y, ValueType)
FileGet(fHandle, temp, n)
y = CType(temp, x)
 
Wow, i know this is an old post but in case you ever read this makai, i have one word for you.

Thanks!
 

Similar threads

Back
Top