Link to home
Start Free TrialLog in
Avatar of CMCONE
CMCONEFlag for United States of America

asked on

How do I determine if a field is protected or unprotected in a 3270 emulation session through VBA?

I use VBA to work with a TN3270 emulation session.  I would like to look at a field on a screen and determine if it is protected or not.  If it's not protected, I will write data to that field.  I have managed to make it work through the macro software provided with the emulation software; however, I can not seem to get to work with VBA.  Below is how I connect to the 3270 session.

Dim Session As New atmsession
Dim Screen As New atmscreen3270
Dim Connection As Object
Dim Model As ATM_3270_MODEL

Set Session = New atmsession
Set Screen = New atmscreen3270

Session.Screen = Screen
Forms![Systems Applications].AtmTerminal1.Session = Session

Set Connection = CreateObject("atm.con.tn3270")
Connection.UseTN3270E = True

Session.Screen.Model = ATM_3270_MODEL_5
Connection.RemoteHostAddress = "XXX.XXX.XXX.XXX"
Connection.DestinationPort = XXXX
Connection.ResourceName = "#XXXXCCC"
Connection.TimeOut = 15
Forms![Systems Applications].AtmTerminal1.Session.Connection = Connection
Forms![Systems Applications].AtmTerminal1.Session.Connect 0

'This is the code that worked in the macro editor with the emulation software:

attr1 = session.screen.feldattribute(7, 7)

if attr1 = 240 or attr1 = 249  then
 msgbox ("Field is protected")
 session.screen.putstring "XXXX",7,7
 session.screen.waithostquiet 1000, -1
end if
Avatar of RobSampson
Flag of Australia image

Hi, you can use this to check if a worksheet is protected:

or this to check is a single cell is protected:

If Range("C4")l.Locked = True Then
   MsgBox "Cell is locked."
   MsgBox "Cell is not locked."
End If


Avatar of CMCONE


I'm looking for the attribute of a field in a 3279 emulation session, not excel.
The code is have above is very similar to VBA except for the lines with Forms! in them.  Those are direct references so you'll have to find a way to get to them, if you need that.

What errors do you get when you try to run this in VBA? I suspect you cannot create the objects

You'll need to add a reference to the DLL that provides those object types, although I don't know what that is.  To add the reference, click Tools --> References, and try to find it in the list, otherwise click Add and browse to the correct DLL.....


Avatar of CMCONE


I am able to create the objects just fine and perform numerous other taskes.  The reference to the DLL is there.  I do not receive an error.  The variable attr1 is just empty.
Hmmm, what if, before this line:
attr1 = session.screen.feldattribute(7, 7)

you put this
MsgBox VarType(session.screen.feldattribute(7, 7))
or this
MsgBox TypeName(session.screen.feldattribute(7, 7))

and see if it can determine what the value or object is?


Avatar of CMCONE


That didn't seem to work.  The msgbox never appeared; however, I did figure out a work around.  I'm just puting the string and if I get an error, it must be protected.  Not sure why it took me this long to try that.  It working just fine.

Thanks for your help!
Oh yeah, cool.  What you could do then, is test for that error.

On Error Resume Next
<field> = "test string"
If Err.Number <> 0 Then
  On Error GoTo 0
  MsgBox "Field is protected"
  MsgBox "Field is not protected"
End If


Avatar of Computer101
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial