Click to See Complete Forum and Search --> : Video Browser/Button dilemma


brjames32
February 10th, 2009, 07:56 AM
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 ;)

HanneSThEGreaT
February 10th, 2009, 08:31 AM
Hey! How is 2009 treating you thus far ¿ :wave:

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 :lol: :D

brjames32
February 10th, 2009, 08:54 AM
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!!

brjames32
February 10th, 2009, 10:38 AM
Hi Hannes I have the followig code for far which works to read the values from the .csv file and name the buttons:

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 :)

brjames32
February 10th, 2009, 11:15 AM
I have now figured out how to read the files in and siaply the filename as the button text:
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

TT(n)
February 10th, 2009, 12:19 PM
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:
pos = f(i).IndexOf(".xxx")

brjames32
February 10th, 2009, 01:01 PM
Thanks for the reply. Tried your code - however, it doesn't do exactly what I want. The code I have is:
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?

brjames32
February 10th, 2009, 02:00 PM
Well nevermind all - I cracked it with:
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 ;)

TT(n)
February 10th, 2009, 02:04 PM
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.

brjames32
February 10th, 2009, 02:20 PM
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 ;)

TT(n)
February 10th, 2009, 03:23 PM
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:

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.:rolleyes:

brjames32
February 10th, 2009, 03:54 PM
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

HanneSThEGreaT
February 10th, 2009, 11:36 PM
It seems like I missed all the fun!
Great work guys! :thumb: :thumb: