vb6parse 1.0.0

vb6parse is a library for parsing and analyzing VB6 code, from projects, to controls, to modules, and forms.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="VB6Parse Library Reference - seek - File">
    <title>seek - File - VB6Parse Library Reference</title>
    <link rel="stylesheet" href="../../../assets/css/style.css">
    <link rel="stylesheet" href="../../../assets/css/docs-style.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github-dark.min.css">
    <script src="../../../assets/js/theme-switcher.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/vbnet.min.js"></script>
    <script>hljs.highlightAll();</script>
</head>
<body>
    <header class="docs-header">
        <div class="container">
            <h1><a href="../../../index.html">VB6Parse</a> / <a href="../../../library/index.html">Library</a> / <a href="../../../library/functions/file/index.html">File</a> / seek</h1>
            <p class="tagline">VB6 Library Reference</p>
        </div>
    </header>

    <nav class="docs-nav">
        <div class="container">
            <a href="../../../index.html">Home</a>
            <a href="../../../library/index.html">Library Reference</a>
            <a href="../../../documentation.html">Documentation</a>
            <a href="https://docs.rs/vb6parse" target="_blank">API Docs</a>
            <a href="https://github.com/scriptandcompile/vb6parse" target="_blank">GitHub</a>
            <button id="theme-toggle" class="theme-toggle" aria-label="Toggle theme">
                <span class="theme-icon">🌙</span>
            </button>
        </div>
    </nav>

    <main class="container">
        
        <article class="library-item">
            <h1 id="seek-function">Seek Function</h1>
<p>Returns a Long specifying the current read/write position within a file opened using Open statement.</p>
<h2 id="syntax">Syntax</h2>
<pre><code class="language-vbnet">Seek(filenumber)</code></pre>
<h2 id="parameters">Parameters</h2>
<ul>
<li><code>filenumber</code> - Required. Any valid Integer file number.</li>
</ul>
<h2 id="return-value">Return Value</h2>
<p>Returns a Long value indicating the current position in the file:
- For Random mode files: Returns the record number of the next record to be read or written (1-based)
- For Binary, Output, Append, and Input mode files: Returns the byte position where the next operation occurs (1-based)
- Position 1 is the beginning of the file</p>
<h2 id="remarks">Remarks</h2>
<p>The Seek function is used to determine the current position in a file opened with the Open statement.
It is particularly useful for:
- Determining current position before reading/writing
- Saving position to return to later
- Calculating file progress (current position vs file size using LOF)
- Implementing custom file navigation
- Verifying position after Seek statement
For Random access files, Seek returns the record number (1-based) of the next record to be read or written.
For all other access modes (Binary, Input, Output, Append), Seek returns the byte position (1-based).
The Seek function is different from the Seek statement:
- Seek function: Returns current position (read-only operation)
- Seek statement: Sets the position for next read/write (write operation)
The file must be open before calling Seek. Use <code>FreeFile</code> to get an available file number.
Always close files when done using Close statement.</p>
<h2 id="typical-uses">Typical Uses</h2>
<ol>
<li><strong>Current Position</strong>: Determine where you are in the file</li>
<li><strong>Save Position</strong>: Store current position to return to later</li>
<li><strong>Progress Tracking</strong>: Calculate percentage of file processed</li>
<li><strong>Navigation</strong>: Implement forward/backward navigation in files</li>
<li><strong>Record Counting</strong>: Count records processed in Random access</li>
<li><strong>Byte Counting</strong>: Track bytes read/written in Binary mode</li>
<li><strong>Position Verification</strong>: Verify Seek statement worked correctly</li>
<li><strong>File Parsing</strong>: Parse structured binary files with position tracking</li>
</ol>
<h2 id="basic-examples">Basic Examples</h2>
<pre><code class="language-vbnet">&#x27; Example 1: Get current position in binary file
Dim FileNum As Integer
Dim CurrentPos As Long
FileNum = FreeFile
Open &quot;data.bin&quot; For Binary As #FileNum
CurrentPos = Seek(FileNum)  &#x27; Returns 1 at start
Debug.Print &quot;Position: &quot; &amp; CurrentPos
Close #FileNum</code></pre>
<pre><code class="language-vbnet">&#x27; Example 2: Get current record number in random access
Dim FileNum As Integer
Dim RecordNum As Long
FileNum = FreeFile
Open &quot;records.dat&quot; For Random As #FileNum Len = 100
RecordNum = Seek(FileNum)  &#x27; Returns next record number
Debug.Print &quot;Next Record: &quot; &amp; RecordNum
Close #FileNum</code></pre>
<pre><code class="language-vbnet">&#x27; Example 3: Save and restore position
Dim FileNum As Integer
Dim SavedPos As Long
FileNum = FreeFile
Open &quot;data.txt&quot; For Input As #FileNum
&#x27; Read some data...
SavedPos = Seek(FileNum)  &#x27; Save position
&#x27; Read more data...
Seek #FileNum, SavedPos   &#x27; Restore position
Close #FileNum</code></pre>
<pre><code class="language-vbnet">&#x27; Example 4: Calculate progress percentage
Dim FileNum As Integer
Dim Progress As Double
FileNum = FreeFile
Open &quot;large.dat&quot; For Binary As #FileNum
Progress = (Seek(FileNum) / LOF(FileNum)) * 100
Debug.Print &quot;Progress: &quot; &amp; Format(Progress, &quot;0.0&quot;) &amp; &quot;%&quot;
Close #FileNum</code></pre>
<h2 id="common-patterns">Common Patterns</h2>
<h3 id="pattern-1-getcurrentposition">Pattern 1: <code>GetCurrentPosition</code></h3>
<p>Get current file position with error handling</p>
<pre><code class="language-vbnet">Function GetCurrentPosition(FileNum As Integer) As Long
    On Error Resume Next
    GetCurrentPosition = Seek(FileNum)
    If Err.Number &lt;&gt; 0 Then
        GetCurrentPosition = -1  &#x27; Error indicator
    End If
End Function</code></pre>
<h3 id="pattern-2-getprogresspercentage">Pattern 2: <code>GetProgressPercentage</code></h3>
<p>Calculate how much of file has been processed</p>
<pre><code class="language-vbnet">Function GetProgressPercentage(FileNum As Integer) As Double
    Dim CurrentPos As Long
    Dim FileSize As Long
    CurrentPos = Seek(FileNum)
    FileSize = LOF(FileNum)
    If FileSize &gt; 0 Then
        GetProgressPercentage = (CurrentPos / FileSize) * 100
    Else
        GetProgressPercentage = 0
    End If
End Function</code></pre>
<h3 id="pattern-3-isatendoffile">Pattern 3: <code>IsAtEndOfFile</code></h3>
<p>Check if at end of file using position</p>
<pre><code class="language-vbnet">Function IsAtEndOfFile(FileNum As Integer) As Boolean
    IsAtEndOfFile = (Seek(FileNum) &gt; LOF(FileNum))
End Function</code></pre>
<h3 id="pattern-4-getremainingbytes">Pattern 4: <code>GetRemainingBytes</code></h3>
<p>Calculate bytes remaining in file</p>
<pre><code class="language-vbnet">Function GetRemainingBytes(FileNum As Integer) As Long
    GetRemainingBytes = LOF(FileNum) - Seek(FileNum) + 1
End Function</code></pre>
<h3 id="pattern-5-saveandrestoreposition">Pattern 5: <code>SaveAndRestorePosition</code></h3>
<p>Save position, perform operation, restore</p>
<pre><code class="language-vbnet">Sub SaveAndRestorePosition(FileNum As Integer)
    Dim SavedPos As Long
    SavedPos = Seek(FileNum)
    &#x27; Perform operations that change position
    Seek #FileNum, 1  &#x27; Go to start
    &#x27; Read header...
    Seek #FileNum, SavedPos  &#x27; Restore position
End Sub</code></pre>
<h3 id="pattern-6-getcurrentrecordnumber">Pattern 6: <code>GetCurrentRecordNumber</code></h3>
<p>Get current record in Random access file</p>
<pre><code class="language-vbnet">Function GetCurrentRecordNumber(FileNum As Integer) As Long
    &#x27; For Random access, Seek returns record number
    GetCurrentRecordNumber = Seek(FileNum)
