我正在尝试创建一个查看图像的函数,并返回X像素值。
当我运行代码时,它会在Int1 = CInt(Xdim)行上抛出一个错误,说“Type Mismatch(10080)”
如果我将我正在测试的值硬编码到Xdim中,它可以正常工作。
stackView = new UIStackView
{
Axis = UILayoutConstraintAxis.Vertical,
Alignment = UIStackViewAlignment.Center,
};
scroll = new UIScrollView() { };
Add(scroll);
scroll.AddSubview(stackView);
scroll.EnableAutoLayout();
scroll.FullSizeOf(View);
stackView.AddArrangedSubview(logo);
stackView.AddArrangedSubview(_activityIndicatorView);
//... more items
logo.HeightAnchor.ConstraintEqualTo(72).Active = true;
enterpriseCodeField.HeightAnchor.ConstraintEqualTo(50).Active = true;
enterpriseCodeField.WidthAnchor.ConstraintEqualTo(0.65f * View.Frame.Size.Width).Active = true;
//... more items
stackView.SetCustomSpacing(35, logo);
stackView.SetCustomSpacing(35, _activityIndicatorView);
//... more items
View.AddConstraint(NSLayoutConstraint.Create(stackView, NSLayoutAttribute.CenterY, 0, scroll, NSLayoutAttribute.CenterY, 1, 0));
View.AddConstraint(NSLayoutConstraint.Create(stackView, NSLayoutAttribute.CenterX, 0, scroll, NSLayoutAttribute.CenterX, 1, 0));
答案 0 :(得分:1)
首先检查值是否可以转换为整数:
If IsNumeric(Trim(Xdim)) then
Int1 = CInt(Xdim)
else
'for debug purposes
MsgBox ("XDim non-numeric or empty")
End If
答案 1 :(得分:0)
好吧,我无法找到导致问题的字符,所以我使用这个代码循环只提取数字,它似乎有效。
For X = 1 To Len(Xdim)
If IsNumeric(Mid(Xdim, X, 1)) = True Then
holder = holder & Mid(Xdim, X, 1)
End If
Next X
答案 2 :(得分:0)
此处为WIA版本:
Function ImgXDim(filename As String) As Long
Dim imgWIA as New WIA.ImageFile 'Early Binding needs a reference to Windows Image Aquisition Library in VBA-Ide->Tools->References
'Dim imgWIA as Object 'Late Bound Version
'Set imgWIA = CreateObject("WIA.ImageFile")
imgWIA.LoadFile MacroDir & "\PICS\" & filename
ImgXDim = imgWIA.Width ' use .Height for height
End Function
如您所见,只需三行代码并返回一个long,而不是需要解析的字符串。
如果要在图片控件中显示Tiff(逐页)等,也很有用。