Hi All,
I am asking too many questions too often and it looks like I am not doing my research but I really do.It's just that I code and learn during weekends and all questions arise in a short interval.
For a while I was looking for a way to Pass a Function or Sub as a Parameter, if this is what you were trying to find rickford?
Here is my problem. I have many functions (Background Worker tasks) that I like to do in a Try/Catch block for FINAL versions and without Try/Catch block for BETA versions.
VB Code:
Private Sub bwApp_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bwApp.DoWork Dim t As New cBwJob(cBwJob.JobType.NEW_TASK) t = CType(e.Argument, cBwJob) Select Case t.Job Case cBwJob.JobType.ADD_NEW_TRACKS sBwAppAddNewFilesToLibrary(t.TaskData) Case cBwJob.JobType.CAPITALIZE_FIRST_LETTER sBwAppCaptitalizeWord() Case cBwJob.JobType.FIND_NEW_TRACKS_FROM_HDD sBwAppFindNewTracksFromHDD() Case cBwJob.JobType.INITIALIZE_ITUNES sBwAppLoadItunes() Case cBwJob.JobType.LOAD_ALBUMS sBwAppFillTrackCount() Case cBwJob.JobType.RATINGS_BACKUP sBwAppRatingsBackup() Case cBwJob.JobType.RATINGS_RESTORE sBwAppRatingsRestore() Case cBwJob.JobType.RECOVER_TAGS sBwAppRecoverTags() Case cBwJob.JobType.REPLACE_WORD sBwAppReplaceTextInTags() Case cBwJob.JobType.VALIDATE_LIBRARY If mAppInfo.ApplicationState = AppInfo.SoftwareCycle.FINAL Then sBwAppValidateLibrary() Else Try sBwAppValidateLibrary() Catch ex As Exception mErrOccured = True Dim lErrLog As New System.IO.StreamWriter(mFilePathErrorLog) lErrLog.WriteLine(String.Format("{0}", ex.Message)) lErrLog.WriteLine(String.Format("{0}", ex.StackTrace)) lErrLog.Close() End Try End If End Select End Sub
If you look at the code above, I have done this for ONE BackgroundWorder tasks and I would like to extend this to all the other tasks. I could do it, but ideally I was hoping for something like this to do:
VB Code:
Private Sub sPerformTask(Function myFunction) If mAppInfo.ApplicationState = AppInfo.SoftwareCycle.FINAL Then Try Call myFunction() Catch ex As Exception mErrOccured = True Dim lErrLog As New System.IO.StreamWriter(mFilePathErrorLog) lErrLog.WriteLine(String.Format("{0}", ex.Message)) lErrLog.WriteLine(String.Format("{0}", ex.StackTrace)) lErrLog.Close() End Try Else Call myFunction() End If End Sub
So I can call this like
VB Code:
sPerformTask(sBwAppReplaceTextInTags())VB Code:
sPerformTask(sBwAppReplaceTextInTags())VB Code:
sPerformTask(sBwAppReplaceTextInTags())
Etc...
I hope I am making myself clear.
Any help would be much appreciated.
Thanks,
McoreD


It's just that I code and learn during weekends and all questions arise in a short interval.
Reply With Quote
Please don't duplicate post. I just finished answering this question in another thread and here it is again. That's a great way to confuse the issue and waste people's time when they post answers that have already been posted in another thread.
