Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Visual Basic .NET (http://www.programmingforums.org/forum19.html)
-   -   Class problem (http://www.programmingforums.org/showthread.php?t=11669)

Ithaqua Oct 23rd, 2006 8:00 AM

Class problem
 
I have a problem in that I have created this class below it is designed to allow the user to set the full path to a file and store that data in the variable fullPath, but when I try to retreive that data in the fullPath variable and try to use it in the main program

Quote:

Public Class FileDetails

Private fullPath as string ' Holds the full path and filename of the file

ReadOnly Property FullPathAndFilename() As String
Get
Return _fullPath
End Get
End Property

End Class
The class is called in the main program like this.
Quote:

' Create a new instance of the class that holds files details
Dim MyFileDetails As FileDetails
MyFileDetails = New FileDetails

' Read in the data from the file
Dim objReader As StreamReader = New StreamReader(MyFileDetails.FullPathAndFilename)

Strangley if I try and put the data in the fullPath varible into a message box in the main program it shows the there is data there.

Can any one help?

XanFox Oct 29th, 2006 9:51 PM

Hi,

I am not quite sure what you are trying to do here exactly...(and I am a novice ..)

The FileDetails class has a private string to hold the file address in, but it only seems to have one method... a get (an accessor). If you want to specify the file path wouldn't you need to set it? Also in your main program wouldnt you then need to call on the get method to get that address string?

Iftikhar Oct 30th, 2006 2:58 AM

I am not sure what you are trying to achieve here. YOu have a property which is read only. So you can not allow a user to set full path through it. you can only get what ever is in the fullpath variable.
If you set it up earlier then there could be some other problems. You have not mentioned what kind of error it is generating. File not found or like that.

DaWei Oct 30th, 2006 6:46 AM

@Iftikhar: This has been mentioned before, but perhaps you don't get it.
Quote:

Originally Posted by Signatures Rule #3
Font size - Please don’t increase font size beyond the default text size.


BlackDal Dec 5th, 2006 4:30 PM

your property in class is read-only! why?
you can make it read-write...
:

Property FullPathAndFilename() As String
set(vaslue as string)
  _fullPath = value
end set
Get
Return _fullPath
End Get
End Property



All times are GMT -5. The time now is 8:26 PM.

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