Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 24th, 2006, 4:42 PM   #1
hush
Programmer
 
hush's Avatar
 
Join Date: Feb 2006
Location: 127.0.0.1
Posts: 35
Rep Power: 0 hush is on a distinguished road
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
hush is offline   Reply With Quote
Old Aug 24th, 2006, 4:52 PM   #2
Random Spirit
Unverified User
 
Join Date: Aug 2006
Posts: 88
Rep Power: 0 Random Spirit is on a distinguished road
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
Random Spirit is offline   Reply With Quote
Old Aug 24th, 2006, 5:39 PM   #3
hush
Programmer
 
hush's Avatar
 
Join Date: Feb 2006
Location: 127.0.0.1
Posts: 35
Rep Power: 0 hush is on a distinguished road
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#?
hush is offline   Reply With Quote
Old Aug 24th, 2006, 5:40 PM   #4
Random Spirit
Unverified User
 
Join Date: Aug 2006
Posts: 88
Rep Power: 0 Random Spirit is on a distinguished road
C# uses the keyword using, but the concept is the same.

e.g.

using System.IO;

class Foo{
//blah blah
}
Random Spirit is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Java CS Project Watts Existing Project Development 12 Jun 20th, 2006 3:39 PM
method doesn't recognize variable Krista Java 1 Dec 5th, 2005 5:40 PM
converting from javax.swing.JTextField to java.lang.String Krista Java 5 Dec 5th, 2005 4:08 PM
C++ namespace question kevin_cpp C++ 1 May 17th, 2005 3:28 PM
what is the import command? arod199113 Python 13 Feb 11th, 2005 1:18 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:30 AM.

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