我在Invalid Qualifier
行中遇到Cbx_name(i).Clear
错误。这段代码放在一个单独的模块中,我将在UserForms事件中使用:Call Dynamic_cbx
。我相信我使用[UserForm Name].[Combo Box Name]
形式在模块中正确引用了它,但是我不确定。
Option Explicit
Sub Dynamic_cbx()
Dim dCell As Range
Dim dict As Scripting.Dictionary
Dim Cbx_count As Long, i As Long
Cbx_count = 8
ReDim Cbx_loop(1 To Cbx_count) As Long, Cbx_name(1 To Cbx_count) As Long
Cbx_loop(1) = ThisWorkbook.Worksheets("Foil Profile").ListObjects("tblFoilProfile").ListColumns("SUPPLIER").Index
Cbx_loop(2) = ThisWorkbook.Worksheets("Foil Profile").ListObjects("tblFoilProfile").ListColumns("FOIL DESCRIPTION").Index
Cbx_loop(3) = ThisWorkbook.Worksheets("Foil Profile").ListObjects("tblFoilProfile").ListColumns("BRAND").Index
Cbx_loop(4) = ThisWorkbook.Worksheets("Foil Profile").ListObjects("tblFoilProfile").ListColumns("COLOR NUMBER").Index
Cbx_loop(5) = ThisWorkbook.Worksheets("Foil Profile").ListObjects("tblFoilProfile").ListColumns("FOIL WIDTH").Index
Cbx_loop(6) = ThisWorkbook.Worksheets("Foil Profile").ListObjects("tblFoilProfile").ListColumns("UOM (Foil Width)").Index
Cbx_loop(7) = ThisWorkbook.Worksheets("Foil Profile").ListObjects("tblFoilProfile").ListColumns("FOIL LENGTH").Index
Cbx_loop(8) = ThisWorkbook.Worksheets("Foil Profile").ListObjects("tblFoilProfile").ListColumns("UOM (Foil Length)").Index
Cbx_name(1) = frmFoilPanel.cbxSupplier
Cbx_name(2) = frmFoilPanel.cbxFoilDescription
Cbx_name(3) = frmFoilPanel.cbxFoilBrand
Cbx_name(4) = frmFoilPanel.cbxColorNumber
Cbx_name(5) = frmFoilPanel.cbxFoilWidth
Cbx_name(6) = frmFoilPanel.cbxUOMfw
Cbx_name(7) = frmFoilPanel.cbxFoilLength
Cbx_name(8) = frmFoilPanel.cbxUOMfl
For i = 1 To Cbx_count
Cbx_name(i).Clear
Next i
For i = 1 To Cbx_count
With dict
For Each dCell In ThisWorkbook.Worksheets("List_Box").Range(Col_Letter(i) & "2:" & Col_Letter(i) & TotalRowsCount("Foil Purchases.xlsm", "List_Box", "tblFoilInfoHelper"))
If Not .exists(dCell.Value) Then
.Add dCell.Value
End If
Next dCell
Cbx_name(i).List = .keys
Set dict = Nothing
End With
Next i
End Sub
答案 0 :(得分:0)
这是一个数组。要清空索引处的内容,
//+------------------------------------------------------------------+
//| Tops.mq4 |
//| nicholishen |
//| https://www.forexfactory.com/nicholishen |
//+------------------------------------------------------------------+
#property copyright "nicholishen"
#property link "https://www.forexfactory.com/nicholishen"
#property version "1.00"
#property strict
#property indicator_chart_window
#include <arrays/list.mqh>
#include <chartobjects/chartobjectslines.mqh>
class Line : public CChartObjectTrend
{
static int m_instances;
int m_instance;
public:
Line(datetime t1, double p1, datetime t2, double p2){
m_instance = ++m_instances;
this.Create(0, "Line_"+string(m_instance), 0, t1, p1, t2, p2);
this.Color(clrMagenta);
this.RayRight(false);
}
};
int Line::m_instances = 0;
CList list;
//+------------------------------------------------------------------+
int OnInit(){return(INIT_SUCCEEDED);}
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
if(list.Total() > 0)
return(rates_total);
for(int i=0; i<10; i++) {
list.Add(new Line(time[i+1], high[i+1], time[i], high[i]));
}
return rates_total;
}
//+------------------------------------------------------------------+
没有用于数组索引的.clear方法。