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

查看:12
本文介绍了现代,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:

AbsMaxVoltage = 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.

需要考虑的其他几点:

  • 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天全站免登陆