Shell中图像尺寸字符串中的Replace()问号 [英] Replace() question mark in image dimensions string from Shell
问题描述
我正在尝试通过使用VBA中的Shell对象来获取位图的高度.
I'm trying to get the height of a bitmap by using the Shell object in VBA.
这是代码的相关部分(bmp
是自定义类的成员,而.Width
是定义为Integer的属性.)
Here is the relevant portion of code (bmp
is a member of a custom class, and .Width
is a property defined as an Integer.)
Set objImg = objShell.Namespace(subfs(sf)).ParseName(bmp.Name)
tmpDim = objShell.Namespace(subfs(sf)).GetDetailsOf(objImg, 162)
tmpDim = Replace(tmpDim, "?", "")
tmpDim = Replace(tmpDim, " pixels", "")
bmp.Width = CInt(tmpDim)
由于tmpDim的值为?754
,所以我在最后一行收到类型不匹配错误.作为参考,第二行之后的tmpDim值为?754 pixels
.
I'm getting a Type Mismatch error on the last line because the value of tmpDim is ?754
. For reference, the value of tmpDim after the second line is ?754 pixels
.
我有一个步骤用空字符串替换?
,但是它不起作用.如何摆脱问号字符?
I have a step to replace the ?
with an empty string, but it does not work. How can I get rid of the question mark character?
推荐答案
您看到的问号实际上不是问号. Asc()函数将返回值63,但是AscW()将可能返回8206,即从左到右的unicode标记.
The question mark you are seeing is not actually a question mark. The Asc() function will return a value of 63, but AscW() will probably return 8206, the unicode left-to-right mark.
我相信VBA使用两字节宽的字符存储字符串. Asc函数只会返回0-255的值,对于超出该范围的任何内容,似乎会返回63.
I believe VBA stores strings using two-byte wide characters. The Asc function will only return a value of 0-255 and appears to return 63 for anything outside that range.
这就是为什么您的Replace(tmpDim, "?", "")
无法正常工作的原因.
您正在尝试等价的
This is why your Replace(tmpDim, "?", "")
doesn't work.
You're trying the equivilent of
Replace(tmpDim, Chr(63), "")
您需要
Replace(tmpDim, ChrW(8206), "")
(假设?是从左到右的标记,在我的测试中是这样)
(Assuming the ? is the left-to-right mark, which in my testing it is)
这篇关于Shell中图像尺寸字符串中的Replace()问号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!