End Function</code></pre>
<h3 id="pattern-7-calculatebytesprocessed">Pattern 7: <code>CalculateBytesProcessed</code></h3>
<p>Track bytes processed since start</p>
<pre><code class="language-vbnet">Function CalculateBytesProcessed(FileNum As Integer, StartPos As Long) As Long
    CalculateBytesProcessed = Seek(FileNum) - StartPos
End Function</code></pre>
<h3 id="pattern-8-validatefileposition">Pattern 8: <code>ValidateFilePosition</code></h3>
<p>Verify position is within file bounds</p>
<pre><code class="language-vbnet">Function ValidateFilePosition(FileNum As Integer) As Boolean
    Dim CurrentPos As Long
    Dim FileSize As Long
    CurrentPos = Seek(FileNum)
    FileSize = LOF(FileNum)
    ValidateFilePosition = (CurrentPos &gt;= 1 And CurrentPos &lt;= FileSize + 1)
End Function</code></pre>
<h3 id="pattern-9-getpositioninfo">Pattern 9: <code>GetPositionInfo</code></h3>
<p>Get detailed position information</p>
<pre><code class="language-vbnet">Sub GetPositionInfo(FileNum As Integer, ByRef Position As Long, _
                    ByRef Size As Long, ByRef Remaining As Long)
    Position = Seek(FileNum)
    Size = LOF(FileNum)
    Remaining = Size - Position + 1
End Sub</code></pre>
<h3 id="pattern-10-seektopercentage">Pattern 10: <code>SeekToPercentage</code></h3>
<p>Jump to percentage of file</p>
<pre><code class="language-vbnet">Sub SeekToPercentage(FileNum As Integer, Percentage As Double)
    Dim TargetPos As Long
    TargetPos = CLng((LOF(FileNum) * Percentage) / 100)
    If TargetPos &lt; 1 Then TargetPos = 1
    Seek #FileNum, TargetPos
    Debug.Print &quot;Moved to position: &quot; &amp; Seek(FileNum)
End Sub</code></pre>
<h2 id="advanced-usage">Advanced Usage</h2>
<h3 id="example-1-filepositiontracker-class">Example 1: <code>FilePositionTracker</code> Class</h3>
<p>Track and manage file positions with bookmarks</p>
<pre><code class="language-vbnet">&#x27; Class: FilePositionTracker
Private m_FileNum As Integer
Private m_Bookmarks As Collection
Private Sub Class_Initialize()
    Set m_Bookmarks = New Collection
End Sub
Public Sub Initialize(FileNum As Integer)
    m_FileNum = FileNum
End Sub
Public Function GetCurrentPosition() As Long
    GetCurrentPosition = Seek(m_FileNum)
End Function
Public Sub AddBookmark(BookmarkName As String)
    Dim CurrentPos As Long
    CurrentPos = Seek(m_FileNum)
    On Error Resume Next
    m_Bookmarks.Remove BookmarkName
    On Error GoTo 0
    m_Bookmarks.Add CurrentPos, BookmarkName
End Sub
Public Sub GoToBookmark(BookmarkName As String)
    Dim BookmarkPos As Long
    On Error Resume Next
    BookmarkPos = m_Bookmarks(BookmarkName)
    If Err.Number = 0 Then
        Seek #m_FileNum, BookmarkPos
    Else
        Err.Raise vbObjectError + 1001, &quot;FilePositionTracker&quot;, _
                  &quot;Bookmark not found: &quot; &amp; BookmarkName
    End If
End Sub
Public Function GetProgress() As Double
    Dim CurrentPos As Long
    Dim FileSize As Long
    CurrentPos = Seek(m_FileNum)
    FileSize = LOF(m_FileNum)
    If FileSize &gt; 0 Then
        GetProgress = (CDbl(CurrentPos) / CDbl(FileSize)) * 100
    Else
        GetProgress = 0
    End If
End Function
Public Function GetRemainingBytes() As Long
    GetRemainingBytes = LOF(m_FileNum) - Seek(m_FileNum) + 1
End Function
Public Sub ClearBookmarks()
    Set m_Bookmarks = New Collection
End Sub</code></pre>
<h3 id="example-2-binaryfileparser-module">Example 2: <code>BinaryFileParser</code> Module</h3>
<p>Parse structured binary files with position tracking</p>
<pre><code class="language-vbnet">&#x27; Module: BinaryFileParser
Private Type FileHeader
    Signature As String * 4
    Version As Integer
    RecordCount As Long
