visual basic 2010 copy paste subroutine - visual-studio-2010

I am trying to write 2 simple subroutines in VB 2010 that could be used with toolstripbutton contorls for multiple textboxes in a form. I know simple copy paste could be done using the textbox1.Copy() and TextBox1.Paste() methodes. What i am trying to do is write a common subroutine which could be used on any textboxes in the form not just one particular textbox.
My codes are below, I know there are errors in it, just wondering how it could be achieved. Any help would be highly appreciated. Thanks.
Public Class Form1
Private Sub copytext()
Dim txt As Control
If TypeOf txt Is TextBox Then
Clipboard.Clear()
Clipboard.SetText(txt.SelectedText)
End If
End Sub
Private Sub pastetext()
Dim txt As Control
If TypeOf txt Is TextBox Then
txt.Text = Clipboard.GetText
End If
End Sub
Private Sub mnuCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuCopy.Click
Call copytext()
End Sub
Private Sub mnuPaste_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuPaste.Click
Call pastetext()
End Sub
End Class

Related

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?
See the Host Access Class Library Automation Objects.
Here is an example VB script I wrote years ago to reconnect sessions:
Option Explicit
Dim autECLConnList As Object
Dim i As Integer
Set autECLConnList = CreateObject("PCOMM.autECLConnList")
autECLConnList.Refresh
If autECLConnList.Count > 0 Then
For i = 1 to autECLConnList.Count
If autECLConnList(i).CommStarted Then
autECLConnList(i).StopCommunication()
End If
autECLConnList(i).StartCommunication()
Next
End If
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

how to put a number in a text box using a button in visual basic application forms

I am trying to make a calculator on visual basic application forms and I have most of the codes sorted. How do I make it so when I press the number button, it puts the number in the text box. It also needs to be able to work so if I pressed 1 then 2 then 3, it appears a 123.
Just set the SelectedText() property of the TextBox to the Text() property of your button.
For example:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
TextBox1.SelectedText = Button1.Text
TextBox1.Focus()
End Sub
If you make all the buttons fire the same handler, then it becomes:
Private Sub AllButtons_Click(sender As System.Object, e As System.EventArgs) _
Handles Button1.Click, Button2.Click, Button3.Click, Button4.Click, Button5.Click, _
Button6.Click, Button7.Click, Button8.Click, Button9.Click, Button0.Click
Dim btn As Button = DirectCast(sender, Button)
TextBox1.SelectedText = btn.Text
TextBox1.Focus()
End Sub

make label update on file directory change (visual basic)

When I use an OpenFileDialog, and select a file and click open etc, etc...
I want a label on the same form to automatically update with the directory path. At the moment I have this working, However the label updates on click, not automatically on the directory change.
CODE:
Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click
Label4.Text = OpenFileDialog2.FileName
End Sub
Cna I change the "Label4_Click" to something else for an auto update?
How are you displaying the OpenFileDialog? You need to update the Label from there!...
Something like:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
If OpenFileDialog2.ShowDialog = Windows.Forms.DialogResult.OK Then
Label4.Text = OpenFileDialog2.FileName
End If
End Sub

Where to add code?

I am just starting out with windows forms and I am making a button with a mouseover image change (I know I should probably wait with this untill later) and I found this webpage that describes it.
How to change button background image on mouseOver?
and my current code looks like this
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
But I am not sure about where to add the code that is in the link. It gives me error anywhere I put it.

Enabling CTRL+Z property in masked edit textbox using VB.Net

I am using a masked edit text box in my windows application that was developed by using vb.net.
In normal text boxes (CTRL+Z- to revert back to original value) is working fine. But In case of Masked Edit Textboxes its not working fine.
Can any one please help me about this.
This ctrl+Z should provide the functionality as same as normal textbox.
You can use a variable to store the current text by programming the Leave event and check during the KeyDown event for the combination of Control+Z:
Dim oldText As String = ""
Private Sub MaskedTextBox1_KeyDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) _
Handles MaskedTextBox1.KeyDown
If e.Control AndAlso e.KeyCode = Keys.Z Then MaskedTextBox1.Text = oldText
End Sub
Private Sub MaskedTextBox1_Leave(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles MaskedTextBox1.Leave
oldText = MaskedTextBox1.Text
End Sub

Resources