how to call/run/activate a function 2 (1 Viewer)

smiler44

Registered User.
Local time
Today, 13:55
Joined
Jul 15, 2008
Messages
641
I may have shot my self in the foot with my previous post. I realise I managed to get into another function more by luck then programming know how. I dont understand how to make functions run and can only just understand a very simple funtion but still could not write one. I need leading by the hand at the moment so would appreciate some help.
If I were to use a command button what code would I attach to it to call the following function?

The funtion gets what ever charectors are on the screen at a given
co-ordinance

Thank you in advance
smiler44

Code:
[FONT=Calibri][SIZE=3]Function GetStringFromScreen(tnsscreen As Object, ypos As Integer, xpos As Integer, length As Integer) As String[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]' Get a string from screen object given xpos, ypos & length[/SIZE][/FONT]
[FONT=Calibri][SIZE=3]' If Session Disconnected, (TNS crash) raise error.[/SIZE][/FONT]
[FONT=Calibri][SIZE=3] [/SIZE][/FONT][FONT=Calibri][SIZE=3]On Error GoTo GetStringFromScreen_ERH[/SIZE][/FONT]
[FONT=Calibri][SIZE=3] [/SIZE][/FONT][FONT=Calibri][SIZE=3]If tnsscreen.Parent.Connected = True Then[/SIZE][/FONT]
[SIZE=3][FONT=Calibri]    GetStringFromScreen = tnsscreen.GetString(ypos, xpos, length)[/FONT][/SIZE]
[FONT=Calibri][SIZE=3]End If[/SIZE][/FONT]
[FONT=Calibri][SIZE=3] [/SIZE][/FONT][FONT=Calibri][SIZE=3]Exit Function[/SIZE][/FONT]
[FONT=Calibri][SIZE=3] [/SIZE][/FONT][FONT=Calibri][SIZE=3]GetStringFromScreen_ERH:[/SIZE][/FONT]
[SIZE=3][FONT=Calibri]    Err.Raise numSESSIONDISCONNECTED, Title, strSESSIONDISCONNECTED[/FONT][/SIZE]
[SIZE=3][FONT=Calibri]    Exit Function[/FONT][/SIZE]
[FONT=Calibri][SIZE=3] [/SIZE][/FONT][FONT=Calibri][SIZE=3]End Function[/SIZE][/FONT]
 

PNGBill

Win10 Office Pro 2016
Local time
Tomorrow, 00:55
Joined
Jul 15, 2008
Messages
2,271
I think your function is asking too much in the Name of it. You have too many variables declared in the function name that can easily be declared and set in the function itself.

To call a function from a Command Button only requires One Line of code. The Function Name.

You often have a few other lines though.
eg
Code:
[FONT=Verdana][SIZE=2]Private Sub CmdFrmSingleLoanStatement_Click()
On Error GoTo Err_CmdFrmSingleLoanStatement_Click
    
    Dim LoanID As Integer                           'Variable to hold Loan ID
        
    LoanID = Me.txtLDPK                             'put value from form control to variable
 
    LoanStatementSingle CStr(LoanID)                'call function to Generate Statement
    
Exit_CmdFrmSingleLoanStatement_Click:
    Exit Sub
    
Err_CmdFrmSingleLoanStatement_Click:
    MsgBox Err.Description
    Resume Exit_CmdFrmSingleLoanStatement_Click[/SIZE][/FONT]
[FONT=Verdana][SIZE=2]End Sub[/SIZE][/FONT]

Putting aside the lines related to Error Handling, Dim LoanID creates a variable to hold a unique reference. In this case, the Primary Key of a Loan Record.

LoanID = Me.txtLDPK assigns the value in text box control txtLDPK from the form (screen) where the command button was clicked.

LoanStatmentSingle CStr(LoanID)

calls the function LoanStatementSingle(LoanID As String)

If the function is only used for screen position then you can referr to the screen in the function code rather then require many variables to be set in the function name.

Some functions don't require any variables to be set and will just work with their own data collection or referr to the form in focus.
 

smiler44

Registered User.
Local time
Today, 13:55
Joined
Jul 15, 2008
Messages
641
Thanks pngBill.
I crack this. spent quite some time looking at the screen and a book with a very and I mean very basic funtion. In the end I added a text box and used this code attached to a command button

Text2.text = GetStringFromScreen(tnsscreen, 18, 14, 6)

The 18 is the row. 14 is the column and the 6 is the number of charectors I want to get the data for.

smiler44
 

Users who are viewing this thread

Top Bottom