现代,unicode 友好的“.ini 文件"在VB6中存储配置数据 [英] Modern day, unicode-friendly ".ini file" to store config data in VB6

查看:22
本文介绍了现代,unicode 友好的“.ini 文件"在VB6中存储配置数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将数据结构、几个数组和十几个变量的内容存储在一个文件中,该文件可以由我的软件保存和重新加载,也可以由用户在文本编辑器中选择编辑重新加载.对于文本编辑,我需要清楚地标记数据,就像在一个好的 ole .ini 文件中一样:

I'd like to store the contents of a data structure, a few arrays, and a dozen or so variables in a file that can be saved and reloaded by my software as well as optionally edited in a text editor by a user reloaded. For the text editing, I need the data to be clearly labeled, like in a good ole .ini file:

绝对最大电压 = 17.5

AbsMaxVoltage = 17.5

有一个 GUI,有人可能会争辩说,用户应该只从 GUI 加载、保存和修改,但客户希望能够以文本形式读取和修改数据.

There's a GUI, and one could argue that the user should just load and save and modify from the GUI, but the customer wants to be able to read and modify the data as text.

编写代码来保存和重新加载它很容易(假设所有标签都在同一个地方,只有数据发生了变化).随着更多的工作(或使用一些已经存在的 INI R/W 代码,我可以注意标签,所以如果一行被删除或在变量周围移动仍然正确填充,但这两种方法似乎都很旧 -学校.所以我对当今最聪明的编程人员会如何解决这个问题很感兴趣(使用十年前的 VB6,我不得不承认我仍然喜欢它).

It's easy enough to write code to save it and reload it (assuming all the labels are in the same place and only the data has changed). With more work (or using some of the INI R/W code that's already out there I could pay attention to the label so if a line gets deleted or moved around the variables still get stuffed correctly, but both of these approaches seem pretty old-school. So I'm interested in how the brightest minds in programming would approach this today (using decade-old VB6 which I have to admit I still love).

免责声明:我是一名电气工程师,而不是程序员.这不是我的日常工作.好吧,也许这是我日常工作的一部分.

Disclaimer: I'm an electrical engineer, not a programmer. This isn't my day job. Well maybe it's a few % of my day job.

干杯!

推荐答案

很多人会向您推荐 XML.问题是 XML 还是那么流行,有些人使用它无处不在,无需真正思考.

Lots of people will recommend XML to you. The problem is XML is still so trendy, some people use it everywhere without really thinking about it.

就像 Jeff Atwood 所说一样,很难 供非程序员阅读 XML,尤其是编辑它.规则太多了,比如转义特殊字符和以正确的顺序关闭标签.一些专家建议将 XML 视为二进制格式,根本不是文本格式.

Like Jeff Atwood said, it's hard for non-programmers to read XML and particularly to edit it. There are too many rules, like escaping special characters and closing the tags in the correct order. Some experts recommend you treat XML as a binary format, not a text format at all.

我建议使用 INI 文件,前提是 32K 的最大大小限制不是问题.在我自己的 VB6 中,我从未在许多类似情况下达到过这个限制.INI 文件对于普通人来说很容易编辑,并且很容易从 VB6 中读取和编写它们.只需使用网络上免费提供的一些优秀的插入代码即可.

I recommend using INI files, provided the maximum size limit of 32K is not a problem. I've never reached that limit in many similar situations in my own VB6. INI files are easy for ordinary folk to edit, and it's easy to read and write them from VB6. Just use some of the excellent drop-in code freely available on the web.

  • 我确定 杰伊·里格斯他的回答中提供的非常好,因为它来自 VBAccelerator.
  • 我也推荐这个课程,因为卡尔彼得森的任何东西也会很棒.
  • I'm sure the class Jay Riggs provided in his answer is excellent, because it's from VBAccelerator.
  • I would also recommend this class, because anything by Karl Peterson will be excellent too.

需要考虑的其他几点:

  • 您是否考虑过将文件放入哪个目录?立>
  • 您在问题中提到了Unicode 友好".INI 文件不是 Unicode,但这在实践.除非您想存储当前代码页不支持的字符(例如英文计算机上的中文),否则这是一项不寻常的要求,并且会导致您 其他问题.
  • 传奇的 Windows 大师 Raymond Chen 描述了XML 配置的优势文件覆盖 INI 文件.其中许多依赖于只读的 XML 文件.一个合法的优势是如果数据是高度结构化的——类层次结构或类似的.根据您的描述不适用.
  • Have you considered which directory to put the files into?
  • You mentioned "Unicode-friendly" in the question. INI files aren't Unicode, but that doesn't matter in practise. Unless you want to store characters that aren't supported on the current code page - like Chinese on an English computer - an unusual requirement, and one that will cause you other problems in a VB6 program anyway.
  • Legendary Windows guru Raymond Chen described the advantages of XML configuration files over INI files. Many of them rely on the XML file being read-only. The one legitimate advantage is if the data is highly structured - class heirarchies or the like. From your description that doesn't apply.

这篇关于现代,unicode 友好的“.ini 文件"在VB6中存储配置数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