CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Join Date
    Dec 2002
    Location
    Tenby, Wales
    Posts
    277

    Video Browser/Button dilemma

    I am developing a Video Browser project for a friend who lives 200 miles away. I have the form laid out with around 15 buttons. Now at the moment, there are 15 videos in a folder that the buttons are linked to. In time though, my friend may want to change the video that each button plays. The problem is that the videos will be named differently and that means the button text will be wrong.

    What I have come up with is to let him name the new videos first starting with a number which will dictate which button the video is for. Next, after the number will come the name of the video which will form the button's text. So using this example, the filename may be:

    1 Boat Launch Video.mpg
    This would mean that the video would be for the first button and the text on the button would be Boat aunch Video.

    Would this be the best way to go about it? My friend has no Programming experience and it would be a pain for me to have to update the program each time he adds/changes a video.

    Any suggestions??
    Thanks
    Visual Basic 2005 ver. 8.0.50727.867

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Video Browser/Button dilemma

    Hey! How is 2009 treating you thus far ¿

    That is a good idea, I see where you're going with it ( I think ). You'll incorporate the logic in there to extract the number from the video name - for the location ( which button ), and use the rest of the name for the button name - it can work

    Another idea, is to have a Text file which stores the names of the files using some sort of delimiter, for example :
    Launch Boat.mpg, Launch Plane.mpg, Launch Train.mpg

    Either should be relatively simple to do As long as your friend knows exactly what to do.
    Perhaps you can take it a step further in the next update ( depending on how this one works ), and implement some Exceptin handling routines - if your friend forgot a number, or misplaced a comma.

    I hope this was helpful, as you know, I'm not the sharpest dude around here

  3. #3
    Join Date
    Dec 2002
    Location
    Tenby, Wales
    Posts
    277

    Smile Re: Video Browser/Button dilemma

    Hi Hannes

    2009 is great - so far!!! How are you?

    Your idea is probably better and probably means the coding should be simpler - i.e. less accessing of the text file! Not sure how I will go about it but will have a go!!

    Thanks as usual Hannes!!
    Visual Basic 2005 ver. 8.0.50727.867

  4. #4
    Join Date
    Dec 2002
    Location
    Tenby, Wales
    Posts
    277

    Re: Video Browser/Button dilemma

    Hi Hannes I have the followig code for far which works to read the values from the .csv file and name the buttons:

    Code:
    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim FileNumber As Integer = FreeFile()
    
            ' Open file
            FileOpen(FileNumber, "d:\test.csv", OpenMode.Input)
            ' Loop until end of file
            Do Until EOF(FileNumber)
                ' Read a line from file
                Dim Text As String = LineInput(FileNumber)
                ' Split line at commas
                Dim Values() As String = Split(Text, ",")
                ' Values(0) now contains first column value,
                ' Values(1) contains second column, etc.
                Debug.Print(Values(0))
                Debug.Print(Values(1))
                Debug.Print(Values(2))
                Debug.Print(Values(3))
                Debug.Print(Values(4))
                cmd1.Text = Values(0)
                cmd2.Text = Values(1)
                cmd3.Text = Values(2)
                cmd4.Text = Values(3)
                cmd5.Text = Values(4)
            Loop
    
            ' Close file
            FileClose(FileNumber)
    
    
        End Sub
    End Class
    If I wanted to use the names of files in a folder instead of a .csv file to name the buttons, how would i go about it? Also, I wouldn't want the .avi etc on the end - just the actual filename.

    Thanks a lot
    Visual Basic 2005 ver. 8.0.50727.867

  5. #5
    Join Date
    Dec 2002
    Location
    Tenby, Wales
    Posts
    277

    Re: Video Browser/Button dilemma

    I have now figured out how to read the files in and siaply the filename as the button text:
    Code:
     Dim strSource As String = "D:\test\"
            Dim f() As String = Directory.GetFiles(strSource)
            For i As Integer = 0 To UBound(f)
                Debug.Print(f(i))
                cmd1.Text = (f(0))
            Next
    I just need to know how to get the .xxx file extension off? I just need the filename.

    Can anyone modify my code to show me how??

    Thanks a lot
    Visual Basic 2005 ver. 8.0.50727.867

  6. #6
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    Re: Video Browser/Button dilemma

    Code:
            Dim strSource As String = "D:\test\"
            Dim f() As String = Directory.GetFiles(strSource)
            Dim pos As Integer = 0
            For i As Integer = 0 To UBound(f)
                Debug.Print(f(i))
                pos = f(i).IndexOf(".")
                If pos > 0 Then
                   cmd1.Text = f(i).Substring(0, pos)
                End If
            Next
    This should work better.
    You were setting the text to f(0) every time.

    You could also identify each extension specifically with this line:
    Code:
       pos = f(i).IndexOf(".xxx")

  7. #7
    Join Date
    Dec 2002
    Location
    Tenby, Wales
    Posts
    277

    Re: Video Browser/Button dilemma

    Thanks for the reply. Tried your code - however, it doesn't do exactly what I want. The code I have is:
    Code:
        Dim strSource As String = "D:\test\"
            Dim f() As String = Directory.GetFiles(strSource)
            For i As Integer = 0 To UBound(f)
                Try
                    'Debug.Print(f(i))
                    cmd1.Text = (f(0).Substring(8)) ' Deletes Drive letter and directory name from filnename
                    cmd2.Text = (f(1).Substring(8))
                    cmd3.Text = (f(2).Substring(8))
                    cmd4.Text = (f(3).Substring(8))
                    cmd5.Text = (f(4).Substring(8))
                Catch
                End Try
            Next
    Which works fine in removing the leading characters e.g. driver letter, directory etc but I also need to remove the extension from the . onwards.

    Any ideas?
    Visual Basic 2005 ver. 8.0.50727.867

  8. #8
    Join Date
    Dec 2002
    Location
    Tenby, Wales
    Posts
    277

    Re: Video Browser/Button dilemma

    Well nevermind all - I cracked it with:
    Code:
     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim strSource As String = "D:\test\"
            Dim f() As String = Directory.GetFiles(strSource)
            For i As Integer = 0 To UBound(f)
                Try
                    'Debug.Print(f(i))
                    cmd1.Text = Path.GetFileNameWithoutExtension(f(0)) ' Deletes Drive letter and directory name from filnename
                    cmd2.Text = Path.GetFileNameWithoutExtension(f(1))
                    cmd3.Text = Path.GetFileNameWithoutExtension(f(2))
                    cmd4.Text = Path.GetFileNameWithoutExtension(f(3))
                    cmd5.Text = Path.GetFileNameWithoutExtension(f(4))
                Catch
                End Try
            Next
        End Sub
    Thanks all who contributed
    Visual Basic 2005 ver. 8.0.50727.867

  9. #9
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    Re: Video Browser/Button dilemma

    My idea is that it does exactly what you wanted to do.

    Okay, I see you've found a second solution already.
    Although you've put it into a loop.
    Last edited by TT(n); February 10th, 2009 at 03:07 PM.

  10. #10
    Join Date
    Dec 2002
    Location
    Tenby, Wales
    Posts
    277

    Re: Video Browser/Button dilemma

    TT(n)

    It's in a loop as there are 15 files in the folder and 15 buttons. The filenames make up the button labels so the only way to do it was to put it in a loop otherwise, your way, I only got the first filename.

    Seems to work fine with my code.

    Thanks for your suggestins anyway
    Visual Basic 2005 ver. 8.0.50727.867

  11. #11
    Join Date
    Jun 2004
    Location
    NH
    Posts
    678

    Re: Video Browser/Button dilemma

    Sorry, you've got it completely backwards.

    You are using the loop incorrectly.
    The buttons text property is set 15 times.

    Set each one once in the loop:
    Code:
    If i = 0 Then
       cmd1.Text = Path.GetFileNameWithoutExtension(f(i))
    ElseIf i = 1 Then
       cmd2.Text = Path.GetFileNameWithoutExtension(f(i))
    ElseIf i = 2 Then
       cmd3.Text = Path.GetFileNameWithoutExtension(f(i))
    ElseIf i= 3 Then
       cmd4.Text = Path.GetFileNameWithoutExtension(f(i))
       'And so on...
    End If
    You asked to wipe the extension of off a string, and I gave you the exact way to do it with the one button you had.
    I assumed you knew how to conditionally account for i and other buttons like above.
    The GetFileNameWithoutExtension, also works ofcourse, but at least use the loop properly, and my code works fine.

  12. #12
    Join Date
    Dec 2002
    Location
    Tenby, Wales
    Posts
    277

    Re: Video Browser/Button dilemma

    Oh yeah . . . .

    I see now. Sorry - I guess I am sooooo tired that I missed that!!

    So both of our ways work then!

    Thanks for your help
    Visual Basic 2005 ver. 8.0.50727.867

  13. #13
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Video Browser/Button dilemma

    It seems like I missed all the fun!
    Great work guys!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured