none
fileput RRS feed

  • Question

  • Please can you help? This should work, but does not. It appears that Microsoft has dlelted the call fileput entirely and replaced it with FilePutObject. The only problem is, it doesnot work! How do I make it work with a structure? The code below is what I'm using to test with. I need examples of some working code. All my existing programs use FilePut and I need to know how to make it work! Thank you for any help or documentation you can provide.

    Imports System.IO
    Public Class Form1
        Structure TestData
            Public Line1 As String
            Public Dte As Date
        End Structure

        '
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

            Dim fnum As Integer
            Dim CastType As New TestData With {.Line1 = "Paul", .Dte = Now}

            fnum = FreeFile()
            FileOpen(fnum, "CastType", OpenMode.Random, OpenAccess.ReadWrite, OpenShare.Default, 64)
            FilePutObject(fnum, CastType)
            Seek(fnum, 1L)
            FileGetObject(fnum, CastType)
            MsgBox("Data=", CastType.Line1)
        End Sub
    End Class

    Monday, April 23, 2018 1:19 PM

Answers

  • Well, as of now I cannot explain it, but everything seems to be working correctly again, with no error messages. Sorry to bother you. I have changed nothing.
    • Marked as answer by PaulGAbell Tuesday, April 24, 2018 3:35 AM
    Tuesday, April 24, 2018 3:35 AM

All replies

  • Please can you help? This should work, but does not. It appears that Microsoft has dlelted the call fileput entirely and replaced it with FilePutObject. The only problem is, it doesnot work! How do I make it work with a structure? The code below is what I'm using to test with. I need examples of some working code. All my existing programs use FilePut and I need to know how to make it work! Thank you for any help or documentation you can provide.

    Imports System.IO
    Public Class Form1
        Structure TestData
            Public Line1 As String
            Public Dte As Date
        End Structure

        '
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

            Dim fnum As Integer
            Dim CastType As New TestData With {.Line1 = "Paul", .Dte = Now}

            fnum = FreeFile()
            FileOpen(fnum, "CastType", OpenMode.Random, OpenAccess.ReadWrite, OpenShare.Default, 64)
            FilePutObject(fnum, CastType)
            Seek(fnum, 1L)
            FileGetObject(fnum, CastType)
            MsgBox("Data=", CastType.Line1)
        End Sub
    End Class

    Stuck in the past?

    https://www.daniweb.com/programming/software-development/threads/311504/how-to-convert-get-put-in-vb-net

    Or Moving on to the new future?

    https://msdn.microsoft.com/en-us/library/system.io.file_methods(v=vs.110).aspx

    You will need to learn the new ways of .net and then decide.

    Do you want to read the old data files with the new app version?

    What is the data all strings? Images video or what? That will come to play. 

    How about a database like SQL or etc?

    Or do you want to use your old code as much as possible? Is it vb6 code?

    You will prob end up changing your apps data structure. You might as well make a class for customer and etc and save that as a list. That can be serialized if you want. Then read the list of the class.

    It is hard but well worth the update to .net. Not that hard really. Just takes time.

    Monday, April 23, 2018 1:43 PM
  • Paul,

    Please don't ask for the same problems 2 questions before one is done (marked as answer) 


    Success
    Cor



    Monday, April 23, 2018 2:11 PM
  • Paul,

    Please don't ask for the same problems 2 questions before one is done (marked as answer) 


    Success
    Cor




    Well that makes it fun! FilePut and FileGet....Hmmm. Stoneages....

    La vida loca

    Monday, April 23, 2018 4:51 PM
  • If I knew you guys were going to be so fast and responsive I would have checked for replies sooner. Thank you ALL! I really appreciate you help and encouragement!

    I have over 40 programs I have written and sell for more than a few years and almost all of use the format (FileGet and FilePut) subroutines as they are the easiest way for me to read and write random access files. The data is mostly strings and could all be converted to strings easily. It is all new code, VS2010, 13, 15 and 17. All versions have worked correctly and very well until the last update. I went to write a new program and upon execution I immediately got an Depreciated error, please use FilePutObject. OK, I did it and got another error saying that the structure I was using was not compatible. Said it was not an object. Da**n. How am I supposed to know there is a NEW call and what to use as arguments? Well, I am always willing to compromise and do things a new way. At this point I just want to know the quickest and easiest way to use what I have already coded, if possible. As to new ways, I really would appreciate your alls opinion of which way to read and write random access files would be, when the data is mixed. (strings, dates,integers, etc.) A few years ago I had a similar question and the response was do it with strings. Only how do I access a random record in a string file. File IO is so RICH in Visual Basic, you could write a book on it. I would really like to read a book on random access file IO, if there are any or at least, a pdf or article or something. Any help you all can provide will be greatly appreciated. The links provided so far have really enlightened me. More confusing at the moment is to see a simple example of FilePutObject writing several array out to a file. Evidently Structure is NOT a valid type.

    Monday, April 23, 2018 8:04 PM
  • I really would appreciate your alls opinion of which way to read and write random access files would be, when the data is mixed. (strings, dates,integers, etc.) A few years ago I had a similar question and the response was do it with strings. Only how do I access a random record in a string file.

    Well I'm not a database person but it sounds like storing all those types would be perfect for a database. On the other hand not knowing exactly what it is you are storing and why I suppose would possibly lead to invalid input on our parts for assisting you IMO.

    La vida loca

    Monday, April 23, 2018 8:13 PM
  • Oh, OK. I thought I had already mentioned that. I am creating an employee database with obvious employee type dta. Names, dates, ages, etc. I need to be able to edit them when necessary and save their changes.
    Monday, April 23, 2018 8:21 PM
  •  It is all new code, VS2010, 13, 15 and 17. All versions have worked correctly and very well until the last update. I went to write a new program and upon execution I immediately got an Depreciated error, please use FilePutObject. OK, I did it and got another error saying that the structure I was using was not compatible. Said it was not an object. Da**n. How am I supposed to know there is a NEW call and what to use as arguments?

    Your existing projects should not change with updates. What do you mean exactly? What was updated? Windows? Visual Studio?

    Do you mean when you start a new default project with Visual Studio and use old code you get an error?

    Yes all the things you mention are issues. But working code should stay working. Something must have changed or etc? Its not clear to me what you are asking I guess.

    Monday, April 23, 2018 8:51 PM
  • Oh, OK. I thought I had already mentioned that. I am creating an employee database with obvious employee type dta. Names, dates, ages, etc. I need to be able to edit them when necessary and save their changes.

    Hi

    Please show an example of the data fields and their types that you are saving/loading from the 'random access' file - and, what is the file extension of your data file?


    Regards Les, Livingston, Scotland

    Monday, April 23, 2018 8:59 PM
  • Well an SQL database would work for that. There are several types. Express edition is free I believe. But how to use one you would have to talk to others about.

    Download SQL Server 2017 for Windows

    Then there's issues of how to use a connection string with one and providing a copy of the database with a program such that the connection string works to the correct path when hard coded, etc. It would take some time to learn how to use one I figure.


    La vida loca

    Monday, April 23, 2018 9:28 PM
  • I immediately got an Depreciated error, please use FilePutObject. OK, I did it and got another error saying that the structure I was using was not compatible.

    What is the exact error message?  I suspect it might be that the structure is not serializable, which is likely easy to fix.

    Monday, April 23, 2018 9:57 PM
  • Well, as of now I cannot explain it, but everything seems to be working correctly again, with no error messages. Sorry to bother you. I have changed nothing.
    • Marked as answer by PaulGAbell Tuesday, April 24, 2018 3:35 AM
    Tuesday, April 24, 2018 3:35 AM