End Type
Public Function ParseFile(FileName As String) As Collection
    Dim FileNum As Integer
    Dim Header As FileHeader
    Dim Records As New Collection
    Dim i As Long
    Dim StartPos As Long
    FileNum = FreeFile
    Open FileName For Binary As #FileNum
    &#x27; Read header
    StartPos = Seek(FileNum)
    Debug.Print &quot;Reading header at position: &quot; &amp; StartPos
    Get #FileNum, , Header
    Debug.Print &quot;Header read, now at position: &quot; &amp; Seek(FileNum)
    &#x27; Validate signature
    If Header.Signature &lt;&gt; &quot;DATA&quot; Then
        Close #FileNum
        Err.Raise vbObjectError + 1001, &quot;ParseFile&quot;, &quot;Invalid file signature&quot;
    End If
    &#x27; Read records
    For i = 1 To Header.RecordCount
        Dim RecordPos As Long
        Dim RecordData As String
        RecordPos = Seek(FileNum)
        Debug.Print &quot;Reading record &quot; &amp; i &amp; &quot; at position: &quot; &amp; RecordPos
        &#x27; Read record (example: 100 byte records)
        RecordData = Space$(100)
        Get #FileNum, , RecordData
        Records.Add RecordData
    Next i
    Debug.Print &quot;Finished at position: &quot; &amp; Seek(FileNum)
    Debug.Print &quot;File size: &quot; &amp; LOF(FileNum)
    Close #FileNum
    Set ParseFile = Records
End Function
Public Function GetFileProgress(FileNum As Integer) As String
    Dim CurrentPos As Long
    Dim FileSize As Long
    Dim Percentage As Double
    CurrentPos = Seek(FileNum)
    FileSize = LOF(FileNum)
    If FileSize &gt; 0 Then
        Percentage = (CDbl(CurrentPos) / CDbl(FileSize)) * 100
    Else
        Percentage = 0
    End If
    GetFileProgress = &quot;Position: &quot; &amp; CurrentPos &amp; &quot; of &quot; &amp; FileSize &amp; _
                      &quot; (&quot; &amp; Format(Percentage, &quot;0.0&quot;) &amp; &quot;%)&quot;
End Function</code></pre>
<h3 id="example-3-randomaccessnavigator-class">Example 3: <code>RandomAccessNavigator</code> Class</h3>
<p>Navigate through Random access file records</p>
<pre><code class="language-vbnet">&#x27; Class: RandomAccessNavigator
Private m_FileNum As Integer
Private m_RecordLength As Integer
Private m_TotalRecords As Long
Public Sub Initialize(FileName As String, RecordLength As Integer)
    m_RecordLength = RecordLength
    m_FileNum = FreeFile
    Open FileName For Random As #m_FileNum Len = RecordLength
    m_TotalRecords = LOF(m_FileNum) \ RecordLength
End Sub
Public Function GetCurrentRecord() As Long
    &#x27; For Random access, Seek returns record number
    GetCurrentRecord = Seek(m_FileNum)
End Function
Public Function GetTotalRecords() As Long
    GetTotalRecords = m_TotalRecords
End Function
Public Function MoveNext() As Boolean
    Dim CurrentRecord As Long
    CurrentRecord = Seek(m_FileNum)
    If CurrentRecord &lt;= m_TotalRecords Then
        &#x27; Seek statement will auto-advance after Get
        MoveNext = True
    Else
        MoveNext = False
    End If
End Function
Public Sub MovePrevious()
    Dim CurrentRecord As Long
    CurrentRecord = Seek(m_FileNum)
    If CurrentRecord &gt; 1 Then
        Seek #m_FileNum, CurrentRecord - 1
    End If
End Sub
Public Sub MoveFirst()
    Seek #m_FileNum, 1
End Sub
Public Sub MoveLast()
    Seek #m_FileNum, m_TotalRecords
End Sub
Public Function IsAtBeginning() As Boolean
    IsAtBeginning = (Seek(m_FileNum) = 1)
End Function
Public Function IsAtEnd() As Boolean
    IsAtEnd = (Seek(m_FileNum) &gt; m_TotalRecords)
