Search code examples
visual-studioibm-midrangesendkeysinputbox

Visual Studio - How to inject textbox text into an external application?


I'm trying to build an app to run on top of IBM i (AS400). So far I can get the application to open and login, but I'm looking for a dynamic solution as opposed to using static send keys

Imports System.Threading
Public Class Form1
Dim a As New Process
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    a.StartInfo.FileName = "C:\Program Files\reflection\default scripts\as400.rsf"
    a.Start()
    Thread.Sleep(3000)
    SendKeys.SendWait("UserID {TAB}")
    Thread.Sleep(1000)
    SendKeys.SendWait("Password {Enter}")
End Sub
End Class

I can run a macro that will display a popup box where the password is entered

Sub Macro1()
'
' Generated by the Reflection Macro Recorder on 03-18-2015  13:03:31.50
' Generated by Reflection for IBM for Windows 8.00
'
With Session
    Dim hostpassword As String

    .WaitForEvent rcEnterPos, "30", "0", 6, 53
    .WaitForDisplayString ".", "30", 6, 49
    .TransmitANSI "USERID"
    .TransmitTerminalKey rcIBMTabKey

    hostpassword = "PASSWORD"
    .TransmitANSI hostpassword
    .TransmitTerminalKey rcIBMEnterKey
End With
End Sub

I can't just copy and paste that into visual studio and get it to work that way. So my question is how do I get a textbox to inject whatever is typed, into a command line of an external application? I've done a fair amount of research but most everything I've found doesn't apply to what I'm attempting as every tutorial I've found is geared towards MS Office, Excel mostly. Can someone please point me in the right direction?


Solution

  • Thanks for the reply, however I'm not having any connection issues as the program opens and logs in just fine, I was just trying to figure out how to get text from my form into AS400 and I didn't realize the solution was this simple, I'm very surprised no one answered, or maybe they were waiting for me to figure it out on my own

    Imports System.Threading
    Public Class Form1
    
    Dim a As New Process
    
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        a.StartInfo.FileName = "C:\Program Files\reflection\default scripts\as400.rsf"
        a.Start()
        Thread.Sleep(1000)
        SendKeys.SendWait(TextBox1.Text)
        Thread.Sleep(1000)
        SendKeys.SendWait("{TAB}")
        Thread.Sleep(1000)
        SendKeys.SendWait(TextBox2.Text)
        Thread.Sleep(1000)
        SendKeys.SendWait("{ENTER}")
    End Sub
    End Class