Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

the following code works just fine:

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?

Edited by Thinker
  • *Gurus*
Posted

The best answer is, don't 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.

 

I'm not sure how you'd 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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

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

Posted

if anyone reads this thread this is the answer:

 

Dim temp As ValueType = CType(y, ValueType)

FileGet(fHandle, temp, n)

y = CType(temp, x)

  • 5 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...