【发布时间】:2014-01-23 21:33:19
【问题描述】:
VBA 新手。我正在尝试建立一个Dimensions的值(从Excel电子表格中的两个不同的单元格中提取,其中一个可能大于另一个,我总是希望首先使用较小的数字)其中输出(一个将被连接的字符串来自其他函数的字符串)可能是以下之一:
4868(没有 x 分隔整数值) 48x60.5(用 x 分隔整数和实数) 36.5x60(x 分隔实数和整数) 24.75x72.125(x 分隔实数和整数)
变量类型在 VBA 中定义为 Single(不是 Double)。这是我的代码:
Function getDimDisplay(h As Single, w As Single) As String
Dim strResult As String
Dim iH As Integer
Dim iW As Integer
Dim strH As Variant
Dim strW As Variant
iH = CInt(h)
iW = CInt(w)
Select Case h
Case (h >= w And iH = h And iW = w)
strH = CStr(iH)
strW = CStr(iW)
strResult = strW & strH
Case (h >= w And iH <> h And iW = w)
strH = CStr(h)
strW = CStr(iW)
strResult = strW & "x" & strH
Case (w >= h And iH = h And iW <> w)
strH = CStr(iH)
strW = CStr(w)
strResult = strH & "x" & strW
Case (w >= h And iH <> h And iW <> w)
strH = CStr(h)
strW = CStr(w)
strResult = strH & "x" & strW
End Select
getDimDisplay = strResult
End Function
它会编译,但不会返回任何输出。什么给了?
【问题讨论】:
-
哎呀,刚刚意识到最后一个case语句是实数和实数。大脑打嗝....
-
那么...你的问题解决了吗?如果是,请删除帖子或自己回答(请参阅屏幕底部的按钮)。
-
仍在修修补补.....它适用于大多数情况,但不是全部。