Please post the relevant code - in this case, the read, write, and the strucure - don't post the entire project unless requested.
When posting code use the [code][/code] or [highlight=vb][/highlight] tags around it.
For c = 1 To n
Get #Canal, , tk
List1.AddItem vbTab & tk.Id & vbTab & tk.Name & vbTab & tk.Date
Next c
"Get #Canal, , tk" should be "Get #Canal, c, tk"
With binary access you have to move the pointer to the next record yourself, and you have to tell the Get-Statement WHICH record you want
btw: If you're using something called "database.txt", why don't you actually use a "real" database?
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
thanks for answering the problem is in the file menu there is the option to read record it goes to the frmindicereg form
I introduce a data to be read and it reads me the first record
I enter another data and it does not display it
For c = 1 To n
Get #Canal, , tk
List1.AddItem vbTab & tk.Id & vbTab & tk.Name & vbTab & tk.Date
Next c
"Get #Canal, , tk" should be "Get #Canal, c, tk"
With binary access you have to move the pointer to the next record yourself, ...
I'm quite sure you have "random access-mode" in mind (which is not used here).
Leaving the second param out, is perfectly fine for that loop.
If you have to give the Offset-Param explicitely, you'll have to do it "in Bytes"...
... in the case of the above loop, this would be the expression:
1 + (c - 1) * Len(tk)
thanks for answering the problem is not in the vertodo menu
the problem is in the file menu read record
that when entering the first data it reads it
you enter another data and it does not read it
If you want to solve "the problem" properly, you should start working with a library,
which is specialized for this task (I'd suggest ADO, because nearly everyone here is familiar with it).
For that, please:
- open a new Project
- then include a reference to "Microsoft ActiveX DataObjects 2.6"
- adjust the Project-Properties, to "Start from Sub Main"
Since all you want is "working against a single Table-File with records" (which is not a DB),
you can easily accomplish the same thing you were currently trying to do with your UDT-based "ISAM-File",
but using a "free standing ADO-Rs" instead.
This avoids (for the moment) any interaction with a real Database, but will teach you a lot about
"handling ADO-Rs" (which you can see as a kind of "Table-with-records"-representation.
Here's Demo-Code for a new *.bas-Module (to make the RsTable-Object Public across your whole Project):
Code:
Option Explicit
Public RsTasksFileName As String, RsTasks As New ADODB.Recordset
Sub Main()
RsTasksFileName = App.Path & "\Tasks.rs"
On Error Resume Next
RsTasks.Open RsTasksFileName 'try to open the Rs(Table)-Obj from a file
If Err = 3709 Then '...in case the file was not existing or not readable, we create a new Rs-Definition
RsTasks.Fields.Append "Id", adInteger
RsTasks.Fields.Append "Date", adDate
RsTasks.Fields.Append "Name", adVarWChar, 30
RsTasks.Open
Err.Clear
RsTasks.Save RsTasksFileName
If Err Then MsgBox "unable to create an RsFile at this location: " & RsTasksFileName
End If
On Error GoTo 0
Form1.Show 'finally, show your Main-Form
End Sub
That's all you need to establish a new "RsTasks"-Table-like Object which is publically visible in all Forms -
and which automatically creates a new File with the right "Field-Formats", in case the file was not yet existing.
(please look at the blue-colored lines above, which are quite similar to your prior UDT-definition).
To demonstrate, how to work in your "User-Code" with such an Rs-Object, take a look at the following Form1-Code:
Code:
Option Explicit
Private Sub Form_Load()
Caption = "Click Me, to add a new Record": AutoRedraw = True
ReflectRsStateOnForm
End Sub
Private Sub ReflectRsStateOnForm()
Print "Current RecordCount: " & RsTasks.RecordCount
If RsTasks.RecordCount Then RsTasks.MoveFirst
Do Until RsTasks.EOF
Print " "; RsTasks!ID, RsTasks!Date, RsTasks!Name
RsTasks.MoveNext
Loop
End Sub
Private Sub Form_Click()
RsTasks.AddNew
RsTasks!ID = RsTasks.RecordCount
RsTasks!Date = Date
RsTasks!Name = "Name for ID " & RsTasks.RecordCount
RsTasks.UpdateBatch
ReflectRsStateOnForm
End Sub
Private Sub Form_Unload(Cancel As Integer)
RsTasks.Save RsTasksFileName
End Sub
The above reflects the current state (the contents) of your Rs-Object at Startup,
and already demonstrates how to "insert new records" (in Form_Click).
Learning how to work with such an Rs-Object is not really that hard,
as the little code-snippet shows - please fill in the missing gaps yourself
(e.g. the different ways, how to position the current RecordPointer in such an Rs, how to do Deletes, etc.)
Seriously, you will produce much less errors with your Data, when you work through such an Object-Layer -
(and it will teach you, how to work against a "real DBEngine" later, which is not much different).
I will try it but what I need is the same example but with open for binary
What I've posted is doing the very same thing as your UDT-based ISAM-File approach -
only "much better" (less codelines, less chances to make errors).
Your former example was trying to interact with "a set of Records, stored in a single file".
The same is true for my example (a RecordSet, stored in a single File).
The difference is, that you will not have to write your own Functions,
to interact with this file - because "everything is already built-in" -
into the Rs-Object itself, including:
- Open and Save Methods (to and from a file on Disk)
- an .AddNew Method which allows you to add a new Record to it
- a .Delete Method which allows you to remove any Record from it (even in-between)
- a .RecordCount-Property which reflects the current Count properly, even after .AddNew or .Delete)
- several Record-Positioning Methods (.AbsolutePosition, MoveFirst/MoveLast/MoveNext/MovePrevious)
- several Record-Search-Methods like .Find or .Filter
- it supports Unicode-Text and will not require you to use weird "RTrim()" calls, to shorten "UDT-FixedLength-Strings"
- and last but not least, it supports true DataBinding against Text- Date- or CheckBox-Controls
All of the above are "hardened, well-tested methods" you don't have to write yourself,
which allow you to produce Data-Forms with a third of the code you've shown in your Zip-example.
Also note (if that is your fear), that "checking in an ADO-Project-Reference" -
will not require you to install "anything extra" along with your App-Executable.
ADO will work on any Windows-Installation (from XP onwards) because ADO is a System-COMponent.
So please use it, instead of trying to write your own "ISAM-Table-Driver" around UDT-defs.