How can I open a Random file with a structure in compact framework

G

Guest

Happy new year for everybody...

My problem is this:
I can open a random file with vs2005 this way(normal project), but not in a
smart device project.

example of the way i do in a normal project:
Structure Record
public ID As Integer
public Cod as short
<vbfixedString(50)> public Name As String
<vbfixedString(50)> public Adress as String
<vbfixedString(50)> public City as String
public Sit as single
End Structure

private sub button_click() etc.....
Dim MyRecord As Record
FileOpen(1, "TESTFILE", OpenMode.Random)
Do While Not EOF(1)
FileGet(1, MyRecord)
ListBox1.items.add MyRecord.name
Loop
FileClose(1)
end sub()

My question is:
How can i open this file in the Compact Framework, smart device project?
Can somebody give-me a exemple of how to do it real close to the one i
wrote here?

Thanks for your attention and colaboration

Luis
 
G

Guest

The CF doesn't support the operations you're trying to use. The solution is
to quit using legacy file commands and use Stream-based file operations. A
stream works in about the same way anyway. Open, seek based on your
structure size and then read.

-Chris
 
G

Guest

ctacke, MANY THANKS FOR YOUR HEPL, BUT I DIDN´T Found it yet.
Here is the thing i am making as you said, but it doen´t work, can you see
what am i making wrong? I can not assign the string to the variant of the
structure. see the code here:
this is the module with the structure:
-------------------------------------------------------------------------
Module Module1
Public Structure clientes
Public codint As Short
<VBFixedString(15)> Public CODCLi As String
<VBFixedString(50)> Public Nome As String
<VBFixedString(50)> Public Morada As String
<VBFixedString(50)> Public Locali As String
<VBFixedString(50)> Public Estab As String
<VBFixedString(15)> Public Contrib As String
<VBFixedString(15)> Public TelefE As String
<VBFixedString(15)> Public TelefR As String
<VBFixedString(15)> Public TeleM As String
<VBFixedString(15)> Public Fax As String
<VBFixedString(30)> Public Mail As String
Public PrazV As Short
Public vend As Short
<VBFixedString(10)> Public UVenda As String
<VBFixedString(10)> Public PVenda As String
Public ctip As Short
Public CZon As Short
Public cszon As Short
Public DESC As Short
Public PzPag As Short
Public Situacao As Short
End Structure

this is the way i am trying to acess the data in teh random file:
------------------------------------------------------------------------

Imports System
Imports System.IO
Imports System.Text
Imports Microsoft.VisualBasic

Public Class Form3

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Const fileName As String = "clibas.dbf"
Dim Linha As String
Dim dat As New clientes
Dim dataarray(357) As Byte
Dim fileStream As FileStream = New FileStream(fileName, FileMode.Open)

Try
' Set the stream position to the beginning of the stream.
fileStream.Seek(0, SeekOrigin.Begin)
' Read and verify the data.
For i As Integer = 0 To 357
TextBox1.Text = TextBox1.Text + fileStream.ReadByte()
Next i

Finally

' an error here where a canot put the data comming from the filestream to
the variant in the module

DAT= TEXTBOX1.TEXT
ListBox1.Items.Add(dat.codint)
ListBox1.Items.Add(dat.CODCLi)
ListBox1.Items.Add(dat.Nome)

fileStream.Close()
End Try
End Sub
end class

can you help-me to this problem?
Thanks and have a very good year 2006
happy new year
Luis
 

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