帮一客户修改VB6程序,需要将一些文本转换成json数组并输出。经过一番研究,决定用插件实现。
1. 安装插件Chilkat
Chilkat Full-Version Software Components Downloads (chilkatsoft.com)
选择 Chilkat ActiveX Components
win32和x64的版本,实测我的Win10 x64系统用win32版本是有效的。
2. 添加引用
工程 > 引用,勾选 Chilkat ActiveX v9.5.0, 确定
3. 代码
'组织数据格式》》》》》》》》》》》》
Dim textToShow As String
textToShow = TextLEDInfo.Text
Dim font As String
Dim color As String
Dim bgColor As String
Dim type1 As String
'格式统一设定
font = "2"
color = "0"
bgColor = "7"
type1 = "1"
Dim wordArray As New ChilkatJsonArray
For I = 0 To Len(textToShow) - 1
Dim word As String
word = Mid(textToShow, I + 1, 1) 'Mid()下标从1开始
'组织json
Dim success As Long
success = wordArray.AddObjectAt(I)
Dim obj As ChilkatJsonObject
Set obj = wordArray.ObjectAt(I)
success = obj.UpdateString("word", word)
success = obj.UpdateString("font", font)
success = obj.UpdateString("color", color)
success = obj.UpdateString("bgColor", bgColor)
success = obj.UpdateString("type", type1)
Next
'wordArray.EmitCompact = 0 换行,此处不需要
TextBoxContent.Text = wordArray.Emit()
效果:
实测有效,问题解决。