End Function
Public Function GetProgress() As Double
    Dim CurrentRecord As Long
    CurrentRecord = Seek(m_FileNum)
    If m_TotalRecords &gt; 0 Then
        GetProgress = (CDbl(CurrentRecord - 1) / CDbl(m_TotalRecords)) * 100
    Else
        GetProgress = 0
    End If
End Function
Public Sub Close()
    Close #m_FileNum
End Sub</code></pre>
<h3 id="example-4-fileprogressmonitor-class">Example 4: <code>FileProgressMonitor</code> Class</h3>
<p>Monitor file processing progress with time estimates</p>
<pre><code class="language-vbnet">&#x27; Class: FileProgressMonitor
Private m_FileNum As Integer
Private m_StartPosition As Long
Private m_StartTime As Double
Private m_FileSize As Long
Public Sub StartMonitoring(FileNum As Integer)
    m_FileNum = FileNum
    m_StartPosition = Seek(FileNum)
    m_StartTime = Timer
    m_FileSize = LOF(FileNum)
End Sub
Public Function GetCurrentPosition() As Long
    GetCurrentPosition = Seek(m_FileNum)
End Function
Public Function GetBytesProcessed() As Long
    GetBytesProcessed = Seek(m_FileNum) - m_StartPosition
End Function
Public Function GetPercentComplete() As Double
    Dim CurrentPos As Long
    CurrentPos = Seek(m_FileNum)
    If m_FileSize &gt; 0 Then
        GetPercentComplete = (CDbl(CurrentPos) / CDbl(m_FileSize)) * 100
    Else
        GetPercentComplete = 0
    End If
End Function
Public Function GetElapsedSeconds() As Double
    GetElapsedSeconds = Timer - m_StartTime
End Function
Public Function GetEstimatedTimeRemaining() As Double
    Dim BytesProcessed As Long
    Dim BytesRemaining As Long
    Dim ElapsedTime As Double
    Dim BytesPerSecond As Double
    BytesProcessed = Seek(m_FileNum) - m_StartPosition
    BytesRemaining = m_FileSize - Seek(m_FileNum) + 1
    ElapsedTime = Timer - m_StartTime
    If BytesProcessed &gt; 0 And ElapsedTime &gt; 0 Then
        BytesPerSecond = BytesProcessed / ElapsedTime
        GetEstimatedTimeRemaining = BytesRemaining / BytesPerSecond
    Else
        GetEstimatedTimeRemaining = 0
    End If
End Function
Public Function GetProgressReport() As String
    Dim Report As String
    Dim PercentComplete As Double
    Dim ElapsedTime As Double
    Dim RemainingTime As Double
    PercentComplete = GetPercentComplete()
    ElapsedTime = GetElapsedSeconds()
    RemainingTime = GetEstimatedTimeRemaining()
    Report = &quot;Progress: &quot; &amp; Format(PercentComplete, &quot;0.0&quot;) &amp; &quot;%&quot; &amp; vbCrLf
    Report = Report &amp; &quot;Position: &quot; &amp; Seek(m_FileNum) &amp; &quot; of &quot; &amp; m_FileSize &amp; vbCrLf
    Report = Report &amp; &quot;Elapsed: &quot; &amp; Format(ElapsedTime, &quot;0.0&quot;) &amp; &quot;s&quot; &amp; vbCrLf
    Report = Report &amp; &quot;Remaining: &quot; &amp; Format(RemainingTime, &quot;0.0&quot;) &amp; &quot;s&quot;
    GetProgressReport = Report
End Function
Public Sub Reset()
    m_StartPosition = Seek(m_FileNum)
    m_StartTime = Timer
End Sub</code></pre>
<h2 id="error-handling">Error Handling</h2>
<p>The Seek function can generate the following errors:
- <strong>Error 52</strong> (Bad file name or number): File not open or invalid file number
- <strong>Error 5</strong> (Invalid procedure call): File number is invalid
Always use error handling when working with file I/O:</p>
<pre><code class="language-vbnet">On Error Resume Next
CurrentPos = Seek(FileNum)
If Err.Number &lt;&gt; 0 Then
    MsgBox &quot;Error getting position: &quot; &amp; Err.Description
