kcwallace Posted December 1, 2005 Posted December 1, 2005 (edited) I have a VB6 application that writes a 2 dimensional array (40,1024) to a file using FileNum2=freefile Open FilePath For Binary As #FileNum2 Put #FileNum2, , VoltArr Close #FileNum2 Where VoltArr is a 40 x 1024 array of double type. I know need to open that file using .NET 2003. I need to load the entire array at once just like I did in VB6 using Dim FileNum As Integer FileNum = FreeFile Open FName For Binary As #FileNum Get #FileNum, , ImageArr 'Populate array Close #FileNum Can someone point me in the right direction? Edited December 1, 2005 by kcwallace Quote Go Beavs!!!
kcwallace Posted December 1, 2005 Author Posted December 1, 2005 I found my own answer Dim FNum As Int16 = FreeFile() FileOpen(FNum, FName, OpenMode.Binary) FileGet(FNum, ImgArr) FileClose(FNum) Quote Go Beavs!!!
Leaders snarfblam Posted December 1, 2005 Leaders Posted December 1, 2005 .Net introduces streams to Visual Basic. I hear rumors that streams are faster (I don't doubt it, since under the hood, FileOpen, FileGet, and FileClose probably use FileStreams), and once you get used to them, it is quite possible that you might like the way they work better. The Visual Basic file access functions are considered "bad" and "vb-ish." They aren't exactly C# friendly (it might not be a problem for you, but it could become a problem when a C# programmer wants to help you with code or you search google for help with file access and come up with C# code). Ultimately it is a matter of preference, but I thought I would just give you more options and broaden your horizon and all that happy stuff. Quote [sIGPIC]e[/sIGPIC]
kcwallace Posted December 1, 2005 Author Posted December 1, 2005 I tried to get the filesteam to work, I was successful, but never without having to loop through the entire array which is very time consuming. I would love to make it work without the old code. Quote Go Beavs!!!
Leaders snarfblam Posted December 2, 2005 Leaders Posted December 2, 2005 You can read a whole bunch of bytes into a buffer (in this case our buffer could be an array of bytes). 'Let's load 100 bytes of data into memory in one read operation Dim MyStream As New IO.FileStream("MyFile", IO.FileMode.Open, IO.FileAccess.Read) Dim MyData As Byte() = New Byte(99) {} MyStream.Read(MyData, 0, MyData.Length) MyStream.Close() Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.