我以前发布了此信息。但是,从那时起,我就能够找出按字母顺序排列的集合。我把帖子删除了,因为那是一团糟。
我想按字母顺序排列用户窗体控件,因为它们位于窗体上。我按字母顺序排列了该集合,但是,我在代码的顺序上苦苦挣扎。现在,只添加第一行。
这是它的外观:
Private Sub UserForm_Initialize()
On Error GoTo Err_UserForm_Initialize
Set objNode = ActiveDocument.CustomXMLParts.SelectByNamespace("http://schemas.rlicorp.net/ContentManagement.Claims").Item(1).DocumentElement
If objNode.SelectSingleNode("/ns0:Claim[1]/ns0:Contacts[1]") Is Nothing Then
Exit Sub
End If
Dim ctlTo As Control
Dim ctlCc As Control
Dim ctlName As Control
Dim ctlTempName As Control
Dim ctlAddress1 As Control
Dim ctlAddress2 As Control
Dim ctlCity As Control
Dim ctlState As Control
Dim ctlZIP As Control
Dim ctlRole As Control
Dim cName As Variant
Dim tempname As String
Dim coll As Collection
Dim i As Long
Dim nAddresses As Integer
Set objNode = ActiveDocument.CustomXMLParts.SelectByNamespace("http://schemas.rlicorp.net/ContentManagement.Claims").Item(1).DocumentElement
nAddresses = 0
Set coll = nameCollection
For i = 1 To Int(objNode.SelectSingleNode("/ns0:Claim[1]/ns0:Contacts[1]").ChildNodes.Count)
Set objNode1 = objNode.SelectSingleNode("/ns0:Claim[1]/ns0:Contacts[1]").ChildNodes(i)
If (Not (objNode1.SelectSingleNode("ns0:Address1[1]") Is Nothing)) Or _
(Not (objNode1.SelectSingleNode("ns0:Name[1]") Is Nothing)) Then
nAddresses = nAddresses + 1
For Each cName In nameCollection
If Not (objNode1.SelectSingleNode("ns0:Name[1]") Is Nothing) Then
tempname = objNode1.SelectSingleNode("ns0:Name[1]").Text
End If
If cName <> tempname Then Exit For
Debug.Print cName
Set ctlTo = fraSelectContact.Controls.Add("Forms.Checkbox.1", "chkTo" & nAddresses)
ctlTo.Left = lblTo.Left
ctlTo.Top = lblTo.Top + 20 + (nAddresses - 1) * 30
Set ctlCc = fraSelectContact.Controls.Add("Forms.Checkbox.1", "chkCc" & nAddresses)
ctlCc.Left = lblCc.Left
ctlCc.Top = lblCc.Top + 20 + (nAddresses - 1) * 30
Set ctlName = fraSelectContact.Controls.Add("Forms.TextBox.1", "txtName" & nAddresses)
ctlName.Left = lblName.Left
ctlName.Top = lblName.Top + 20 + (nAddresses - 1) * 30
ctlName.Width = 130
ctlName.Text = cName
Set ctlAddress1 = fraSelectContact.Controls.Add("Forms.TextBox.1", "txtAddress1_" & nAddresses)
ctlAddress1.Left = lblAddress1.Left
ctlAddress1.Top = lblAddress1.Top + 20 + (nAddresses - 1) * 30
ctlAddress1.Width = 170
If Not (objNode1.SelectSingleNode("ns0:Employer[1]") Is Nothing) Then
ctlAddress1.Text = objNode1.SelectSingleNode("ns0:Employer[1]").Text & ";"
End If
If Not (objNode1.SelectSingleNode("ns0:Address1[1]") Is Nothing) Then
ctlAddress1.Text = ctlAddress1.Text & objNode1.SelectSingleNode("ns0:Address1[1]").Text
End If
Set ctlAddress2 = fraSelectContact.Controls.Add("Forms.TextBox.1", "txtAddress2_" & nAddresses)
ctlAddress2.Left = lblAddress2.Left
ctlAddress2.Top = lblAddress2.Top + 20 + (nAddresses - 1) * 30
ctlAddress2.Width = 160
If Not (objNode1.SelectSingleNode("ns0:Address2[1]") Is Nothing) Then
ctlAddress2.Text = objNode1.SelectSingleNode("ns0:Address2[1]").Text
End If
Set ctlCity = fraSelectContact.Controls.Add("Forms.TextBox.1", "txtCity" & nAddresses)
ctlCity.Left = lblCity.Left
ctlCity.Top = lblCity.Top + 20 + (nAddresses - 1) * 30
ctlCity.Width = 60
If Not (objNode1.SelectSingleNode("ns0:City[1]") Is Nothing) Then
ctlCity.Text = objNode1.SelectSingleNode("ns0:City[1]").Text
End If
Set ctlState = fraSelectContact.Controls.Add("Forms.TextBox.1", "txtState" & nAddresses)
ctlState.Left = lblState.Left
ctlState.Top = lblState.Top + 20 + (nAddresses - 1) * 30
ctlState.Width = 30
If Not (objNode1.SelectSingleNode("ns0:State[1]") Is Nothing) Then
ctlState.Text = objNode1.SelectSingleNode("ns0:State[1]").Text
End If
Set ctlZIP = fraSelectContact.Controls.Add("Forms.TextBox.1", "txtZIP" & nAddresses)
ctlZIP.Left = lblZIP.Left
ctlZIP.Top = lblZIP.Top + 20 + (nAddresses - 1) * 30
ctlZIP.Width = 50
If Not (objNode1.SelectSingleNode("ns0:Zip[1]") Is Nothing) Then
ctlZIP.Text = objNode1.SelectSingleNode("ns0:Zip[1]").Text
End If
Next cName
End If
Next i
Exit_UserForm_Initialize:
Exit Sub
Err_UserForm_Initialize:
MsgBox Err.Number & " _ " & Err.Description & vbCrLf & "Contact claimcenterhelp@rlicorp.com"
Resume Exit_UserForm_Initialize
End Sub
unction nameCollection() As Collection
Dim coll As Collection
Set coll = New Collection
Set objNode = ActiveDocument.CustomXMLParts.SelectByNamespace("http://schemas.rlicorp.net/ContentManagement.Claims").Item(1).DocumentElement
For i = 1 To Int(objNode.SelectSingleNode("/ns0:Claim[1]/ns0:Contacts[1]").ChildNodes.Count)
Set objNode1 = objNode.SelectSingleNode("/ns0:Claim[1]/ns0:Contacts[1]").ChildNodes(i)
If Not (objNode1.SelectSingleNode("ns0:Name[1]") Is Nothing) Then
coll.Add Item:=objNode1.SelectSingleNode("ns0:Name[1]").Text
End If
Next i
QuickSort coll, 1, coll.Count
Set nameCollection = coll
End Function
Sub QuickSort(coll As Collection, first As Long, last As Long)
Dim vCentreVal As Variant, vTemp As Variant
Dim lTempLow As Long
Dim lTempHi As Long
lTempLow = first
lTempHi = last
vCentreVal = coll((first + last) \ 2)
Do While lTempLow <= lTempHi
Do While coll(lTempLow) < vCentreVal And lTempLow < last
lTempLow = lTempLow + 1
Loop
Do While vCentreVal < coll(lTempHi) And lTempHi > first
lTempHi = lTempHi - 1
Loop
If lTempLow <= lTempHi Then
vTemp = coll(lTempLow)
coll.Add coll(lTempHi), After:=lTempLow
coll.Remove lTempLow
coll.Add vTemp, Before:=lTempHi
coll.Remove lTempHi + 1
lTempLow = lTempLow + 1
lTempHi = lTempHi - 1
End If
Loop
If first < lTempHi Then QuickSort coll, first, lTempHi
If lTempLow < last Then QuickSort coll, lTempLow, last
End Sub
运行此程序时,我没有收到任何错误,但这是表单最终看起来像的样子:
这是XML的简化版本
<?xml version="1.0" encoding="utf-8" ?>
- <Claim xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ID>00989876</ID>
<Description>General Liability</Description>
<ContractID>A78656789</ContractID>
+ <Contract>
- <Contacts>
- <ClaimContact>
<Name>John Doe</Name>
<Address1>PO Box 712</Address1>
<City>Jacksonville</City>
<State>FL</State>
<Zip>98631</Zip>
</ClaimContact>
- <ClaimContact>
<Name>Alton Carpeting</Name>
<Address1>4567 Watchworks Ave</Address1>
<City>Detroit</City>
<State>MI</State>
<Zip>98631</Zip>
</ClaimContact>
+ <ClaimContact>
+ <ClaimContact>
</Contacts>
<ClaimUser />
</Claim>
答案 0 :(得分:0)
最后弄清楚了。只需按正确的顺序放置语句即可。谢谢Mike和Cindy的帮助。
const PLUGIN_DIR_NAME = "mytheme";
const GENERAL_CONFIG_INI = "../config/config.ini";
const THEME_CONFIG_INI = "./config/config.ini";
const path = require('path');
const Promise = require('bluebird');
const fs = Promise.promisifyAll( require('fs') );
const ini = require('ini');
// include the css extraction and minification plugins
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CopyPlugin = require('copy-webpack-plugin');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
module.exports = env => {
const global_config = ini.parse( fs.readFileSync( GENERAL_CONFIG_INI, 'utf-8' ) );
const theme_config = ini.parse( fs.readFileSync( THEME_CONFIG_INI, 'utf-8' ) );
var a_author_uri = global_config.author_uri.split(":");
var author_protocol = a_author_uri[0];
var author_uri_without_protocol = a_author_uri[1].replace( "//", "" );
var a_author_uri_domain = author_uri_without_protocol.split(".");
var author_uri_domain_name, author_uri_extension;
if( a_author_uri_domain.length === 3 ){
author_uri_domain_name = a_author_uri_domain[1];
author_uri_extension = a_author_uri_domain[2];
}else if( a_author_uri_domain.length === 2 ){
author_uri_domain_name = a_author_uri_domain[0];
author_uri_extension = a_author_uri_domain[1];
}
var a_prev_theme_version = theme_config.theme_infos.version.split(".");
var prev_major_theme_version = parseInt( a_prev_theme_version[0] );
var prev_minor_theme_version = parseInt( a_prev_theme_version[1] );
var prev_patch_theme_version = parseInt( a_prev_theme_version[2] );
var prev_build_theme_version = parseInt( a_prev_theme_version[3] );
var next_build_theme_version, next_patch_theme_version, next_minor_theme_version, next_major_theme_version;
if( env.version === "build" ){
next_build_theme_version = prev_build_theme_version + 1;
next_patch_theme_version = prev_patch_theme_version;
next_minor_theme_version = prev_minor_theme_version;
next_major_theme_version = prev_major_theme_version;
}else if( env.version === "patch" ){
next_build_theme_version = 0;
next_patch_theme_version = prev_patch_theme_version + 1;
next_minor_theme_version = prev_minor_theme_version;
next_major_theme_version = prev_major_theme_version;
}else if( env.version === "minor" ){
next_build_theme_version = 0;
next_patch_theme_version = 0;
next_minor_theme_version = prev_minor_theme_version + 1;
next_major_theme_version = prev_major_theme_version;
}else if( env.version === "major" ){
next_build_theme_version = 0;
next_patch_theme_version = 0;
next_minor_theme_version = 0;
next_major_theme_version = prev_major_theme_version + 1;
}
theme_config.theme_infos.version = next_major_theme_version + "." + next_minor_theme_version + "." + next_patch_theme_version + "." + next_build_theme_version;
fs.writeFileSync( THEME_CONFIG_INI, ini.stringify( theme_config, {} ) );
return{
plugins: [
new CleanWebpackPlugin(),
// extract css into dedicated file
new MiniCssExtractPlugin({
filename: './' + PLUGIN_DIR_NAME + '/style.css'
}),
//Only copy php files
new CopyPlugin([
{
from: 'dev',
ignore: ['*.sass', 'next/css/common/**/*.css'],
},
])
],
entry: [ './dev/' + PLUGIN_DIR_NAME + '/style.sass', './dev/' + PLUGIN_DIR_NAME + '/css/common/normalize.css', './dev/' + PLUGIN_DIR_NAME + '/css/common/main.sass' ],
output: {
path: path.resolve(__dirname, 'dist/'),
},
module: {
rules: [
// compile all .scss files to plain old css
{
test: [/css\/common\/.*\.(css|sass)$/],
use: [{loader: MiniCssExtractPlugin.loader},
{loader: 'css-loader'},
{
loader: 'sass-loader',
options: {
prependData: '$theme-name: ' + theme_config.theme_infos.name +
';$author:' + global_config.author +
';$author-uri-protocol:' + author_protocol +
';$author-uri-domain:' + author_uri_domain_name +
';$author-uri-extension:' + author_uri_extension +
';$description:' + theme_config.theme_infos.description.replace(/:/g, "%3A").replace(/;/g, "%3B") + ';' +
';$version-major:' + next_major_theme_version + ';' +
';$version-minor:' + next_minor_theme_version + ';' +
';$version-patch:' + next_patch_theme_version + ';' +
';$version-build:' + next_build_theme_version + ';',
}
}
]
}
]
}
}
};