复选框的.Value [英] The .Value of a Check Box

查看:73
本文介绍了复选框的.Value的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一堆复选框中只测试一个True值,所以我

计算我可以在添加值后测试精确到-1的值。


在下面的情况0中,它有效。但在所有其他情况下,它失败了,类型

错误。来找出,有时,没有*明显的*原因 - 真是

返回,在其他时间,-1。


有人可以解释这个(看似)随机行为,并告诉我一个方法来

强制整数结果? CInt(Me!c20)不起作用,也不使用

显式.Value属性。


----------- --------------------------------------

Dim i As Integer


选择Case Me!tPages.Value

案例0

i =我!c2 +我!c3

案例1

i =我!c20 +我!c36 +我!c15 +我!c25 +我!c29

结束选择

如果我<> -1然后

--------------------------------

-

Darryl Kerkeslager

解决方案



" Darryl Kerkeslager" ;写了

我想在一堆复选框中只测试一个True值,所以我想我可以测试一个值
在添加值后正好为-1。

在下面的情况0中,它有效。但是在所有其他情况下,它都失败了,出现Type
错误。来找出,有时,
没有*明显的*理由 - 真正的
返回,在其他时间,-1。

有人可以解释这个(貌似)
随机行为,并告诉我一种方法来强制整数结果? CInt(Me!c20)
没有用,也没有使用
显式.Value属性。




我不知道为什么CInt(Me!c20)对你不起作用。


以下内容直接从立即窗口复制。


? Cint(True)

-1

? Cint(-1)

-1


所以,在我看来Cint应该返回-1,无论控件是否有一个

值为True或值为-1。


我建议在每个控件上使用一些Debug.Print语句,并且

关于CInt应用于每个人尝试调试。


Larry Linson

Microsoft Access MVP


< blockquote>" Larry Linson" <博***** @ localhost.not>写了


我不知道为什么CInt(我!c20)不适合你。

以下内容直接从立即复制窗口。

? Cint(True)
-1
? Cint(-1)
-1

所以,在我看来,Cint应该返回-1,无论Control的值是True还是-1。




很幸运!根据您对我的代码正确性的信任,我找了另一个问题。
另一个问题。我意识到所有的问题区域首先要调用这个

代码:


Private Sub tPages_Change()

Dim ctl As Control

每个ctl In Me.Controls

如果ctl.ControlType = acCheckBox那么ctl.Value = ctl.DefaultValue

下一页

设置ctl = Nothing

End Sub

所以我搜索了Google的ctl.DefaultValue并且恰好读了一篇

帖子,其中作者使用Eval()来封闭ctl.DefaultValue。


我认为Access是随机的(大约15个) (%)将我的

默认的True和False值解释为字符串。 Eval()修正了这个问题。

-

Darryl Kerkeslager


只有字符串。


I wanted to test for only one True value in a bunch of checkboxes, so I
figured I could just test for a value of exactly -1 after adding the values.

In case 0 below, it worked. But in all other cases, it failed, with a Type
error. Come to find out, sometimes, for no *apparent* reason - "True" is
returned, at other times, -1.

Can someone explain this (seemingly) random behavior, and tell me a way to
force the integer result? CInt(Me!c20) did not work, nor di using the
explicit .Value property.

-------------------------------------------------
Dim i As Integer

Select Case Me!tPages.Value
Case 0
i = Me!c2 + Me!c3
Case 1
i = Me!c20 + Me!c36 + Me!c15 + Me!c25 + Me!c29
End Select

If i <> -1 Then
--------------------------------

--
Darryl Kerkeslager

解决方案


"Darryl Kerkeslager" wrote

I wanted to test for only one True value in
a bunch of checkboxes, so I
figured I could just test for a value of
exactly -1 after adding the values.

In case 0 below, it worked. But in all
other cases, it failed, with a Type
error. Come to find out, sometimes,
for no *apparent* reason - "True" is
returned, at other times, -1.

Can someone explain this (seemingly)
random behavior, and tell me a way to
force the integer result? CInt(Me!c20)
did not work, nor did using the
explicit .Value property.



I don''t know why CInt(Me!c20) didn''t work for you.

The following is copied directly from the Immediate Window.

? Cint(True)
-1
? Cint(-1)
-1

So, it appears to me that Cint should return -1 whether the Control has a
value of True or a value of -1.

I''d suggest uusing some Debug.Print statements on each of the Controls, and
on CInt applied to each of them to try to debug.

Larry Linson
Microsoft Access MVP


"Larry Linson" <bo*****@localhost.not> wrote


I don''t know why CInt(Me!c20) didn''t work for you.

The following is copied directly from the Immediate Window.

? Cint(True)
-1
? Cint(-1)
-1

So, it appears to me that Cint should return -1 whether the Control has a
value of True or a value of -1.



Got lucky! Based on your faith in the correctness of my code, I looked for
another problem. I realized that all the problem areas were calling this
code first:

Private Sub tPages_Change()
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.ControlType = acCheckBox Then ctl.Value = ctl.DefaultValue
Next
Set ctl = Nothing
End Sub
So I searched Google for "ctl.DefaultValue" and just happened to read one
post where the author used Eval() to enclose the ctl.DefaultValue.

I assume that Access was randomly (about 15% of the time) interpreting my
default True and False values as strings. Eval() fixed that.
--
Darryl Kerkeslager


There are only strings.


这篇关于复选框的.Value的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