FindByString Method

Description

This method searches the Fields collection for the target string. The string must be completely contained within the field to be considered a match.
 

Applies To Objects

Fields
 

Syntax

Fields.FindByString( TargetString, start, length, dirIgnoreCase )
 

Parameters

Parameter
Description
TargetString
The target string to search for.
start
The offset location where the search will begin. For row 1 column 1 of the screen display buffer, the offset is 0.
length
The length from start to include in the search.
dir
An OHIO_DIRECTION value which represents the direction of the search.
IgnoreCase
Indicates whether the search is case sensitive. True means that case will be ignored. False means the search will be case sensitive.
 

Return Values

Returns the Field object containing the TargetString. If the TargetString is not found, a null value will be returned.
 

Sample VB Code

Public AllSessions As OhioSessions
Public WithEvents MySession As OhioSession
Public MyScreen As OhioScreen
Public AllFields As OhioFields

Private Sub Form_Load()

Set AllSessions = New OhioSessions
Set MySession = AllSessions.AddSession("C:\test.zcc", 1)
Set MyScreen = MySession.Screen

MySession.Connect

End Sub

' get the current fields
Private Sub cmdGetFields_Click()

Dim i As Integer
Dim MyField As OhioField

AllFields.Refresh
For i = 1 To AllFields.Count

Set MyField = AllFields.Item(i)
MsgBox MyField.String

Next i

End Sub

Private Sub cmdSendKeys_Click()

MyScreen.SendAid OHIO_KEY_ENTER

End Sub

Private Sub MySession_OnSessionChanged(ByVal oState As OHIO_STATE)

Set AllFields = MyScreen.Fields

End Sub

Private Sub MySession_OnScreenChanged(ByVal inUpdate As OHIO_UPDATE, ByVal inStart As Long, ByVal inEnd As Long)

Dim MyField As OhioField
Dim My2ndField As OhioField

' try finding the word "logon" on the screen
Set MyField = AllFields.FindByString("logon", 0, MyScreen.Rows * MyScreen.Columns, OHIO_DIRECTION_FORWARD, True)
If (Not MyField Is Nothing) Then

MsgBox "Found string 'logon' at Field starting at position: " & MyField.Start
Set My2ndField = AllFields.FindByPosition(MyField.Start)
' MyField and My2ndField are referencing the same field now
If (My2ndField Is MyField) Then

MsgBox "Same Field"

End If

End If

End Sub

Private Sub Form_Unload(Cancel As Integer)

MySession.Disconnect
AllSessions.CloseSession MySession.SessionName

End Sub

Sample C++ Code

#define OHIO_STATE_DISCONNECTED 0
#define OHIO_STATE_CONNECTED 1
#define OHIO_UPDATE_HOST 0
#define OHIO_UPDATE_CLIENT 1
#define OHIO_DIRECTION_FORWARD 0
#define OHIO_DIRECTION_BACKWARD 1
 

BEGIN_DISPATCH_MAP(CMyView, CView)

DISP_FUNCTION_ID(CMyView, "OnSessionChanged", 0, OnSessionChanged, VT_EMPTY, VTS_I4)DISP_FUNCTION_ID(CMyView, "OnScreenChanged",  1, OnScreenChanged,  VT_EMPTY, VTS_I4 VTS_I4 VTS_I4)

END_DISPATCH_MAP()

void CMyView::OnSessionChanged(long iState)
{

if ( iState == OHIO_STATE_CONNECTED )

m_AllFields = m_MyScreen.GetFields();

}
void CMyView::OnScreenChanged(long iUpdate, long iStart, long iEnd)

{

if ( iUpdate == OHIO_UPDATE_HOST )
{

m_AllFields.Refresh();

IOhioField MyField1 = m_AllFields.FindByString( "logon", 0, 80*24, OHIO_DIRECTION_FORWARD, TRUE );
if ( MyField1.m_lpDispatch )
{

TRACE( "Found string 'logon' at Field starting at position: %d\n", MyField1.GetStart() );

IOhioField MyField2 = m_AllFields.FindByPosition( MyField1.GetStart() );
// should refer to the same field object
ASSERT( MyField1.m_lpDispatch == MyField2.m_lpDispatch );

}
TRACE( "There are %d fields\n", m_AllFields.GetCount() );
MyField1 = m_AllFields.GetItem( 1 );
TRACE( "First field starts at %d\n", MyField1.GetStart() );

}

}

Sample C# Code

try

{

PASSHIOLib.IOhioFields AllFields = screen.Fields;

PASSHIOLib.IOhioField MyField;

PASSHIOLib.IOhioField MyField1;

AllFields.Refresh();

MyField = AllFields.FindByString( "logoff", 0, screen.Rows*screen.Columns, PASSHIOLib.OHIO_DIRECTION.OHIO_DIRECTION_FORWARD, 1 );

if ( MyField != null)

{

MessageBox.Show ( "Found string 'logoff' at Field starting at position: " + MyField.Start );

MyField1 = AllFields.FindByPosition( MyField.Start );

// should refer to the same field

MessageBox.Show ("Field starting at " + MyField.Start + " = " + MyField1.String);

}

}

catch (Exception ex)

{

MessageBox.Show ("Exception: " + ex);

}