本文介绍了格尔,我找不到答案!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 嘿伙计们, 我一直在这里读新闻组已经有一段时间了,并且通过我这本非常有用的书去了 ,Microsoft Visual Basic .NET Step by Step Version 2003,一遍又一遍,我觉得这样的假人。我读过你了 fella'一边谈论溪流而另一边谈论溪流,而且不能为了b / b 我的生活能够很好地掌握它们。我一直在阅读你们彼此折腾的文章,但我不能完全跟随他们知道为什么 以及我怎么想的使用流而不是FileGet和FilePut 过去对我有用的东西。 我的困境是我一直在使用FileGet和FilePut我记得很长的例行程序,而且我不知道如何更有效地使用 的东西虽然我已经读到了这么多的流是如此之多比旧的 例程更快。我有一个小文件我正在使用该商店名称和 地址并定期搜索,但FileGet和FilePut 似乎只是如此这些天爸爸抨击很慢,即使在快速机器上也是如此。我知道这些机器应该能够在更短的时间内搜索整个文件 而不是我想到它,但是需要花一点时间, 大大减慢了程序的速度,因此必须有更好的方法。 我一直在使用的微软书中说流很棒,而且 甚至给出了一个使用它们的例子。我的问题是我不能用b $ b来弄清楚如何使用它们代替随机访问文件例程 FileGet和FilePut。我之前试图解决这个问题,并且在序列化的过程中发送了 。所以,我终于有了这个为我工作 今天,我非常高兴。我找到的所有信息 然而,并没有帮助我学习如何打开文件流然后 发送或检索记录后的记录往返,或者只是选择我想要的任何 记录,比如我可以使用随机访问文件和 FilePut和FileGet函数。 我很抱歉已经过时了,但是如果有人能指出我要找到如何做多个记录而不是单个记录,我会 非常棒。 这里有一个非常简单的例子,说明了我已经设法把它们整合在一起了 我遇到的所有信息: < Serializable()>公共类blankRecord < VBFixedString(24)>公共名称 < VBFixedString(32)>公共地址线路1 < VBFixedString(32)>公共地址线2 < VBFixedString(32)>公共地址线3 结束等级 私有子保存地址 昏暗记录为新的blankRecord Dim fs作为New FileStream(" c:\test.txt",FileMode.OpenOrCreate) Dim bf as New Runtime.Serialization.Formatters.Binary.BinaryForm atter bf.Serialize(fs,record) fs.Close() End Sub 我不明白的是我如何修改上面的代码让我 将多个地址保存到我的地址文件中,就像我可以的那样 使用: FilePut(fileNumber,record,recordNumber) 非常感谢您花时间阅读我的长篇文章。 困惑的程序员, Brian PS也许如果有人知道一本书或文章的行为文件 Streams for Dummy,我会非常感激,因为我不想让任何人 觉得他们正在为我工​​作。Hey Guys,I''ve been perusing the newsgroup here for some time now, and goingthrough my ever so non-helpful book, Microsoft Visual Basic .NET Step byStep Version 2003, over and over, and I feel like such a dummy. I read youfella''s talking up one side and down the other about streams, and can''t forthe life of me get a good grasp of them. I''ve been reading the articles youtoss around to each other but I can''t quite follow them enough to know whyand how I''m supposed to be using streams instead of the FileGet and FilePutstuff that worked for me in the past.My dilemma is that I have been using FileGet and FilePut routines for aslong as I can remember, and I don''t know how to be more efficient withthings although I''ve read that streams are so much faster than the oldroutines. I have a little file I''m working with that stores names andaddress and is searched through on a regular basis, but FileGet and FilePutseem to be just so dad-blasted slow these days, even on fast machines. Iknow these machines should be able to search the entire file in less timethan it takes me to think about it, but gosh it takes quite a little while,which slows down the program considerably, so there must be a better way.That Microsoft book I''ve been using says that streams are great, andeven gives a little example of using them. My problem is that I can''tfigure out how to use them in place of the random access file routinesFileGet and FilePut. I''ve tried to figure this out before, and was sentdown the path of serialization. So, I finally got that to work for metoday, and am wonderfully happy about that. All the information I''ve foundhowever, doesn''t help me to learn how to open a stream to a file and thensend or retrieve record after record to and from, or just pick out anyrecord I want from it, like I could using a random access file and theFilePut and FileGet functions.I''m sorry to be out of date, but if anybody could point me towardsfinding out how to do multiple records instead of just a single one, I wouldbe very greatful.Here''s a very simplified example of what I''ve managed to put together out ofall the information I''ve run across:<Serializable()> Public Class blankRecord<VBFixedString(24)> Public name<VBFixedString(32)> Public addressLine1<VBFixedString(32)> Public addressLine2<VBFixedString(32)> Public addressLine3End ClassPrivate Sub saveAddressDim record As New blankRecordDim fs As New FileStream("c:\test.txt", FileMode.OpenOrCreate)Dim bf as NewRuntime.Serialization.Formatters.Binary.BinaryForm atterbf.Serialize(fs, record)fs.Close()End SubWhat I don''t understand yet is how I can modify the above code to let mesave more than one address into my address file, like I could if I wereusing:FilePut(fileNumber, record, recordNumber)Thank you very much for taking time to read my long winded post.Confused programmer,BrianP.S. Maybe if anybody knew of a book or article along the lines of "FileStreams for Dummy''s", I would be most greatful, as I don''t want anybody tofeel they are doing my work for me.推荐答案 我不是序列化的朋友,但AFAIK你可以不这样做。 序列化是一种面向对象的方式来存储数据。它按顺序存储了 ,而不是通过recored记录,即不能保证所有 记录具有相同的长度 - 但必须假设为随机 访问文件。你可以做什么(使用序列化)是使用或写一个包含所有要存储的实例的可序列化集合。然后你可以改为序列化整个集合。 如果我需要一个随机访问文件,我会使用fileget / fileput(没有 更深入体验它的性能),或者我会使用BinaryWriter 将内容写入文件(逐位,整数整数,... 。)。 - Armin http://learn.to/quote http://www.plig.net/nnq/nquote.htmlI''m not a friend of serialization, but AFAIK you can not do it this way.Serialization is an object oriented way to store data. It''s storedsequentially, not record by recored, i.e. there is no guarantee that allrecords have the same length - but that has to be assumed for a randomaccess file. What you can do (using serialization) is use or write aserializable collection containing all instances to be stored. Then you canserialize the whole collection instead.If I needed a random access file, I''d use fileget/fileput (without havingdeeper experience in it''s performance), or I''d use a BinaryWriter thatwrites the contents to the file (bit by bit, integer by integer,...).--Armin http://learn.to/quote http://www.plig.net/nnq/nquote.html 你 FilePut FilePut 我知道这些机器应该能够以比我考虑的更少的时间搜索整个文件它,但是它需要相当多的I know these machines should be able to search the entire file in lesstime than it takes me to think about it, but gosh it takes quite a little 而找到的所有信息 将 " File Streams for Dummy'',我会非常感激,因为我不喜欢我不想让任何人觉得他们正在为我工​​作。"File Streams for Dummy''s", I would be most greatful, as I don''t want anybodyto feel they are doing my work for me. 这篇关于格尔,我找不到答案!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-22 22:01
查看更多