动态附加年份名称的VBA函数

时间:2015-07-07 18:55:07

标签: vba ms-access access-vba

我在Access中有一个表单,每年都有复选框。复选框命名为ch +(无论哪一年) 我想编写运行依赖于复选框的查询,但我不想为每个框重写它,所以我正在编写一个以年份为输入的函数,检查是否选中了该年份的框,然后运行查询是否已被选中。

我试过这样的事情:

struct Exercises {
  let category: String
  let name : String
  let x_seed: [Double]
  let y_seed: [Double]
  let hasMult: Bool
}

let exercises = [
  Exercises(category:"Sports", name:"Bowling", x_seed:[125,155,185], y_seed:[3.00, 3.73, 4.43], hasMult:false),
  Exercises(category:"Sports", name:"Water Polo", x_seed:[125,155,185], y_seed:[10.00, 12.40,14.80], hasMult:false),
  Exercises(category:"Sports", name:"Handball", x_seed:[125,155,185], y_seed:[12.00, 14.87, 17.77], hasMult:false),
  Exercises(category:"Sports", name:"Dancing", x_seed:[125,155,185], y_seed:[3.00, 3.73, 4.43], hasMult:true),
  Exercises(category:"Sports", name:"Frisbee", x_seed:[125,155,185], y_seed:[3.00, 3.73, 4.43], hasMult:false),
  Exercises(category:"Sports", name:"Volleyball", x_seed:[125,155,185], y_seed:[3.00, 3.73, 4.43], hasMult:false),
  Exercises(category:"Sports", name:"Archery", x_seed:[125,155,185], y_seed:[3.50, 4.33, 5.17], hasMult:false),
  Exercises(category:"Sports", name:"Golf", x_seed:[125,155,185], y_seed:[3.50, 4.33, 5.17], hasMult:true)
]

let options = NSStringCompareOptions.CaseInsensitiveSearch | NSStringCompareOptions.DiacriticInsensitiveSearch

// Filter exercises by name (case and diacritic insensitive)
let filteredExercises = exercises.filter {
  $0.name.rangeOfString("Ol", options: options) != nil
}

let filteredExerciseNames = ", ".join(filteredExercises.map({ $0.name }))
println(filteredExerciseNames)

似乎设置一个字符串变量等于我想要检查的表单中的布尔变量的名称不起作用。

如何编写年份输入的函数,然后测试与该年度相关的表格中的复选框是否为真?

由于

1 个答案:

答案 0 :(得分:1)

试试这个:

var str = '123?type=hand&status=alive';
var re = /[?&]([^=]+)/g; 
var m;
var result = [];

while ((m = re.exec(str)) !== null) {
    if (m.index === re.lastIndex)
        re.lastIndex++;
    result.push(m[1]);
}

console.log(result);
//=> ["type", "status"]