VBA Variables within a Loop - BlueZone Emulation

1.1k Views Asked by At

When I run the below code I cannot pass "Qty" to BlueZone. It will successfully pass the for each variable "aisle" using SendKey within the loop. I tested the outputs on the active sheet and I get the values based on myRange.Offset(0,n).

I have an n x 4 array that I want to loop through. I need to pass a different set of variables for each iteration.

Is my structure wrong?

BlueZone is 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
2

There are 2 best solutions below

0
Justin F On

So, my company uses BlueZone as well. 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:

SendKey Qty
0
Kevin Casey On

I know this is an old thread, but I found it looking for BlueZone info myself.

We also use BlueZone, and our practice is to use WaitReady instead of 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.

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? Otherwise, Qty will always be the value of the first row no matter what row aisle is...

Best, Kevin