End If</code></pre>
<h2 id="performance-considerations">Performance Considerations</h2>
<ul>
<li>Seek function is very fast (just reads internal file pointer)</li>
<li>No disk I/O involved (unlike reading/writing data)</li>
<li>Can be called frequently without performance impact</li>
<li>Useful for progress tracking in loops without overhead</li>
<li>Combine with LOF for efficient progress calculations</li>
</ul>
<h2 id="best-practices">Best Practices</h2>
<ol>
<li><strong>Validate File Number</strong>: Ensure file is open before calling Seek</li>
<li><strong>Use with LOF</strong>: Combine with LOF function to calculate progress</li>
<li><strong>Error Handling</strong>: Always use error handling for file operations</li>
<li><strong>Close Files</strong>: Always close files when done to free resources</li>
<li><strong>Save Position</strong>: Store position before operations that change it</li>
<li><strong>1-Based Position</strong>: Remember positions start at 1, not 0</li>
<li><strong>Mode Awareness</strong>: Know whether function returns record# or byte position</li>
<li><strong><code>FreeFile</code> Usage</strong>: Use <code>FreeFile</code> to get available file numbers</li>
<li><strong>Progress Updates</strong>: Update UI periodically, not on every byte</li>
<li><strong>Position Validation</strong>: Verify position is within expected range</li>
</ol>
<h2 id="comparison-with-related-functions">Comparison with Related Functions</h2>
<table>
<thead>
<tr>
<th>Function/Statement</th>
<th>Purpose</th>
<th>Returns</th>
<th>Mode-Specific</th>
</tr>
</thead>
<tbody>
<tr>
<td>Seek (Function)</td>
<td>Get current position</td>
<td>Long (position)</td>
<td>Record# or byte position</td>
</tr>
<tr>
<td>Seek (Statement)</td>
<td>Set position</td>
<td>N/A (void)</td>
<td>Sets for next operation</td>
</tr>
<tr>
<td>LOF</td>
<td>Get file size</td>
<td>Long (bytes)</td>
<td>Total file size</td>
</tr>
<tr>
<td>EOF</td>
<td>Check end of file</td>
<td>Boolean</td>
<td>True if past end</td>
</tr>
<tr>
<td>Loc</td>
<td>Get current position</td>
<td>Long</td>
<td>Similar to Seek</td>
</tr>
<tr>
<td><code>FileLen</code></td>
<td>Get file length</td>
<td>Long (bytes)</td>
<td>File must be closed</td>
</tr>
</tbody>
</table>
<h2 id="platform-considerations">Platform Considerations</h2>
<ul>
<li>Available in VB6, VBA (all versions)</li>
<li>1-based positioning (unlike many other languages)</li>
<li>Maximum file size limited by Long data type (2GB)</li>
<li>For files &gt; 2GB, position may overflow</li>
<li>Random access mode returns record numbers</li>
<li>All other modes return byte positions</li>
</ul>
<h2 id="limitations">Limitations</h2>
<ul>
<li>Cannot handle files larger than 2GB (Long overflow)</li>
<li>File must be open before calling Seek</li>
<li>Returns position for next operation (not last operation)</li>
<li>For Random access, assumes fixed-length records</li>
<li>No support for 64-bit file positions</li>
<li>Cannot determine position in closed files</li>
</ul>
<h2 id="related-functions">Related Functions</h2>
<ul>
<li><code>Seek</code> (Statement): Set the position for next read/write operation</li>
<li><code>LOF</code>: Get the length of an open file in bytes</li>
<li><code>EOF</code>: Determine if end of file has been reached</li>
<li><code>Loc</code>: Get the current read/write position (similar to Seek function)</li>
<li><code>Get</code>: Read data from file (advances position)</li>
<li><code>Put</code>: Write data to file (advances position)</li>
<li><code>Open</code>: Open file for I/O operations</li>
<li><code>Close</code>: Close an open file</li>
<li><code>FreeFile</code>: Get next available file number</li>
</ul>
        </article>
        
        <div style="margin-top: 3rem; padding-top: 2rem; border-top: 1px solid var(--border-color);">
            <p>
                <a href="index.html">← Back to File</a> |
                <a href="../index.html">View all functions</a>
            </p>
        </div>

    </main>

    <footer>
        <div class="container">
            <p>&copy; 2024-2026 VB6Parse Contributors. Licensed under the MIT License.</p>
        </div>
    </footer>
</body>
</html>