-
Nov 16th, 2012, 01:40 AM
#1
Thread Starter
Frenzied Member
How do I change "Put" "Get" offsets?
The first byte with Put and Get statements is number 1 in VB6, but is number 0 in most every other context for any other software and any other programming language. So I would like to know if I can change the default number for the "first byte" from 1 to 0. I know I can do this with arrays (usually arrays start at index 0, but you can change this to index 1). Can I do the same thing for file offsets?
-
Nov 16th, 2012, 09:33 AM
#2
Re: How do I change "Put" "Get" offsets?
-
Nov 16th, 2012, 09:33 AM
#3
Re: How do I change "Put" "Get" offsets?
Although i don't really see any issue with this you may declare an array with predefined dimentions:
Dim arTest(1 To 100) As Integer
or you can define lower bound with Option Base:
Code:
Option Explicit
Option Base 1
Private Sub Form_Load()
Dim arTest(100) As Integer
Debug.Print LBound(arTest)
End Sub
-
Nov 16th, 2012, 04:38 PM
#4
Re: How do I change "Put" "Get" offsets?
It works this way for historical reasons. It has never been a big enough issue to warrant anything like Option Base or an Open option.
Remember, Microsoft Basics have a long history and they were never meant for professional use until fairly late in the game. So even though "numbering from 1" is awkward (like array indexes they're offsets and not numbers) it made good sense when early Basics were created.
The original Basic was meant as a dumbed down Fortran with basic Strings added, and the target audience was libreral arts students at Dartmouth College. People for whom the concept of "zero" is as foreign as it was to the Romans.
To maintain backward compatibility many of these things have been retained in vestigial form. A few have been made optionally settable, and defaults have even changed. But not file byte and record offsets.
Last edited by dilettante; Nov 16th, 2012 at 04:41 PM.
-
Nov 23rd, 2012, 04:26 AM
#5
Thread Starter
Frenzied Member
Re: How do I change "Put" "Get" offsets?
Option Base works for Arrays. Is there an equivalent for file open, such as Option FileOffsetBase, or something?
-
Nov 23rd, 2012, 04:36 AM
#6
Re: How do I change "Put" "Get" offsets?
-
Nov 23rd, 2012, 06:00 AM
#7
Thread Starter
Frenzied Member
Re: How do I change "Put" "Get" offsets?
Originally Posted by Magic Ink
No there is not.
That sucks. For it to work properly the constant "1" must be stored somewhere in the EXE file of VB6, as the exe file of ANY SOFTWARE is just compiled binary code which talks to the computer on a LOW LEVEL which would always recognize byte0 as the first byte. So if there is some way, may be I can hack vb6.exe and make it use 0 for the offset instead?
-
Nov 23rd, 2012, 10:17 AM
#8
Re: How do I change "Put" "Get" offsets?
What you're looking for probably isn't in VB6.EXE. Most likely it's in msvbvm60.dll.
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)
-
Nov 24th, 2012, 03:25 PM
#9
Re: How do I change "Put" "Get" offsets?
Originally Posted by Ben321
That sucks. For it to work properly the constant "1" must be stored somewhere in the EXE file of VB6, as the exe file of ANY SOFTWARE is just compiled binary code which talks to the computer on a LOW LEVEL which would always recognize byte0 as the first byte. So if there is some way, may be I can hack vb6.exe and make it use 0 for the offset instead?
Sounds like a lot of trouble for nothing. So long as you know what the offset is then there is no problem. I would think the amount of time it took to write the first post would be more time than I could justify spending on something this trival.
-
Nov 25th, 2012, 12:19 AM
#10
Thread Starter
Frenzied Member
Re: How do I change "Put" "Get" offsets?
It irks me because 1 is not the "correct" offset number for the first byte of a file. It is supposed to be 0. Whenever I see specs for a file type and the list locations of bytes within a file. It's ALWAYS based on 0 being the first byte. If I write the program in VB6 using the offsets in the documentation for a given file format, the program has big problems because it's off by one byte. I have to remember to always add 1 to every offset.
-
Nov 25th, 2012, 01:55 AM
#11
Re: How do I change "Put" "Get" offsets?
That's because you're thinking of 'Offset' rather than 'Absolute Byte Position' (i.e. Byte Number) which is what Get and Put use. Offset 0 is Absolute Byte Position (Byte Number) 1. It's not too difficult a thing to convert
Code:
Get #intFile, lngOffSet + 1, bytData
Put #intFile1, lngOffSet + 1, bytData
you only have to remember to do it once.
-
Nov 25th, 2012, 10:59 AM
#12
PowerPoster
Re: How do I change "Put" "Get" offsets?
I'm with Doogle's solution of " lngOffSet + 1".
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|