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")
else
 session.screen.putstring "XXXX",7,7
 session.screen.waithostquiet 1000, -1
end if
Avatar of RobSampson
RobSampson
Flag of Australia image

Hi, you can use this to check if a worksheet is protected:
http://www.vbaexpress.com/kb/getarticle.php?kb_id=239

or this to check is a single cell is protected:

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

Regards,

Rob.
Avatar of CMCONE

ASKER

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
atmsession
atmscreen3270

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.....

Regards,

Rob.
Avatar of CMCONE

ASKER

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?

Regards,

Rob.
Avatar of CMCONE

ASKER

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
  Err.Clear
  On Error GoTo 0
  MsgBox "Field is protected"
Else
  MsgBox "Field is not protected"
End If

Regards,

Rob.
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

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