我有一个VB项目,我试图使用一些VBA代码,根据Excel工作表的第一列找到重复的行,并创建一个" 1"的标志,但是当VBA代码时在VB中使用会给出错误:
InvalidCastException未处理 重载决议失败,因为没有Public'<>'可以使用以下参数调用: '公共共享运算符<>(as As String,b As String)As Boolean': 参数匹配参数' a'无法转换为' __ ComObject'到' String'。
- (void)viewDidLoad {
[self drawText];
[super viewDidLoad];
AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
NSFetchRequest *request = [[NSFetchRequest alloc]init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Guest" inManagedObjectContext:appDelegate.managedObjectContext];
[request setEntity:entity];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSError *error;
NSArray *fetchedObjects = [context executeFetchRequest:request error:&error];
NSString*guestString =@"";
for(NSManagedObject *obj in fetchedObjects) {
guestString =[guestString stringByAppendingString:[NSString stringWithFormat:@"%@ %@ %@\n",[obj valueForKey:@"guestLastName" ],[obj valueForKey:@"guestName"],[obj valueForKey:@"guestZipCode"];
}
self.textView.text = guestString;
for(NSManagedObject *obj in fetchedObjects)
{
NSLog(@"Name:%@\n Last Name %@\n" , [obj valueForKey:@"guestName"],[obj valueForKey:@"guestLastName"]);
}
}
任何帮助都会非常理解为什么会出现这种错误
答案 0 :(得分:2)
当单元格为空时,调用MainSheet1.Cells(Duplicate_ID,1)给出Nothing(null)。因此,不要将其与字符串匹配,请将其检查为空值。
If MainSheet1.Cells(Duplicate_ID, 1) IsNot Nothing Then
End If
答案 1 :(得分:0)
使用IsNot
代替<>
If Duplicate_ID IsNot Duplicate_Found_Index Then 'if the match index is not equals to current row number, then it is a duplicate value
MainSheet1.Cells(Duplicate_ID, 34) = "1"
Else
MainSheet1.Cells(Duplicate_ID, 34) = "0"
End If