刚学习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
它可以编译,但不会返回任何输出。出了什么问题?