locked
FileOpen, FileGet don't seem to be working. RRS feed

  • Question

  • Is there a conflict here with FileIO? I'm trying to compare an incoming serialnumber with a serialnumber in a file. FileToOpen has a valid path and filename but by the time I get to the Instr function, sCalFile is blank, an empty string.  Any ideas?  Thank you,   Greg

        Private Function CheckCalibrationFile(ByVal sn_number As String) As Boolean
            Dim iCalFile As Short
            Dim FileToOpen As String = ""
            Dim aCALFile(64) As Byte
            Dim sCALFile As String = ""
            Dim Counter As Short
            Try
                iCalFile = FreeFile()
                FileToOpen = DirSelected & "\" & FileSelected
                FileOpen(iCalFile, FileToOpen, OpenMode.Binary, OpenAccess.Read)
                FileGet(iCalFile, aCALFile)
                FileClose(iCalFile)
                For Counter = 0 To 63
                    sCALFile = sCALFile & Chr(aCALFile(Counter))
                Next Counter
                If InStr(1, sCALFile, sn_number, CompareMethod.Text) > 0 Then
                    CheckCalibrationFile = True
                Else
                    CheckCalibrationFile = False
                End If
        End Function

    Sunday, October 21, 2012 6:40 PM

Answers

  • thanks Frank.  It is actually just a text file.

    Consider, then, either using a TextFieldParser or a StreamReader.

    Is the text file delimited or fixed width or just how?

    dotNet has many ways you can get this data into a usable form which you can then work with.


    Please call me Frank :)


    • Edited by Frank L. Smith Monday, October 22, 2012 12:57 AM
    • Marked as answer by Youen Zen Tuesday, October 30, 2012 7:48 AM
    Monday, October 22, 2012 12:56 AM

All replies

  • This is a VB.Net forum and your code is VB6 so not the appropriate forum.

    However, if I remember correctly, the file should have been written using Put for the FileGet to work properly. That may be of some help. I am curious as to why you do not read it as a string instead of bytes that you convert to string, maybe that would be possible. I can't say because I don't know the format of the file.

    My VB6 is rusty and rapidly fading from memory so what I say may be wrong.


    Regards David R
    ---------------------------------------------------------------
    The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones.
    Object-oriented programming offers a sustainable way to write spaghetti code. - Paul Graham.
    Every program eventually becomes rococo, and then rubble. - Alan Perlis
    The only valid measurement of code quality: WTFs/minute.

    Sunday, October 21, 2012 7:44 PM
  • @David,

    VB6 and try?



    Cor


    Sunday, October 21, 2012 8:24 PM
  • I don't know what you up to, but I assume you want to read a binary file.

    For that is in .Net the BinaryReader

    http://msdn.microsoft.com/en-us/library/system.io.binaryreader.aspx


    Success
    Cor

    Sunday, October 21, 2012 8:28 PM
  • Cor

    Given the cryptic nature of your post, how about this clue:

    Gegs (two words 9 and 4)


    Regards David R
    ---------------------------------------------------------------
    The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones.
    Object-oriented programming offers a sustainable way to write spaghetti code. - Paul Graham.
    Every program eventually becomes rococo, and then rubble. - Alan Perlis
    The only valid measurement of code quality: WTFs/minute.

    Sunday, October 21, 2012 9:27 PM
  • Sunday, October 21, 2012 9:31 PM
  • David,

    In the code is the keyword Try, in VB6 that is On Error and therefore it cannot be VB6.

    Less cryptic?

    However, probably Hazz is uprading from VB6 and wants to change as less as possible.

     


    Success
    Cor


    Sunday, October 21, 2012 9:42 PM

  • Hi Riced & Cor Ligthert,

    They are in the Microsoft.VisualBasic Namespace.  :)


    @John

    Did I say it was no VB Net, I did not like those methods in VB6 so for sure won't use them in VB Net.


    Success
    Cor

    Sunday, October 21, 2012 9:46 PM
  • Hi Cor,

    Okay sorry, but you seemed to agree with Riced ( a.k.a. David R ) in your 1st post.

    My misunderstanding, once again, sorry.




    Regards,

    profile for John Anthony Oliver at Stack Overflow, Q&A for professional and enthusiast programmers

    Click this link to see the NEW way of how to insert a picture into a forum post.

    Installing VB6 on Windows 7

    App Hub for Windows Phone & XBOX 360 developers.

    Sunday, October 21, 2012 10:27 PM
  • Hazz,

    No, don't worry, I won't proffer a solution here - I'm sure I'm the last person you want advice from *LOL* ... but since you do want an answer, let me suggest some things:

    Explain what sort of file this is, what's in it, what you're trying to get from it, etc..

    There are many very capable people in this thread and indeed in this forum who can help you get what you need to get done - I am very confident of that.

    I hope you get your situation straightened out soon. Good luck with it. :)


    Please call me Frank :)

    Sunday, October 21, 2012 11:08 PM
  • thanks Frank.  It is actually just a text file. There is a serial number with alpha and numeric characters at the beginning of the file.  A serial number is passed into the function and a search is done in the file to see if there is a match.

    This is code I 'inherited' and it was an upgrade to .net from vb6 at some time in the past. 

    If there are any better .net library calls, I would rather use them.

    • Edited by hazz Monday, October 22, 2012 12:59 AM
    Monday, October 22, 2012 12:51 AM
  • thanks Frank.  It is actually just a text file.

    Consider, then, either using a TextFieldParser or a StreamReader.

    Is the text file delimited or fixed width or just how?

    dotNet has many ways you can get this data into a usable form which you can then work with.


    Please call me Frank :)


    • Edited by Frank L. Smith Monday, October 22, 2012 12:57 AM
    • Marked as answer by Youen Zen Tuesday, October 30, 2012 7:48 AM
    Monday, October 22, 2012 12:56 AM