还在处理我的第一个VBA脚本,但是我被卡住了。我想将变量设置为单元格值和文本,但它只允许我将变量设置为一个或另一个,而不是两者。
示例:
Dim Week As Range
Dim WeekCurrent As String
Set Week = .Range("F4")
If Week.Value = "Initial Week" Then
WeekCurrent = "Initial Week"
Else
WeekCurrent = "Week #" Week.Value
End If
所需结果:“初始周”或“周#x”稍后再打电话。
我可以将其设置为"Week #"
文本或Week.Value
,但不能同时设置为private void dgvCompany_SelectionChanged(object sender, EventArgs e)
{
if (dgvCompany.CurrentCell != null)
{
DataView dv = new DataView();
dv.Table = htctDataSet.co_lang;
int irow = dgvCompany.CurrentCell.RowIndex;
DataRow daRow = htctDataSet.company.Rows[irow]; // use this to get value used in filter below:
string s = daRow.Field<int>("company_id").ToString(); // this throw exception after doing a delete
dv.RowFilter = "company_id = " + s; //edited to show above line is problem
dgvLang.DataSource = dv;
}
}
。我确定我使用了错误的声明或其他东西。
截至目前,我的解决方法涉及将我想要使用此变量的任何实例更改为IF THEN ELSE并将编码量加倍,因为我必须复制代码。感谢您的反馈。
答案 0 :(得分:1)
另一种方法可能是:
If IsNumeric(Week) Then WeekCurrent = "Week #" & Week Else WeekCurrent = Week