问题描述
非常简单:我想要一个编辑字段,其中已经有文本(一种默认值),但是它也是可编辑的。 我尝试了很多不同的版本,但还没有什么想要工作的。
这是我尝试的最后一个版本(复选框可以正常运行):
<Property Id="MYPROPERTY" Value="default" />
<UI>
<Dialog Id="ConfigVariablesDlg" Width="370" Height="270">
<Control Type="Edit" Id="InputField" Property="MYPROPERTY" X="125" Y="27" Width="100" Height="15" Indirect="yes" Text="[MYPROPERTY]">
<Condition Action="disable"><![CDATA[EnableBox<>"1"]]></Condition>
<Condition Action="enable">EnableBox="1"</Condition>
</Control>
<Control Type="CheckBox" Id="MyBox" Width="10" Height="10" X="110" Y="30" Property="EnableBox" CheckBoxValue="1"/>
</Dialog>
</UI>
解决方法
定义属性时,只需为它分配一个这样的值
Sub KNMsemiAutomaticCleaner()
'looks for column with KNM_X coordinate
Set aCell = Range("2:2").Find(What:="RKNM")
RKNM_X_col = aCell.Column
'Finds the last row with data,i.e.,last non-blank cell in column A(1)
firstRow = 7
lastRow = Cells(Rows.Count,1).End(xlUp).Row
'loops through each cell with data in the column
For i = firstRow To lastRow - firstRow
'finds outliers in RKNM and asks if delete
VariationFramesRange = 20
If i > firstRow + VariationFramesRange And IsEmpty(Cells(i,RKNM_X_col)) = False Then
VariationMin = WorksheetFunction.Min(Range(Cells(i - VariationFramesRange,RKNM_X_col),Cells(i - 1,RKNM_X_col)))
VariationMax = WorksheetFunction.Max(Range(Cells(i - VariationFramesRange,RKNM_X_col)))
VariationRange = VariationMax - VariationMin
'searches for last non-zero and non-empty prior value of KNM_X
For pre = 1 To 100
If Abs(Cells(i - pre,RKNM_X_col).Value) > 0 Then
LastValue = Cells(i - pre,RKNM_X_col).Value
Exit For
End If
Next
'tests if the actual value of KNM_X is an outlier,compares if the difference between actual value and last value of KNM_X is greater than range of values within last 20 cells
If Abs(Cells(i,RKNM_X_col).Value - LastValue) > VariationRange Then
'if actual value seems to be outlier,it creates a XY chart which shows the last 20 and next 5 values of KNM_X so the operator can visualy determine if the value is really an outlier
Dim ochartObj As ChartObject
Dim oChart As Chart
Set rng = Range(Cells(i - 20,RKNM_X_col + 4),Cells(i - 5,RKNM_X_col + 9)) 'Area to put the chart in
Set ochartObj = ActiveSheet.ChartObjects.Add(Left:=rng.Left,Width:=rng.Width,Top:=rng.Top,Height:=rng.Height)
Set oChart = ochartObj.Chart
oChart.ChartType = xlXYScatterLines
oChart.SeriesCollection.Add Source:=Range("a" & i)
oChart.SeriesCollection(1).Name = "Context"
oChart.SeriesCollection(1).XValues = Range(Cells(i - 20,1),Cells(i + 5,1))
oChart.SeriesCollection(1).Values = Range(Cells(i - 20,RKNM_X_col))
oChart.SeriesCollection.Add Source:=Range("a" & i)
oChart.SeriesCollection(2).Name = "Outlier"
oChart.SeriesCollection(2).XValues = Range("a" & i)
oChart.SeriesCollection(2).Values = Range("cb" & i)
ochartObj.Visible = True ' this does not help
'moves the screen to chart and selects cells with coordinates of the identified outlier
Application.Goto Range(Cells(i - 20,Cells(i - 20,RKNM_X_col + 2)),Scroll:=True
Range(Cells(i,Cells(i,RKNM_X_col + 2)).Select
'Application.Wait (Now + TimeValue("0:00:05")) 'does not help either
'creates MsgBox which asks whether to delete the outlier
Result = MsgBox("Delete frame " & i - 5 & "?",vbYesNoCancel + vbQuestion)
If Result = vbYes Then
Range(Cells(i,RKNM_X_col + 2)).Clear
MsgBox "Frame deleted."
ElseIf Result = vbCancel Then
Exit Sub
End If
'deletes the chart
ochartObj.Delete
End If
End If
Next
End Sub
因此,您从<Property Id="MYPROPERTY">Text you want to fill in</Property>
元素中删除了Value字段,并事先定义了Property。 (仍在您的UI元素中!)
所以最后,您的代码应该看起来像这样
Control
*编辑我也很漂亮(但不是完全确定)
<UI>
<Property Id="MYPROPERTY">Text you want to fill in</property>
<Dialog Id="ConfigVariablesDlg" Width="370" Height="270">
<Control Type="Edit" Id="InputField" Property="MYPROPERTY" X="125" Y="27" Width="100" Height="15" Indirect="yes">
<Condition Action="disable"><![CDATA[EnableBox<>"1"]]></Condition>
<Condition Action="enable">EnableBox="1"</Condition>
</Control>
<Control Type="CheckBox" Id="MyBox" Width="10" Height="10" X="110" Y="30" Property="EnableBox" CheckBoxValue="1"/>
</Dialog>
应该是
![CDATA[EnableBox<>"1"]]
这至少对我有用