lar3ry's Profile User Rating: *****

Reputation: 313 Architect
Active Posts:
1,298 (1.11 per day)
12-September 12
Profile Views:
Last Active:
User is offline Nov 14 2015 10:47 PM

Previous Fields

OS Preference:
Who Cares
Favorite Browser:
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Who Cares
Your Car:
Dream Kudos:

Latest Visitors

Icon   lar3ry has not set their status

Posts I've Made

  1. In Topic: Detect the beggining of a line

    Posted 6 Oct 2015

    Personally, I would use the methods and properties of the TextBox control, along with some string functions.
    The lines in Multiline TextBoxes are an array of strings, so...

        Private Sub checkTextBox()
            Dim i As Integer
            For i = 0 To TextBox1.Lines.Count - 1
                If TextBox1.Lines(i).StartsWith("whatever") Then
                    'do stuff with TextBox1.Lines(i) here
                End If
        End Sub
  2. In Topic: Can't update a TextBox from a handler

    Posted 25 May 2015

    View Postmaceysoftware, on 25 May 2015 - 01:48 AM, said:

    Would you care to share your answer, for anyone else who find this thread, nothing in your code suggest that its done on a separate thread, I also didn't require an invoke when writing it.

    scratch that before I was just using debug.print not actual controls I see how it works now

    Actually, yes. I did not share my answer because I needed to remove a few things from it (password generation and sending) before posting, and I really had to get to bed.

    There is one thing in the code that is actually unnecessary in this particular application. Because I know already that the Invoke is required, I could have just used it. The SetText Sub is a little more general, and can be used from the main thread or a separate thread.

    The only thing I don't like about this solution is that the incoming data is not available until a CR or LF (or both) comes in, which means that I can't trigger on the prompt in the Linux device, as it obviously does not have a CR or LF. The workaround I used is to send the command line with StandardInput.WriteLine(), but add an extra LF. This gives me two prompts returnig, but I can live with that. If anyone knows a way to collect the incoming data as it arrives, I welcome the info.

    Anyway, here's the code...

    Imports System
    Imports System.Text
    Imports System.IO
    Imports System.Diagnostics
    Imports System.Threading
    Imports System.ComponentModel
    Imports Microsoft.VisualBasic
    Public Class Form1
        Private MyProcess As New Process
        Delegate Sub SetTextCallback(newString As String)
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            With MyProcess.StartInfo
                .FileName = "CMD.exe"
                .UseShellExecute = False
                .CreateNoWindow = True
                .RedirectStandardInput = True
                .RedirectStandardOutput = True
                .RedirectStandardError = True
            End With
            AddHandler MyProcess.OutputDataReceived, _
                          AddressOf OutputHandler
        End Sub
        Private Sub ButtonX1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX1.Click
            MyProcess.StandardInput.WriteLine("plink -ssh -v -pw " & password & " root@" & vbLf)
        End Sub
        Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
            MyProcess.StandardInput.WriteLine("exit" & vbLf)
        End Sub
        Private Sub OutputHandler(sendingProcess As Object, _
            out_Line As DataReceivedEventArgs)
            ' Collect the command output.
            If Not String.IsNullOrEmpty(out_Line.Data) Then
            End If
        End Sub
        Private Sub SetText(ByVal newString As String)
            ' Calling from another thread? -> Use delegate
            If Me.TextBox2.InvokeRequired Then
                Dim d As New SetTextCallback(AddressOf SetText)
                ' Execute delegate in the UI thread, pass args as an array
                Me.Invoke(d, New Object() {newString})
    	Else ' Same thread, assign string to the textbox
                Me.TextBox2.Text &= newString & vbCrLf
            End If
        End Sub
    End Class
  3. In Topic: Can't update a TextBox from a handler

    Posted 24 May 2015

    View Postlar3ry, on 24 May 2015 - 09:39 PM, said:

    I know (or at least I think I know) that I have to use Invoke() to call a delegate to get data back to the main thread, either in a TextBox or a String. I just can't figure out how to do that.

    Got it! Finally found an example that allowed me to figure out what each part of it was doing.
  4. In Topic: Can't update a TextBox from a handler

    Posted 24 May 2015

    View Postmaceysoftware, on 24 May 2015 - 04:42 PM, said:

    Hey there,

    The issue isn't that the method is happening on a different thread its because your variable and method are shared.

    I have just tested this code in a test project with removing the shared key words (which you don't need) and the text is successfully re-directed.

    Thanks! That got me actually having data returned.

    Unfortunately, it still leaves me with my original problem I had in a previous iteration of the code. I get a run-time error:

    Cross-thread operation not valid: Control 'TextBox2' accessed from a thread other than the thread it was created on

    I know (or at least I think I know) that I have to use Invoke() to call a delegate to get data back to the main thread, either in a TextBox or a String. I just can't figure out how to do that.
  5. In Topic: How can I check elapsed time?

    Posted 3 Dec 2013

    Another, easy way is to use the StopWatch class.

    Public sw As New Stopwatch

    then later,


My Information

Member Title:
Coding Geezer
Age Unknown
Birthday Unknown
Years Programming:
Programming Languages:
Various Assemblers, Fortran, Basic, Icon, Logo, PostScript, Rexx, COMAL, Pilot, C, C++, VB, VB.NET

Contact Information



Page 1 of 1
  1. Photo

    C.Andrews Icon

    20 Mar 2013 - 11:31
    LOL. You know why. /hat
  2. Photo

    raghav.naganathan Icon

    19 Nov 2012 - 02:50 sure are a great asset in the VB forums :)
Page 1 of 1