是否可以在声明阶段更改变量的名称?

时间:2017-06-26 20:09:34

标签: arrays vb.net variables

我有一个包含10个元素的向量,其中包含的名称 respectivepanels。因为我不想重复10的命令 倍。只有一个语句有一个系统可以做到这一点。怎么做 你通常这样做:

Ext.define('CustomApp', {
  extend: 'Rally.app.App',
  componentCls: 'app',
  launch: function() {
    this.myGrid_Issue = null;
    this.myGrid_Risk = null;
    this._store_Risk();
  },

  _store_Risk: function(id) {
    var myFilter_risk = Ext.create('Rally.data.wsapi.Filter', {
      property: 'c_RAIDType',
      operation: '=',
      value: 'Risk'
    });
    console.log('Filter Risk ', myFilter_risk);
    var store_Risk = Ext.create('Rally.data.wsapi.Store', { // create 
      model: 'PortfolioItem',
      limit: Infinity,
      autoLoad: true,
      filters: myFilter_risk,
      fetch: ['FormattedID', 'Name', 'c_RAIDType'],
    });
    console.log('Store Risk ', store_Risk);
    var myGrid_Risk = Ext.create('Ext.container.Container', {
      items: [{
        xtype: 'rallygrid',
        model: 'PortfolioItem',
        store: store_Risk,
        height: '100%',
        columnCfgs: ['FormattedID', 'Name'],
      }],
    });
    console.log('Grid Risk ', myGrid_Risk);
    var myFilter_Issue = Ext.create('Rally.data.wsapi.Filter', {
      property: 'c_RAIDType',
      operation: '=',
      value: 'Issue'
    });
    console.log('Filter Issue ', myFilter_Issue);
    var store_Issue = Ext.create('Rally.data.wsapi.Store', { // create 
      model: 'PortfolioItem',
      limit: Infinity,
      autoLoad: true,
      filters: myFilter_Issue,
      fetch: ['FormattedID', 'Name', 'c_RAIDType'],
    });
    console.log('Store Issue ', store_Issue);
    var myGrid_Issue = Ext.create('Ext.container.Container', {
      items: [{
        xtype: 'rallygrid',
        model: 'PortfolioItem',
        store: store_Issue,
        height: '100%',
        columnCfgs: ['FormattedID', 'Name'],
      }],
    });
    console.log('Grid Issue ', myGrid_Issue);
    var output = Ext.create('Ext.TabPanel', {
      items: [{
        title: 'Risks',
        items: [
          myGrid_Risk
        ]
      }, {
        title: 'Issues',
        items: [
          myGrid_Issue
        ]
      }]
    });
    this.add(output);
  },
});

示例:

Dim Test As New Panel 
Test.size = new point (10.10)
Test.location = new point (10.10) me.controls.add (test) 

1 个答案:

答案 0 :(得分:0)

假设包含名称的数组名为“vector”,并且已经填充了10个项目,则可以执行此操作:

For n as Integer = 0 to 9
    Me.Controls.Add(new Panel() With {.Name = vector(n), .Size = New Point(10, 10), .Location=New Point(10,10)})
Next

然后您可以通过多种方式与其互动:

'if you know the actual name:
Dim pnlMyPanel as Panel = DirectCast(Me.Controls("pnlFirstPanel"), Panel)

'if you know the index in the vector containing the name:
Dim pnlMyOtherPanel as Panel = DirectCast(Me.Controls(vector(1)), Panel)

'Interact with it as you would any control:
pnlMyPanel.Visible = True
pnlMyPanel.Top = 100