Case statement to Loop

CoachBarker

Well-known member
Joined
Jul 26, 2007
Messages
133
Programming Experience
1-3
This is the last item I need for my internship project before I am done. I need to somehow change this case statement into a loop that points to the folder that is displayed in the picture. I thought the way I did it in case 0 was correct from what I have read in the forums, but it doesn't work. The original path was from the C drive, but now the folder is included with the app.

VB.NET:
Private Sub cbowmv9profile_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbowmv9profile.SelectedIndexChanged
        Select Case cbowmv9profile.SelectedIndex
            Case 0
                frmMain.AddVideo.AxVideoCap1.WMVCustomFileName = (Application.StartupPath & "\Profiles\Orange_Cast_Custom_Profile.prx")
            Case 1
                frmMain.AddVideo.AxVideoCap1.WMVCustomFileName = "C:\Program Files\VideoCap Pro ActiveX Control\Profiles\Window_Media_VideoAudio_9_for_1024x768.prx"
            Case 2
                frmMain.AddVideo.AxVideoCap1.WMVCustomFileName = "C:\Program Files\VideoCap Pro ActiveX Control\Profiles\Window_Media_VideoAudio_9_for_1280x1024.prx"
            Case 3
                frmMain.AddVideo.AxVideoCap1.WMVCustomFileName = "C:\Program Files\VideoCap Pro ActiveX Control\Profiles\Window_Media_VideoAudio_9_for_320x240.prx"
            Case 4
                frmMain.AddVideo.AxVideoCap1.WMVCustomFileName = "C:\Program Files\VideoCap Pro ActiveX Control\Profiles\Window_Media_VideoAudio_9_for_640x480.prx"
            Case 5
                frmMain.AddVideo.AxVideoCap1.WMVCustomFileName = "C:\Program Files\VideoCap Pro ActiveX Control\Profiles\Window_Media_VideoAudio_9_for_800x600.prx"
        End Select
    End Sub

Profiles.JPG
Any help would be greatly appreciated, both by me and my employer

Thanks
CoachBarker
 
in your project's bin\Release or bin\Debug folder, what is the file structure you see there?

DIR /s /b /on if you can at the CMD prompt, please
 
SHouldnt you be expecting them to contain some prx files?

Fo each file in Soln Expl, properties of the file, is Copy to Output set to Do Not COpy?

This will cause you a problem when tryign to use them in your production app, for sure
 
OK so instead of putting the prx files in the solution, (or just in the solution)I have to put them in the profiles folder in the bin folder, or just set them to copy to output.

How about creating a for loop from the case statement, is that possible?
 
A "loop" indicates that you want to repeat something several times, what is it you want to repeat?
 
Unfortunately I learned VS in 1.1 not 2.0 and we were taught totally different how to deal with folders and files. We added them to the solution and then had to figure out how to get to them when we compiled.

So all items that are required should go in their own folders in the bin and should be set to copy out. This would remove the need to have a modules folder where I am using a stream reader to read the files, right? (See post one)

Right now the selected index changed for a combo box is handled with a Select Case statement, because there is a known number of profiles. If I want to dynamically get the selected index, because it is possible more profiles could be added over time I would have to loop through the profiles to get the right one based on the selected index.

