?
Solved

Visual basic routine...having trouble...

Posted on 2005-04-04
9
Medium Priority
?
305 Views
Last Modified: 2013-11-13
   Private Sub StartButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartButton.Click
        If NetstatCheckBox.Checked = True Then
            ' Set Timer to loop forever and viewerLabel.Text to display results
            Dim intTimer As Integer
            intTimer = 0
            Do While intTimer = -1
                Me.ViewerLabel.Text = Shell("C:\WINDOWS\System32\netstat.exe")
            Loop
        End If
    End Sub

What's wrong with my code? It should display the results of netstat in Me.ViewerLable.Text...
0
Comment
Question by:rae_rae
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 9

Expert Comment

by:riaancornelius
ID: 13704364
Shell("C:\WINDOWS\System32\netstat.exe") will simply execute the netstat app in a cmd shell, and probably returns an int (status code when it exits). I don't think you can get the shell to return the text to your app.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 13704428
Something like...

    Private Sub StartButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartButton.Click
        If NetstatCheckBox.Checked = True Then
            Dim p As New Process
            p.StartInfo.UseShellExecute = False
            p.StartInfo.RedirectStandardOutput = True
            p.StartInfo.FileName = "C:\WINDOWS\System32\netstat.exe"
            p.Start()
            Me.ViewerLabel.Text = p.StandardOutput.ReadToEnd()
            p.WaitForExit()
        End If
    End Sub
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 13705855
this code:

            ' Set Timer to loop forever and viewerLabel.Text to display results
            Dim intTimer As Integer
            intTimer = 0
            Do While intTimer = -1
                Me.ViewerLabel.Text = Shell("C:\WINDOWS\System32\netstat.exe")
            Loop


does NOT affect a timer object in any way.  IntTimer is a variable that you set to 0, but it NEVER CHANGES, so when you get to the next line (Do While intTimer = -1), intTimer has the value 0, so the loop immediately terminated, since intTimer is NOT equal to -1 (you just set it to 0!!!!)

You do not appear to have a Timer object in your program???

AW


0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 2

Expert Comment

by:kurtnelle
ID: 13709076
What are you really trying to do, get the output from a command line program or display the network statistics (netstat). If you are trying to get the network statistics then check out this cool ip helper api wrapper

http://www.codeproject.com/vb/net/netstat.asp 

yea its another source code site but hey the implementation is pretty simple ;)

Good Luck
0
 
LVL 3

Author Comment

by:rae_rae
ID: 13711399
Ok i have:
    Private Sub StartButton_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartButton.Click
        Dim UserChoice As Boolean
        If NetstatCheckBox.Checked And Not TracertCheckBox.Checked = True And Not NetTraceCheckBox.Checked = True Then
            Dim p As New Process
            p.StartInfo.UseShellExecute = False
            p.StartInfo.RedirectStandardOutput = True
            p.StartInfo.FileName = "C:\WINDOWS\System32\netstat.exe"
            p.Start()
            Me.ViewerTextBox.Text = p.StandardOutput.ReadToEnd()
            p.WaitForExit()
        ElseIf TracertCheckBox.Checked = True And NetTraceCheckBox.Checked = True Then
            Call SelectionError()
        ElseIf NetstatCheckBox.Checked = True And TracertCheckBox.Checked = True Then
            Call SelectionError()
        ElseIf NetstatCheckBox.Checked = True And NetTraceCheckBox.Checked = True Then
            Call SelectionError()
        ElseIf TracertCheckBox.Checked = True Then
            Me.ViewerTextBox.Text = ""
            MsgBox("Function not yet implimented", MsgBoxStyle.Information, "Tracert Function")
        ElseIf NetTraceCheckBox.Checked = True Then
            Me.ViewerTextBox.Text = ""
            MsgBox("Functions not yet implimented", MsgBoxStyle.Information, "Combo Functions")
        Else
            Me.ViewerTextBox.Text = "Please make any single selection"
        End If

    End Sub
    Private Sub SelectionError()
        Me.ViewerTextBox.Text = "Please make only one selection"
    End Sub

    Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
        Me.ViewerTextBox.Text = "Ready..."

    End Sub
But it's not formatting my data very well...
I'm sure it's cuz i'm just a beginner.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 13712049
>> But it's not formatting my data very well...

What exactly do you want formatted and how?

Are the results netstat.exe making it to ViewerTextBox with the code I gave you?
0
 
LVL 3

Author Comment

by:rae_rae
ID: 13713378
http://www.pirateculture.net/Downloads/NetStat.zip
That's where the source code is...
I guess what i want it to do is for the Viewer.TextBox.Text to be able to scroll...
This isn't entirely necessary, but it would be nice.
I'd prefer it if the output didn't scroll sideways. But the one thing i want for sure is for the window to refresh every so often...
I don't suppose that it matters much how often. I did try to put the code in a loop but it ran so many instances of %systemroot%\system32\netstat.exe that it wasn't possible to see what was happening in the netstat window...it was an imidiate loop though.
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 200 total points
ID: 13713597
>> I guess what i want it to do is for the Viewer.TextBox.Text to be able to scroll...
>> This isn't entirely necessary, but it would be nice.
>> I'd prefer it if the output didn't scroll sideways.

Set the MultiLine property of the TextBox to true and set the ScrollBars property to Vertical.

>> But the one thing i want for sure is for the window to refresh every so often...

Add a Timer control to your form and set its Interval property to "every so often".  An interval of 5000 will make it fire every 5 seconds:

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim p As New Process
        p.StartInfo.UseShellExecute = False
        p.StartInfo.RedirectStandardOutput = True
        p.StartInfo.FileName = "C:\WINDOWS\System32\netstat.exe"
        p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
        p.Start()
        Me.TextBox1.Text = p.StandardOutput.ReadToEnd()
        p.WaitForExit()
    End Sub
0
 
LVL 3

Author Comment

by:rae_rae
ID: 13714191
Thanks a ton !
We could sure use some more programmers on our sites if you're ever interested...
www.pirateculture.net and www.skynet-systems.com
Again, thanks!
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Six Sigma Control Plans
Progress

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question