Problem with specifying a directory when calling a func proc

How do I specify the directory in the call to a func proc?

Page 1 of 1

3 Replies - 2753 Views - Last Post: 18 December 2006 - 09:59 AM Rate Topic: -----

#1 ross_petersen  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 65
  • Joined: 06-August 05

Problem with specifying a directory when calling a func proc

Post icon  Posted 17 December 2006 - 11:00 PM

Hi folks[indent] :)

I have a func proc as follows:

Private Function GetContainingFile(ByVal dirTemp As Directory, ByVal dtDateAndTime As Date) As String

......

End Function



I have a command button on a form that when clicked the following code (in part) executes

Private Sub cmdFindFiles_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFindFiles.Click

		Dim dirTemp As Directory
		Dim fsiTemp As FileSystemInfo

		Dim dtMaxDateAndTime As Date
		Dim strFileStartDateAndTime As String
		Dim strFileEndDateAndTime As String
		Dim strCritDateAsStr As String
		Dim lngTimePeriodAsSecs As Long

'code to check values entered on form
.......

'didn't like this code (value of type string cannot be converted to System.IO>Directory)
		dirTemp = Me.txtSearchFolder.Text

'so I tried this
		dirTemp.SetCurrentDirectory(Me.txtSearchFolder.Text)

'then follows the main part where the func proc is called
		'get the name of the containing file as a string based upon the criteria specified on the form
		strFileStartDateAndTime = GetContainingFile(dirTemp, Me.dtpChooseDate.Value)

........

	End Sub



unfortunately, dirTemp is returning a value of "Nothing", so the call to the func proc doesn't work

So, has anybody got any ideas what the mistake is?

Kind regards and merry Christmas

Ross

Is This A Good Question/Topic? 0
  • +

Replies To: Problem with specifying a directory when calling a func proc

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Problem with specifying a directory when calling a func proc

Posted 18 December 2006 - 12:35 AM

Exactly what data are you entering into the textbox?

Are you entering an absolute path to your directory?
Was This Post Helpful? 0
  • +
  • -

#3 ross_petersen  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 65
  • Joined: 06-August 05

Re: Problem with specifying a directory when calling a func proc

Post icon  Posted 18 December 2006 - 02:42 AM

View Postjayman9, on 18 Dec, 2006 - 12:35 AM, said:

Exactly what data are you entering into the textbox?

Are you entering an absolute path to your directory?


This is the data I am entering:

Quote

C:\Documents and Settings\Ross\My Documents\Programming\Projects\Ultra106Five\SoundFiles\SampleSoundFiles


As you can see, it is the absolute path

Thanks

Ross :)
Was This Post Helpful? 0
  • +
  • -

#4 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Problem with specifying a directory when calling a func proc

Posted 18 December 2006 - 09:59 AM

I believe the problem lies in that you are using a Directory object in the form of a variable, in VS2005 that is not allowed. Do not create an object of type Directory just access it as Directory.SetCurrentDirectory.

Just pass the directory into your function as a String. Although you don't need to pass it in at all, since it is accessible using the Directory object.

Here is one example using the Function the way you designed it:
	Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

		Directory.SetCurrentDirectory("C:\Documents and Settings\Administrator\Desktop\School Assignments\sample files\VB.NET Programs\Test Solution 1")

	End Sub

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Me.TextBox1.Text = GetContainingFile(Directory.GetCurrentDirectory, Date.FromOADate(12 / 19 / 2006))
	End Sub

	Private Function GetContainingFile(ByVal dirTemp As String, ByVal dtDateAndTime As Date) As String
		Dim tempString As String = ""

		tempString = Directory.GetCurrentDirectory
		Return tempString

	End Function



Alternative function that does not pass Directory into it works exactly the same.
	Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

		Directory.SetCurrentDirectory("C:\Documents and Settings\Administrator\Desktop\School Assignments\sample files\VB.NET Programs\Test Solution 1")

	End Sub
	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Me.TextBox1.Text = GetContainingFile(Date.FromOADate(12 / 19 / 2006))
	End Sub

	Private Function GetContainingFile(ByVal dtDateAndTime As Date) As String
		Dim tempString As String = ""

		tempString = Directory.GetCurrentDirectory
		Return tempString

	End Function



Either way will output the following results to a textbox, C:\Documents and Settings\Administrator\Desktop\School Assignments\sample files\VB.NET Programs\Test Solution 1. Hope that helps.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1