DEADLINE! Please help!

  • Thread starter Thread starter KitKat
  • Start date Start date
K

KitKat

I need to get this to go to each folders: Cam 1, Cam 2, Cam 4, Cam 6, Cam 7,
and Cam 8. Well it does that but it also needs to change the file name to
the same folder where the file is being grabbed, BUT it doesn't. I have
tried and tried.....please help

example: C:\Projects\Darryl\Queue Review Files\2-24\Cam
7\Cam7-20060224170000-01.jpg

Cam7 but all I keep getting is Cam1, as the beginning of the jpg
name,...:( HELP!



Dim folder As String = "C:\Projects\Darryl\Queue Review Files\" &
DateTime.ParseExact(cmbDate.SelectedItem.ToString, "MMMM d, yyyy",
Nothing).ToString("M-d") & "\Cam {0}\" & cmbTime.Text

For i As Integer = 1 To 8

Dim pcb As PictureBox = ApplicationControls.FindControl(Me, "pcbCam" & i)

If Not pcb Is Nothing Then

pcb.Image = Image.FromFile(String.Format(folder, i))

'Else

' pcb.Image = Image.FromFile("C:\Projects\Darryl\Queue Review Files\2-24\Cam
7\Cam7-20060224170000-01.jpg")

End If

Next i
 
What does happen...
I do not see the Format specifier to change the file name...

Dim folder As String = "C:\Projects\Darryl\Queue Review Files\" &
DateTime.ParseExact(cmbDate.SelectedItem.ToString, "MMMM d, yyyy",
Nothing).ToString("M-d") & "\Cam {0}\Cam {0}-" & cmbTime.Text
 
Thanks Mike for the help!

That snippet changes the file name to: C:\Projects\Darryl\Queue Review
Files\2-24\Cam 1\Cam 1-Cam1-20060224165649-01.jpg

:(
 
So where does the "Cam" prefix in the file name come from.
The code you posted doesn't show it.

"cmbTime.Text" what is this cmbTime object, it sounds like that's where the
bug is.
 
KitKat said:
I need to get this to go to each folders: Cam 1, Cam 2, Cam 4, Cam 6, Cam
7, and Cam 8. Well it does that but it also needs to change the file name
to the same folder where the file is being grabbed, BUT it doesn't. I have
tried and tried.....please help

example: C:\Projects\Darryl\Queue Review Files\2-24\Cam
7\Cam7-20060224170000-01.jpg

Cam7 but all I keep getting is Cam1, as the beginning of the jpg
name,...:( HELP!

It would help if you gave a clearer and concrete example, like

From ===> To

C:\Projects\Darryl\Queue Review Files\2-24\Cam7\01.jpg ===>
C:\Projects\Darryl\Queue Review Files\2-24\Cam7\Cam7-20060224170000-01.jpg

and explained where the parts of Cam7-20060224170000-01 come from, like

Cam7 is the folder

20060224170000 is the date and ???

01 is the image name -- or whatever.
 
KitKat,

I adviced you to make your procedure more maintainable and showable to
replace that complete datetime stuff by just an array created by a string
split, you ignored that any reason?

Cor
 
It is part of the jpg file name that won't change not a folder.
"Cam1-33333335649.jpg" my code will look in the right folder but will only
look for files with Cam1 in the file name, not Cam2, Cam4, Cam6, Cam7 or
Cam8.. I will post more of my code thanks for helping. I appreciate it very
much.

Private Sub cmbDate_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles cmbDate.SelectedIndexChanged

Try

Dim dt As DateTime =
DateTime.ParseExact(cmbDate.Items(cmbDate.SelectedIndex), "MMMM d, yyyy",
Nothing)

'loads with the default folder files Cam 1

Dim path As String = "C:\Projects\Darryl\Queue Review Files\" & dt.Month &
"-" & dt.Day & "\Cam 1"

Dim dir As New IO.DirectoryInfo(path)

Dim files As IO.FileInfo() = dir.GetFiles("*.jpg")

cmbTime.BeginUpdate()

cmbTime.Items.Clear()

If files.Length > 0 Then

cmbTime.Items.AddRange(files)

End If

cmbTime.EndUpdate()

Catch ex As Exception

MessageBox.Show(ex.Message, "Error Querying Files", MessageBoxButtons.OK,
MessageBoxIcon.Error)

End Try

End Sub



Public Class ApplicationControls

Public Shared Function FindControl(ByVal owner As Form, ByVal name As
String) As Control

Dim propInfo As PropertyInfo = _

owner.GetType().GetProperty(name, BindingFlags.IgnoreCase Or _

BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public)

If Not propInfo Is Nothing Then

Dim value As Object = propInfo.GetValue(owner, Nothing)

If TypeOf value Is Control Then

Return value

End If

End If

Return Nothing

End Function

End Class





Private Sub cmbTime_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles cmbTime.SelectedIndexChanged

Dim folder As String = "C:\Projects\Darryl\Queue Review Files\" &
DateTime.ParseExact(cmbDate.SelectedItem.ToString, "MMMM d, yyyy",
Nothing).ToString("M-d") & "\Cam {0}\Cam {0}-" & cmbTime.Text

'Dim folder As String = "C:\Projects\Darryl\Queue Review Files\" &
DateTime.ParseExact(cmbDate.SelectedItem.ToString, "MMMM d, yyyy",
Nothing).ToString("M-d") & "\Cam {0}\" & cmbTime.Text

For i As Integer = 1 To 8

Dim pcb As PictureBox = ApplicationControls.FindControl(Me, "pcbCam" & i)

If Not pcb Is Nothing Then

pcb.Image = Image.FromFile(String.Format(folder, i)) <<<errors out and
points here

'Else

' pcb.Image = Image.FromFile("C:\Projects\Darryl\Queue Review Files\2-24\Cam
7\Cam7-20060224170000-01.jpg")

End If

Next i

End Sub
 
The reason anyone not really able to help you is that you are not giving us
the full information.

You indicate that an exception occurs at the line:

pcb.Image = Image.FromFile(String.Format(folder, i))

What is the exception?

What value is String.Format(folder, i) producing?
To find out, try:
Console.Writeline(String.Format(folder, i))
at the appropriate point.

You also have a ComboBox? (cmbTime) from which you are getting the last part
of the filename. What is the value you are getting from that control?

When you have the answers to these questions, come back and we might be able
to help you.
 
Sorry I am just learning this stuff. Can you show me what you mean? I have
posted my code below. Thanks for your input.

Private Sub cmbDate_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles cmbDate.SelectedIndexChanged

Try

Dim dt As DateTime =
DateTime.ParseExact(cmbDate.Items(cmbDate.SelectedIndex), "MMMM d, yyyy",
Nothing)

'loads with the default folder files Cam 1

Dim path As String = "C:\Projects\Darryl\Queue Review Files\" & dt.Month &
"-" & dt.Day & "\Cam 1"

Dim dir As New IO.DirectoryInfo(path)

Dim files As IO.FileInfo() = dir.GetFiles("*.jpg")

cmbTime.BeginUpdate()

cmbTime.Items.Clear()

If files.Length > 0 Then

cmbTime.Items.AddRange(files)

End If

cmbTime.EndUpdate()

Catch ex As Exception

MessageBox.Show(ex.Message, "Error Querying Files", MessageBoxButtons.OK,
MessageBoxIcon.Error)

End Try

End Sub



Public Class ApplicationControls

Public Shared Function FindControl(ByVal owner As Form, ByVal name As
String) As Control

Dim propInfo As PropertyInfo = _

owner.GetType().GetProperty(name, BindingFlags.IgnoreCase Or _

BindingFlags.Instance Or BindingFlags.NonPublic Or BindingFlags.Public)

If Not propInfo Is Nothing Then

Dim value As Object = propInfo.GetValue(owner, Nothing)

If TypeOf value Is Control Then

Return value

End If

End If

Return Nothing

End Function

End Class

Private Sub cmbTime_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles cmbTime.SelectedIndexChanged

Dim folder As String = "C:\Projects\Darryl\Queue Review Files\" &
DateTime.ParseExact(cmbDate.SelectedItem.ToString, "MMMM d, yyyy",
Nothing).ToString("M-d") & "\Cam {0}\Cam {0}-" & cmbTime.Text

'Dim folder As String = "C:\Projects\Darryl\Queue Review Files\" &
DateTime.ParseExact(cmbDate.SelectedItem.ToString, "MMMM d, yyyy",
Nothing).ToString("M-d") & "\Cam {0}\" & cmbTime.Text

For i As Integer = 1 To 8

Dim pcb As PictureBox = ApplicationControls.FindControl(Me, "pcbCam" & i)

If Not pcb Is Nothing Then

pcb.Image = Image.FromFile(String.Format(folder, i))

'Else

' pcb.Image = Image.FromFile("C:\Projects\Darryl\Queue Review Files\2-24\Cam
7\Cam7-20060224170000-01.jpg")

End If

Next i

End Sub
 
Thanks for helping Stephany.

The exception is: FileNotFoundException was unhandled
C:\Projects\Darryl\Queue Review Files\2-24\Cam 1\Cam
1-Cam1-20060224165649-01.jpg
cannnot be found, that is because the file is actually:
C:\Projects\Darryl\Queue Review Files\2-24\Cam 1\Cam1-20060224165649-01.jpg

String.Format is producing:
FOLDER:
C:\Projects\Darryl\Queue Review Files\2-24\Cam
{0}\Cam1-20060224170000-01.jpg

VALUE: TYPE:
pcb.Image Nothing System. Drawing.Image

From the combo box cmbTime getting the files associated with the date
selected in my combo box cmbDate, which defaults to each Cam 1 folder.
C:\Projects\Darryl\Queue Review Files\2-24\Cam 1

C:\Projects\Darryl\Queue Review Files\2-27\Cam 7\

C:\Projects\Darryl\Queue Review Files\2-28\Cam 7\

is that what you asked? thanks for helping I am really sorry for the hassle.
 
No....

I think that you are misinterpreting the questions.

You have 2 Comboxes.

One ComboBox (cmbDate) has some values like "2-24" etc.

The other ComboBox (cmbTime) has (I suspect) some filenames that you think
are like "20060224165649-01.jpg" etc.

From what you are reporting I suspect that the values in cmbTime actually
have values more like "Cam1-20060224165649-01.jpg" etc.

Until we know what your exact values are we are shooting in the dark.
 
I have tried:
'Dim folder As String = "C:\Projects\Darryl\Queue Review Files\" &
DateTime.ParseExact(cmbDate.SelectedItem.ToString, "MMMM d, yyyy",
Nothing).ToString("M-d") & "\Cam {0}\Cam {0}-" & cmbTime.Text

'Dim folder As String = "C:\Projects\Darryl\Queue Review Files\" &
DateTime.ParseExact(cmbDate.SelectedItem.ToString, "MMMM d, yyyy",
Nothing).ToString("M-d") & "\Cam {0}\" & cmbTime.Text

Dim folder As String = "C:\Projects\Darryl\Queue Review Files\" &
DateTime.ParseExact(cmbDate.SelectedItem.ToString, "MMMM d, yyyy",
Nothing).ToString("M-d") & "\Cam {0}\" & cmbTime.SelectedItem.ToString

all basically the same result, the jpg found is not the right name of the
folder.



Thanks for assistance.
 
YES you are right! Perhaps the combo box is keeping that file.

Okay.

1. User selects from combobox Date "February 24, 2006" which equals the 2-24
folder.
2. This populates another combo box with files from the default folder,
Cam1, so there will be tons of
Cam1-20060224165648-01.jpg
Cam1-20060224165649-01.jpg
Cam1-20060224165650-01.jpg
Cam1-20060224165651-01.jpg
and so on.

So...I need to take that off, like previously said, a split or something?
take that off and add what the appropiate folder is like Cam6.

I see that must be the problem....can you help me fix this?

Thanks so much Stephany, I appreciate your help as well as everyone else
here.

Thank you for putting up with me.
 
For each of your 8 cams, can you please post the actual name (fully
qualified) of a file that actually exists on you C drive.
 
So, you are saying that there is a file named Cam2-20060224165648-01.jpg in
the Cam2 folder and a file named Cam3-20060224165648-01.jpg in the Cam3
folder and a file named Cam4-20060224165648-01.jpg in the Cam4 folder etc.?

Or, is the file in the folder called 20060224165648-01.jpg and you are just
prepending the 'Cam1-' so you know what cam it belongs to?

Does the -01 directly before the extension signify anything? Like the cam
number perhaps?
 
The one I was using to test was:
Cam1-20060224170000-01.jpg
Cam2-20060224170000-01.jpg
Cam4-20060224170000-01.jpg
Cam6-20060224170000-01.jpg
Cam7-20060224170000-01.jpg
Cam8-20060224170000-01.jpg

sometimes there isn't a picture in that folder but there is of that file.

Thanks again for all your help!
 
That's not the fully qualified file name.

It should look like <drive>:\<folder>\<folder>...\<filename>.<extension>
 
So, you are saying that there is a file named Cam2-20060224165648-01.jpg
in the Cam2 folder
Yes there is a file in each folder of that format.

Or, is the file in the folder called 20060224165648-01.jpg and you are
just prepending the 'Cam1-' so you know what cam it belongs to?
No, I did try that but I am not adding the Cam2- to the file, it already
exists.

Does the -01 directly before the extension signify anything? Like the cam
number perhaps?
Good question, no it doesn't signify anything so there is file in each
folder with the -01.jpg.
It is broken up like this:
Cam2- (camera view)
20060224 (date-year, month, day)
165648 (time stamp in military time and with seconds 4:56:48)
-01.jpg (no method applied)

Thank you very much.
 
Got it working....
Dim folder As String = "C:\Projects\Darryl\Queue Review Files\" &
DateTime.ParseExact(cmbDate.SelectedItem.ToString, "MMMM d, yyyy",
Nothing).ToString("M-d") & "\Cam {0}\Cam{0}" &
cmbTime.Text.SubString(cmbTime.Text.IndexOf("-"))

Thanks for helping!
 
Now we are getting somewhere.

Because you are populating the filename combobox from the Cam1 folder, you
need to replace the "Cam1" in the filename and replace it with the
appropriate value otherwise you will always be looking for a Cam1 file no
matter what folder you are looking in.

Try this.

Dim folder As String = "C:\Projects\Darryl\Queue Review Files\" &
DateTime.ParseExact(cmbDate.SelectedItem.ToString, "MMMM d, yyyy",
Nothing).ToString("M-d") & "\Cam {0}\"

For i As Integer = 1 to 8
Dim pcb As PictureBox = ApplicationControls.FindControl(Me, "pcbCam" &
i.ToString)
If Not pcb Is Nothing Then
pcb.Image = Image.FromFile(String.Format(folder, i) &
cmdTime.Text.Replace("Cam1-", "Cam" & i.ToString * "-")
End If
Next

Please make sure that you don't just use this and forget about it. It is
important that you dissect and understand the techniques that you are being
presented with, specifically, the usage of the String.Format shared method
and the usage of the String.replace method. It is also important that you
understand why the final part of the filename string must be built inside
the loop instead of being assigned to the folder variable initially.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top