简体   繁体   English

如何更改VBA数组十进制分隔符?

[英]How to change VBA array decimal separator?

I would like to change VBA array decimal separator to dot. 我想将VBA数组十进制分隔符更改为点。 I see it as comma. 我将其视为逗号。 I tried: Application.DecimalSeparator="." 我尝试了: Application.DecimalSeparator="."

But when I get the value as MyString = matrix(2, 1) , the decimal separator in VBA arrays maliciously persists as comma. 但是,当我获得MyString = matrix(2, 1) ,VBA数组中的小数点分隔符会以逗号形式恶意保留。 I am not able to get rid of the pest. 我无法除掉害虫。

Is there a way to detect which system separator for VBA arrays is used? 有没有一种方法可以检测使用哪个VBA阵列系统分隔符?

在此处输入图片说明

VBA uses quite a few bits drawn from various parts of the platform to work out which decimal and thousands separator to use. VBA使用从平台各个部分提取的很多位来计算要使用的十进制和千位分隔符。 Application.DecimalSeparator changes a few instances (mostly on the workbook); Application.DecimalSeparator更改了一些实例(大部分在工作簿上); you can tweak others at the OS level, but even then though you get to a couple of cases where you can't change the settings. 您可以在OS级别上调整其他设置,但即使在某些情况下,您也无法更改设置。

Your best bet is to write a simple function to check which separator your platform uses based on a trial conversion of say 1.2 to a string and see what the second character ends up being. 最好的选择是编写一个简单的函数,根据例如1.2到字符串的试验转换来检查平台使用的分隔符,并查看第二个字符最终是什么。 Crude but strangely beautiful. 粗俗但美丽。

Armed with that you can force an interchange of . 有了这个,您就可以强制互换。 and , as appropriate. 和,视情况而定。 Naturally then though you will have to manage all string to number parsing yourself, with some care. 当然,尽管如此,您必须谨慎管理所有字符串以对自己的数字进行解析。

Personally though I think this is epitomises an unnecessary fight with your system settings. 就我个人而言,尽管我认为这是与系统设置不必要的斗争的缩影。 Therefore I would leave everything as it is; 因此,我会保留一切。 grin and bear it in other words. 换句话说,笑着忍受。

您必须在系统设置中进行更改,Excel会从系统中获取这种设置。

I have end up with this function which does exactly what I want. 我最终得到了该功能,该功能正是我想要的。 Thank you all for answers, comments and hints. 谢谢大家的回答,评论和提示。

Function GetVBAdecimalSep()
    Dim a(0) As Variant
    a(0) = 1 / 2
    GetVBAdecimalSep = Mid(a(0), 2, 1)
End Function

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM