Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Visual Basic .NET (http://www.programmingforums.org/forum19.html)
-   -   import namespace (http://www.programmingforums.org/showthread.php?t=11161)

hush Aug 24th, 2006 5:42 PM

import namespace
 
I created a streamreader:

:

Dim sOut As System.IO.StreamReader

But the code I got off a web-page was:

:

Dim sOut as streamreader

I know this is a basic question but I haven’t quite got my head around OOP.

I’m guessing that the second lot of code would have had the namespace system.IO imported thus visual studios knows where to look for streamreader.

My question is how would I use the import or what ever is required to get the second lot of code to work in a “public class form1" button.click procedure without having pre-pend the system.IO

:

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim myProcess As Process = New Process()
        Dim s As String
        myProcess.StartInfo.FileName = "cmd.exe"
        myProcess.StartInfo.UseShellExecute = False
        myProcess.StartInfo.CreateNoWindow = True
        myProcess.StartInfo.RedirectStandardInput = True
        myProcess.StartInfo.RedirectStandardOutput = True
        myProcess.StartInfo.RedirectStandardError = True
        myProcess.Start()
        Dim sIn As System.IO.StreamWriter = myProcess.StandardInput
        sIn.AutoFlush = True

        Dim sOut As System.IO.StreamReader = myProcess.StandardOutput
        Dim sErr As System.IO.StreamReader = myProcess.StandardError

        sIn.Write("ping.exe" & System.Environment.NewLine)
        sIn.Write("exit" & System.Environment.NewLine)
        s = sOut.ReadToEnd()
        If Not myProcess.HasExited Then
            myProcess.Kill()
        End If

        sIn.Close()
        sOut.Close()
        sErr.Close()
        myProcess.Close()
        MessageBox.Show(s)

    End Sub
End Class



I hope this makes sense. If it doesn’t then I will try to clarify to the best of my ability's within my limited programming vocabulary.

hush

Random Spirit Aug 24th, 2006 5:52 PM

You say at the top of the class or module

:

Imports System.IO
//you can imports any namespaces here with the Imports keyword

Class Foo //could be module Foo
//Random programming goes here
End Class


It will then be avaliable in any classes or modules that are in that file. I think thats about right. I have not done much VB.net :)

hush Aug 24th, 2006 6:39 PM

Thanks RS

i was trying all sorts as i like to figure this stuff out myself, i even tried that without the 's' on the end of imports.

i won't be forgeting that in a while.

is it the same for c#?

Random Spirit Aug 24th, 2006 6:40 PM

C# uses the keyword using, but the concept is the same.

e.g.

:


using System.IO;

class Foo{
//blah blah
}



All times are GMT -5. The time now is 12:21 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC