如何在VBA中的输入字符串中使用引号?

时间:2022-04-28 16:01:44

I'm trying to input ColumnWidths for a listbox in MS-Access2007 VBA and I'm having a problem getting it to take decimal numbers.

我正在尝试为MS-Access2007 VBA中的列表框输入ColumnWidths,我在使用十进制数字时遇到问题。

Code:

ResultList.ColumnWidths = "1;0.65;0.7;0.7;0.8;0.4"
Debug.Print ResultList.ColumnWidths

What gets put in for the ColumnWidths:

为ColumnWidths放入的内容:

1;1;1;1;1;0

The way I want to get it to look after entered (based on what's there now):

我希望得到它的方式输入(根据现在的情况):

1";0.65";0.7";0.7";0.8";0.4"

Question:

How do I get it to recognize that I want the decimals there so that it stops rounding? Is there a way to have quotation marks inside the string you want to enter?

如何让它识别出我想要小数点以便它停止舍入?有没有办法在你想要输入的字符串中加上引号?

2 个解决方案

#1


ResultList.ColumnWidths = "1 cm;0.65 cm;0.7 cm;0.7 cm;0.8 cm;0.4 cm"

Look at the documentation for ColumnWidths. It says

查看ColumnWidths的文档。它说

The ColumnWidths property holds a value specifying the width of each column in inches or centimeters, depending on the measurement system (U.S. or Metric) selected in the Measurement system box on the Number tab of the Regional Options dialog box of Windows Control Panel. The default setting is 1 inch or 2.54 centimeters. The ColumnWidths property setting must be a value from 0 to 22 inches (55.87 cm) for each column in the list box or combo box.

ColumnWidths属性包含一个值,以英寸或厘米为单位指定每列的宽度,具体取决于在Windows控制面板的“区域选项”对话框的“数字”选项卡上的“测量系统”框中选择的测量系统(美国或公制)。默认设置为1英寸或2.54厘米。对于列表框或组合框中的每列,ColumnWidths属性设置必须是0到22英寸(55.87厘米)的值。

EDIT: You could specify the widths in inches as well.

编辑:你也可以用英寸指定宽度。

ResultList.ColumnWidths = "1 in;0.65 in;0.7 in;0.7 in;0.8 in;0.4 in"

#2


Shahkalpesh gave you the solution to your problem, but the answer to your actual question is to double up each quote mark in the string.

Shahkalpesh为您提供了解决问题的方法,但您实际问题的答案是将字符串中的每个引号加倍。

sWidths = "1"";0.65"";0.7"";0.7"";0.8"";0.4"""
Debug.Print sWidths

->  1";0.65";0.7";0.7";0.8";0.4"

It's very unbeautiful! This is how you would do it in a regular VB string variable, but it's not the correct syntax for that property.

这非常不美观!这是您在常规VB字符串变量中执行此操作的方法,但它不是该属性的正确语法。

#1


ResultList.ColumnWidths = "1 cm;0.65 cm;0.7 cm;0.7 cm;0.8 cm;0.4 cm"

Look at the documentation for ColumnWidths. It says

查看ColumnWidths的文档。它说

The ColumnWidths property holds a value specifying the width of each column in inches or centimeters, depending on the measurement system (U.S. or Metric) selected in the Measurement system box on the Number tab of the Regional Options dialog box of Windows Control Panel. The default setting is 1 inch or 2.54 centimeters. The ColumnWidths property setting must be a value from 0 to 22 inches (55.87 cm) for each column in the list box or combo box.

ColumnWidths属性包含一个值,以英寸或厘米为单位指定每列的宽度,具体取决于在Windows控制面板的“区域选项”对话框的“数字”选项卡上的“测量系统”框中选择的测量系统(美国或公制)。默认设置为1英寸或2.54厘米。对于列表框或组合框中的每列,ColumnWidths属性设置必须是0到22英寸(55.87厘米)的值。

EDIT: You could specify the widths in inches as well.

编辑:你也可以用英寸指定宽度。

ResultList.ColumnWidths = "1 in;0.65 in;0.7 in;0.7 in;0.8 in;0.4 in"

#2


Shahkalpesh gave you the solution to your problem, but the answer to your actual question is to double up each quote mark in the string.

Shahkalpesh为您提供了解决问题的方法,但您实际问题的答案是将字符串中的每个引号加倍。

sWidths = "1"";0.65"";0.7"";0.7"";0.8"";0.4"""
Debug.Print sWidths

->  1";0.65";0.7";0.7";0.8";0.4"

It's very unbeautiful! This is how you would do it in a regular VB string variable, but it's not the correct syntax for that property.

这非常不美观!这是您在常规VB字符串变量中执行此操作的方法,但它不是该属性的正确语法。