vba - 如何确定控件的 .Left 值?
问题描述
我正在 Microsoft Access 上的 VBA 中构建我的第一个用户界面。
我试图让 .Left 变量显示在下拉选择(库?)中。
唯一弹出的是LeftPadding,我很确定这不是我需要的。为什么我无法声明矩形的左侧位置?
我应该使用另一种类型的变量来声明矩形的位置吗?
如果我做得正确,我的后续问题是关于嵌套 If 语句。我正在尝试计算新可见矩形的位置 + 它的尺寸是否超过了已经可见矩形的左侧位置,如果是,则将其放置在其他位置。
Dim ctl As Control
For Each ctl In [Forms]![frmBuilder]
If Left(ctl.Name, 3) = "box" And Box1.Visible = True Then
If ctl.Visible = True Then
NextCaseNum = Int(Right(ctl.Name, (Len(ctl.Name)) - 3) + 1)
NextCasePosition = (ctl.lef + ctl.Width) + 1440 / 60
NextCaseName = "box" & NextCaseNum
Else
CurCaseLeft = ctl.Left
CurCaseWidth = ctl.Width
CurCaseHeight = ctl.Height
With ctl
.Top = UprightBottom - HInch
.Left = NextCasePosition
.Width = WInch
.Height = HInch
.Visible = True
End With
If CurCaseLeft + CurCaseWidth > Upright2.Left Then
With Beam1
.Top = (((5.5 + 6) * 60) + Box1.Top) / 1440
.Left = Upright1.Left
.Height = (5.5 * 60) / 1440
.Width = ((4 * 60) / 1440) + Upright2.Left - Upright1.Left
.Visible = True
End With
End If
我认为问题出在 CurCaseLeft 和 CurCaseWidth 上,因为由于当前框的 ctl.Left 没有出现,我不知道如何在函数中定义它们。
我是否必须将嵌套的 If 语句分隔到另一个函数中并从当前函数中调用该函数?
解决方案
尝试更明确:
Dim ctl As Control
Dim rct As Rectangle
For Each ctl In [Forms]![frmBuilder]
If Left(ctl.Name, 3) = "box" And Box1.Visible = True Then
If ctl.Visible = True Then
Set rct = ctl
NextCaseNum = Int(Right(rct.Name, (Len(rct.Name)) - 3) + 1)
NextCasePosition = (rct.Left + rct.Width) + 1440 / 60
推荐阅读
- r - 为特定列的每一行添加引号
- reporting-services - SSRS 报告中两个时间值之间的差异
- regex - 为什么正则表达式不适用于搜索 json?
- php - 读取 xlsx 文件期间的喷口和未定义的偏移错误
- jenkins - 詹金斯 - 将超时设置为阶段并继续下一阶段
- php - 使用 PHP 插入多个数据
- python - 数据流 - 写入 BigQuery - 元组到字典
- python-3.x - 在 Raspberry Pi 4 上安装 Kivy 失败
- javascript - 如何从 JsBarcode 实现生成图像?
- oracle-apex - Oracle apex 交互式网格:添加未绑定到表的计算列