Avatar of Jimbo1954
Jimbo1954
 asked on

convert sub to function to return a filepath to calling sub

Hello Again

Could somebody please help me convert this sub to a function to return checkfile as a variable to be used by the calling sub pls can you show me the calling code and how to return checkfile


regards

jimbo

 Public Sub foundupdate()
        TargetFolder = "Update\"         Dim Found As Boolean         Found = False         For Each di As System.IO.DriveInfo In My.Computer.FileSystem.Drives             Dim checkFile As String = System.IO.Path.Combine(di.RootDirectory.FullName, TargetZipped)             If Not di.RootDirectory.Name.ToUpper.StartsWith("C") Then                 If System.IO.File.Exists(checkFile) Then                     Found = True                 End If             End If         Next         If Found = True Then             UpdaterForm.ShowDialog()         End If     End Sub

Open in new window

Visual Basic.NET

Avatar of undefined
Last Comment
Jimbo1954

8/22/2022 - Mon
it_saige

Without testing or making any assumptions about the expectations of the overall logic, quite simply:
Public Function foundupdate() As String
        Dim checkFile As String
        TargetFolder = "Update\"
        Dim Found As Boolean
        Found = False

        For Each di As System.IO.DriveInfo In My.Computer.FileSystem.Drives
            checkFile = System.IO.Path.Combine(di.RootDirectory.FullName, TargetZipped)
            If Not di.RootDirectory.Name.ToUpper.StartsWith("C") Then
                If System.IO.File.Exists(checkFile) Then
                    Found = True
                End If
            End If

        Next
        If Found = True Then
            UpdaterForm.ShowDialog()
        End If

        Return checkFile
End Function

Open in new window

HTH,

-saige-
Jimbo1954

ASKER
Hi Thanks for the quick reply, basically what i am trying to do is search all drive for a folder called update, this needs to look at all drives except the c drive, I then want to use the returned path to then transfer all folders and files to a working directory on c.
so to test i have a form with a button , on pressing the button it calls the function to check the drives
FoundUpdate()
 Public Sub ImportNewTracks(ByVal Checkfile As String)

then using the function return the path, i then want to use that path to get all folders and copy them to a folder on the c drive.

I am still not able to see the return value

Jimbo
it_saige

Will there only be one folder on any of the drives other than C: which contain a folder called update?

-saige-
Your help has saved me hundreds of hours of internet surfing.
fblack61
Jimbo1954

ASKER
yes 
it_saige

And will it only be on one drive?

-saige-
Jimbo1954

ASKER
Yes It will only be on one drive but that drive could be any, except c, so the user could basically use a pen drive but the drive letter will depend on how many drives on their system,
thanks

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
it_saige

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Jimbo1954

ASKER
worked a treat ..... thanks


Jim