Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET General > Help me Return a String from a Function


Reply
 
Thread Tools Display Modes
  #1  
Old 06-27-2012, 06:42 AM
neo_matrix neo_matrix is offline
Freshman
 
Join Date: Mar 2009
Posts: 31
Default Help me Return a String from a Function


Hi all!

I am working on this problem 4 hours now an i cant figure the right way out!

I have a class in this class i call a function which should return some string

the class connects to an ftp server and list the directory and returns the filenames of the dir.

Code:
Public Function GetFileList(ByVal host As String, ByVal username As String, ByVal password As String, ByVal currentdirectory As String) As List(Of String)
        Dim oFTP As FtpWebRequest = CType(FtpWebRequest.Create(host & currentdirectory), FtpWebRequest)
        oFTP.Credentials = New NetworkCredential(username, password)
        oFTP.KeepAlive = True
        oFTP.Method = WebRequestMethods.Ftp.ListDirectory
        Dim response As FtpWebResponse = CType(oFTP.GetResponse, FtpWebResponse)
        Dim sr As StreamReader = New StreamReader(response.GetResponseStream)
        Dim str As String = sr.ReadLine
        Dim oList As New List(Of String)
        While str IsNot Nothing
            If str.StartsWith(Data) Then
                oList.Add(str)
            End If
            str = sr.ReadLine
        End While
 

        sr.Close()
        response.Close()
        oFTP = Nothing
        Return oList
    End Function
so this should return all filenames of that directory

like:

Data1.xml

Data2.xml

Data3.xml

Now i have a form with a listview where i want to call this function and get the files of the "olist"

Code:
Return oList
HOW CAN I DO THAT?!?! i mean how would my sub look like on my form where i want to call that function?
Reply With Quote
  #2  
Old 06-27-2012, 07:48 AM
AtmaWeapon's Avatar
AtmaWeapon AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,416
Default

I'm confused. Are you asking how to call a function?
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #3  
Old 06-27-2012, 07:49 AM
PlausiblyDamp's Avatar
PlausiblyDamp PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Wigan, UK
Posts: 1,678
Default

You would need to create an instance of the class that contains this function and then call this function via that class instance, e.g. if that function was in a class called FTPUtils you would do something like
Code:
Dim ftp as new FtpUtils()
Dim files as List(Of String) = ftp.GetFileList(<need to insert the appropriate parameter values here)
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
Reply


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 Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->