Results 1 to 12 of 12

Thread: How do I change "Put" "Get" offsets?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2008
    Posts
    1,181

    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?

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: How do I change "Put" "Get" offsets?

    No, does it matter?

  3. #3
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    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

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    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.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2008
    Posts
    1,181

    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?

  6. #6
    Frenzied Member
    Join Date
    Mar 2008
    Posts
    1,210

    Re: How do I change "Put" "Get" offsets?

    No there is not.

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2008
    Posts
    1,181

    Re: How do I change "Put" "Get" offsets?

    Quote Originally Posted by Magic Ink View Post
    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?

  8. #8
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    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)

  9. #9
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: How do I change "Put" "Get" offsets?

    Quote Originally Posted by Ben321 View Post
    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.

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2008
    Posts
    1,181

    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.

  11. #11
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    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.

  12. #12
    PowerPoster
    Join Date
    Jul 2001
    Location
    Tucson, AZ
    Posts
    2,166

    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
  •  



Click Here to Expand Forum to Full Width