Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Text File login

Geoff_HGeoff_H Posts: 45Member
How do you login using a text file. Does anyone have any sample code. I need it to opne a text file check if the names there and then check it against the password. Thanks in advance

Comments

  • BitByBit_ThorBitByBit_Thor Posts: 2,444Member
    : How do you login using a text file. Does anyone have any sample code. I need it to opne a text file check if the names there and then check it against the password. Thanks in advance
    :

    Well... simply read the textfile.
    The format is what you make of it... Probably, you'll want to encrypt the password.

    Use the Open statement for opening the textfile.

    [code]
    Dim nBuffer As Integer 'The file buffer number, I believe 0 To 255
    Dim sFileName As String
    Dim nLen As Integer 'Lenght of the data
    Dim sData As String 'The actual data in a string

    'This code will open a textfile in binary mode.
    'There are other modes for opening a file, but I prefer
    ' binary mode for it's wide possibilities, and it doesn't have any
    ' nasty side effects to it
    'With Binary Files, you can open anything. You can also create your
    ' own file formats!

    sFileName = "C:A file.txt"
    nBuffer = FreeFile 'Obtain a free file number
    'Open sFileName with binary mode for reading, while locking the
    ' file from write operations, using nBuffer as filenumber
    Open sFileName For Binary Access Read Lock Write As nBuffer
    'Get the lenght of the file
    nLen = LOF(nBuffer)
    'Create a buffer
    sData = Space$(nBuffer)
    'Get retrieves data from a file.
    'Syntax: Get FileNumber, BytePosition, DataBuffer
    'If you leave BytePosition out, it will be the next byte in the file
    'When you have just opened it, it will be byte 1
    Get nBuffer, , sData

    'Close the file
    Close nBuffer
    'Filebuffer nBuffer is now free for use again

    'Now we can do something with the data we loaded
    'For now, just use a messagebox to show what we got from the file
    MsgBox sData
    [/code]

    Greets...
    Richard

  • melissa_may1melissa_may1 Posts: 937Member
    Hi Richard:

    There are a couple of problems with your code.

    You seem to be confusing the BASIC file buffer number with the actual length of the file buffer.

    So, it's not correct to say that nBuffer could be 0 to 255. It needs to be at least 1, and doesn't need to be as high as 255. It only needs to be as high as the number of simultaneous open files.

    nBuffer = FreeFile 'Obtain a free file number

    This is correct. BASIC will tell you (with the FreeFile function) then number of the next available file buffer. When the program is first run, and after the above line is executed, nBuffer will be 1.

    nLen = LOF(nBuffer)

    This is also correct. LOF needs to reference the buffer number for the file you're interested in.

    'Create a buffer
    sData = Space$(nBuffer)

    OK, here's where the problems start! Remember that nBuffer is currently 1. So this line will put a single space in sData.

    nBuffer does not at all relate to the length of the data that's coming from the file. It only references the number of which buffer will be used to get/put the data to the file.


    'Get retrieves data from a file.
    'Syntax: Get FileNumber, BytePosition, DataBuffer
    'If you leave BytePosition out, it will be the next byte in the file
    'When you have just opened it, it will be byte 1
    Get nBuffer, , sData

    OK, another problem! This will only get the first 1 character from the file.


    Then you go and close the file right away, so you'll not get any more data out of it.

    This is clearly not the desired result!

    This code needs quite a bit of work to make it useful in this situation!


    [purple]Melissa[/purple]

  • BitByBit_ThorBitByBit_Thor Posts: 2,444Member
    I am deeply ashamed...

    Pretty serious typing error indeed.
    What I mean is actually Space$(LOF(nBuffer)) or even easier Space$(nLen)

    Ok... so the buffer numbers range from 1 to 255, I was just of by one, and I said I wasn't sure ;-)

    Greets...
    Richard

Sign In or Register to comment.