Right now I have changed the selected index changed to this to read the prx profiles becasue it is in the solution and it was the way I was taught.
VB.NET:
Private Sub cbowmv9profile_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbowmv9profile.SelectedIndexChanged
        Select Case cbowmv9profile.SelectedIndex
            Case 0
                frmMain.AddVideo.AxVideoCap1.WMVCustomFileName = (..\..\Profiles\Orange_Cast_Custom_Profile.prx")
            Case 1
             frmMain.AddVideo.AxVideoCap1.WMVCustomFileName = (..\..\Profiles\Window_Media_VideoAudio_9_for_1024x768.prx")
            Case 2
                frmMain.AddVideo.AxVideoCap1.WMVCustomFileName = (..\..\Profiles\Window_Media_VideoAudio_9_for_1280x1024.prx")
            Case 3
                frmMain.AddVideo.AxVideoCap1.WMVCustomFileName = (..\..\Profiles\Window_Media_VideoAudio_9_for_320x240.prx")
            Case 4
                frmMain.AddVideo.AxVideoCap1.WMVCustomFileName = (..\..\Profiles\Window_Media_VideoAudio_9_for_640x480.prx")
            Case 5
                frmMain.AddVideo.AxVideoCap1.WMVCustomFileName = (..\..\Profiles\Window_Media_VideoAudio_9_for_800x600.prx")
        End Select
    End Sub

I am working pretty much on my own at my internship and I have tried to implement the use of 2.0 when ever I could. Like nnow I know of at least three areas where I could use the IO.Directory.GetFiles method in this project and get rid of some extra code that I do not need.

Thanks for the advice and pointers
CoachBarker
 
Youre not going to manage this with a loop, at least, not in the way i think youre thinking
What you seem to be saying is, that you want the ability to change the profiles over time, ie. by dropping a new file into the directoy, and have your app recognise the new file and offer it as a profile

You definitely cannot do this with hard coding the names. I would recommend you do something like this:

VB.NET:
Dim files() as String
files = IO.Directory.GetFiles(IO.Path.Combine(Application.StartupPath, "Profiles"), "*.prx")

Dim dt as New DispValDataTable 'typed datatale having 2 columns, Disp and Val, both string

For Each path as String in files 
  dt.AddDispValRow(IO.File.GetFilenameWithoutExtension(path).Replace("_", " "), path)
Next path
myCombo.DataSource = dt
myCombo.DisplayMember = "Disp"
myCombo.ValueMember = "Val"

Your combo now shows a nicely formatted list of all the files in the directory, and when your user clicks the GO button, you just ask it for myCombo.SelectedValue to get the path of the profile they chose
 
I added that code to my form and got the following errors

VB.NET:
Dim dt As New DispValDataTable
Type "DispValDataTable" is not defined
Change 'DispValDataTable' to Data.DataTable

So I tried
Dim DispValDataTable as datatable
but that did not work

VB.NET:
For Each path As String In files
            dt.AddDispValRow(IO.File.GetFilenameWithoutExtension(path).Replace("_", " "), path)
        Next path
Tells me that "GetFilenameWithoutExtension" is not a member of System.IO.File

So what am I missing?


BUt if you highlight it and press F1 it tells you

Returns the file name of the specified path string without the extension.
Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)

and yes I have imported System.IO
 
I added that code to my form and got the following errors

VB.NET:
Dim dt As New DispValDataTable
Type "DispValDataTable" is not defined
Um, yepp.. did you read the comment? Its a typed data table having 2 string columns, disp and val..So you add a new dataset, open it in the designer, add a datatable, add 2 columns called disp and val and then youll have it.

Change 'DispValDataTable' to Data.DataTable
Well, no, because that would create a generic datatable

So I tried
Dim DispValDataTable as datatable
but that did not work
Well, no, because that would make a variable named DispValDataTable

Really, the only way here is to do a wee bit of legwork, and create that helper class (the typed datatable). WOuld take me about a minute.

VB.NET:
For Each path As String In files
            dt.AddDispValRow(IO.File.GetFilenameWithoutExtension(path).Replace("_", " "), path)
        Next path
Tells me that "GetFilenameWithoutExtension" is not a member of System.IO.File

So what am I missing?
Sorry. Its a member of Path, not File, but you really ought to have caught that one yourself when you looked at the docs :D (and then told me i'm dumb/i should write code in the IDE first, not from memory)

Oops. Cjard tells lies! Booo :)
 
Yep I saw the type data table, and when I was on my from work to class it hit me that it should have been a dataset. So when I get back to work tomorrow I will do it the correct way.

And the part with the File I looked right at the top of the document and never caught the path part. Comes from weeks of frustration and loss of sleep.

Thanks for your assistance and patience

CoachBarker
 
Reading a text file

Is there a better way to read a text file that is going to be included in an aoolication? The text files are set to copy and are in the bin foder under debug. I know they are reading them now, but how about when the app is deployed?

VB.NET:
Dim sis As System.IO.StreamReader
        sis = System.IO.File.OpenText("TextFiles\LocalPath.txt")
        txtLocalPath.Text = sis.ReadToEnd()

Thanks
CoachBarker
 
Deployment dir looks same as debug dir, without PDB or VSHOST files, so yeah.

Dim s as String= IO.File.ReadAllText(path)

one liner :p
 
Back
Top