简体   繁体   English

循环中的 VBA 变量 - BlueZone 仿真

[英]VBA Variables within a Loop - BlueZone Emulation

When I run the below code I cannot pass "Qty" to BlueZone.当我运行以下代码时,我无法将“数量”传递给 BlueZone。 It will successfully pass the for each variable "aisle" using SendKey within the loop.它将在循环中使用 SendKey 成功传递每个变量“过道”。 I tested the outputs on the active sheet and I get the values based on myRange.Offset(0,n).我测试了活动工作表上的输出,并获得了基于 myRange.Offset(0,n) 的值。

I have an nx 4 array that I want to loop through.我有一个要循环的 nx 4 数组。 I need to pass a different set of variables for each iteration.我需要为每次迭代传递一组不同的变量。

Is my structure wrong?我的结构错了吗?

BlueZone is terminal emulation. BlueZone 是终端仿真。

https://www.rocketsoftware.com/products/rocket-bluezonepassport-terminal-emulator/rocket-bluezone-terminal-emulation https://www.rocketsoftware.com/products/rocket-bluezonepassport-terminal-emulator/rocket-bluezone-terminal-emulation

Sub Grooming1()



Dim bzhao As Object
Set bzhao = CreateObject("BZWhll.WhllObj")
bzhao.Connect ""


Dim aisle As Variant
Dim Qty As Variant
Dim LDAP As Variant
Dim Priority As Variant

Set myRange = ActiveSheet.Range("A2:A1000")
'Set myQty = ActiveSheet.Range("B2:B1000")
'Set myLDAP = ActiveSheet.Range("C2:C1000")
'Set myPriority = ActiveSheet.Range("D2:D1000")


For Each aisle In myRange

Set Qty = myRange.Offset(0, 1)
Set LDAP = myRange.Offset(0, 2)
Set Priority = myRange.Offset(0, 3)

'end loop at blank cell
    If aisle = "" Then
        Exit For
            End If

bzhao.SendKey "<PF3>"
bzhao.Wait 0.5
bzhao.SendKey Qty '<---ERROR
bzhao.Wait 0.5

'ActiveSheet.Range("F2") = Qty
'ActiveSheet.Range("F3") = LDAP
'ActiveSheet.Range("F4") = Priority
'ActiveSheet.Range("F5") = aisle

Next aisle


End Sub

So, my company uses BlueZone as well.所以,我的公司也使用 BlueZone。 We have created a function that reduces lines of code:我们创建了一个减少代码行数的函数:

Public Function SendKey(ByVal aKey As String)
BZHost.SendKey aKey
If BZHost.WaitReady(10, 1) <> 0 Then
    Err.Raise 2049, "", "BlueZone session failed to respond within 10 second timeout limit!"
End If

End Function So when you want to enter text into BlueZone: End Function 所以当你想在 BlueZone 中输入文本时:

SendKey Qty

I know this is an old thread, but I found it looking for BlueZone info myself.我知道这是一个旧线程,但我发现它自己在寻找 BlueZone 信息。

We also use BlueZone, and our practice is to use WaitReady instead of Wait.我们也使用BlueZone,我们的做法是使用WaitReady而不是Wait。 In fact, we double it up for some reason (but I'm new here).事实上,出于某种原因,我们将其翻倍(但我是新来的)。

The other thing I would suggest is to always use the Format function with numbers, especially if your mainframe right-justifies anything like ours.我建议的另一件事是始终对数字使用 Format 函数,特别是如果您的大型机正确地证明了像我们这样的任何东西。

So if you're typing into a field with a length of six digits, your code would be:因此,如果您正在输入长度为六位数的字段,您的代码将是:

bzhao.SendKey "<PF3>"
bzhao.WaitReady 10, 1
bzhao.WaitReady 10, 100
bzhao.SendKey Format(Qty, "000000") ' padded with zeros
bzhao.SendKey Format(Format(Qty, "@"), "@@@@@@") ' padded with spaces
bzhao.WaitReady 10, 1
bzhao.WaitReady 10, 100

Finally, shouldn't your Offset be on the aisle object, not myRange ?最后,您的 Offset 不应该在aisle对象上,而不是myRange吗? Otherwise, Qty will always be the value of the first row no matter what row aisle is...否则, Qty将始终是第一行的值,无论是哪一排aisle ...

Best, Kevin最好的,凯文

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

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