• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • Last Modified:

help a NOOB - dbl pts - combo boxes selection to picture boxes

0
Kit_Kat111
Asked:
Kit_Kat111
  • 12
  • 9
  • 4
2 Solutions
 
Kit_Kat111Author Commented:
Here is what I have now:

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

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

        For i As Integer = 1 To 8
            Select Case i
                Case 1
                    pcbCam1.Image = Image.FromFile(String.Format(folder, i))

                Case 2
                    pcbCam2.Image = Image.FromFile(String.Format(folder, i))

                Case 4
                    pcbCam4.Image = Image.FromFile(String.Format(folder, i))

                Case 6
                    pcbCam6.Image = Image.FromFile(String.Format(folder, i))

                Case 7
                    pcbCam7.Image = Image.FromFile(String.Format(folder, i))

                Case 8
                    pcbCam8.Image = Image.FromFile(String.Format(folder, i))

                Case Else

            End Select
        Next


My problem is that each image will have the same name, which is a time stamp BUT at the very beginning of each file name it will change, for example: Cam1-33333335649-01.jpg and for another folder it will be Cam2-33333335649-01.jpg, so I need to associate change the file name of each for what folder it is going to.....does I make sense?


0
 
Bob LearnedCommented:
Try this:

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

        Dim folder As String = "C:\Projects\QRF\" & 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, "Cam" & i)

           If Not ctl Is Nothing Then
             pcb.Image = Image.FromFile(String.Format(folder, i))
           End If
            End Select
        Next i

End Sub
0
 
Bob LearnedCommented:
Imports System.Reflection

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
    Else
      Return Nothing
    End If

  End Function  'FindControl

End Class

Bob
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Kit_Kat111Author Commented:
Hi Bob,

Thanks for your assistance!

what is the "ctr"l bc it isn't declared? and the "end function" has a null reference.
0
 
Bob LearnedCommented:
Sorry, I was coding in the comment block:

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

        Dim folder As String = "C:\Projects\QRF\" & 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, "Cam" & i)

           If Not pcb Is Nothing Then
             pcb.Image = Image.FromFile(String.Format(folder, i))
           End If

        Next i

End Sub

Bob
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
"Sorry, I was coding in the comment block"

Bad Bob!...bad!   Lol....   ;)

0
 
Kit_Kat111Author Commented:
Oh.....thank you! But I am confused why the "End Function" has a null reference
0
 
Bob LearnedCommented:
Because I was using the wrong control name:

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

Bob

P.S. Mikey, I believe that I have seen you do the same thing ;)
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Exactly Bob!  I have to get my ribbing in when I can...    =)
0
 
Kit_Kat111Author Commented:
I must be doing something wrong....thanks for helping.

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


        'Try
        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)
            'Dim pcb As PictureBox = ApplicationControls.FindControl(Me, "Cam" & i)
            Select Case i
                Case 1
                    pcbCam1.Image = Image.FromFile(String.Format(folder, i))

                Case 2
                    pcbCam2.Image = Image.FromFile(String.Format(folder, i))

                Case 4
                    pcbCam4.Image = Image.FromFile(String.Format(folder, i))

                Case 6
                    pcbCam6.Image = Image.FromFile(String.Format(folder, i))

                Case 7
                    pcbCam7.Image = Image.FromFile(String.Format(folder, i))

                Case 8
                    pcbCam8.Image = Image.FromFile(String.Format(folder, i))

                    'Case Else
                    If Not pcb Is Nothing Then
                        pcb.Image = Image.FromFile(String.Format(folder, i))
                    End If

            End Select

        Next
        'Catch ex As Exception
        'MessageBox.Show(ex.Message, "Error Querying Files", MessageBoxButtons.OK, MessageBoxIcon.Error)

        'End Try


    End Sub


at the top:

Imports System.Reflection

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
        Else
            Return Nothing
        End If

    End Function
End Class
0
 
Bob LearnedCommented:
You are doing something wrong, because you left the Select Case statements in there.  Replace all that code with the last iteration of the code that I gave you--leave nothing from before.

Bob
0
 
Kit_Kat111Author Commented:
Thanks for helping me.....okay still the same.....

Imports System.Reflection

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
        Else
            Return Nothing
        End If

    End Function  'FindControl   <<Function 'Find Control' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.

End Class


:( Sorry for the hassle.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Change it to:

    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
0
 
Bob LearnedCommented:
Yeah, thanks Mike.  You gotta love 2005.  I had that for 2003, and it doesn't do checks like that.

Bob
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
I keep getting the same warning for lots of my old code as well...
0
 
Bob LearnedCommented:
If you look through the .NET framework, you'll see that form where the last return is Nothing or empty string, or something to avoid any problems.  I have been trying now to stick to that form, but old habits sometimes creep in or are just left lying there.

Bob
0
 
Kit_Kat111Author Commented:
I am so fortunate to have two great minds helping me....

With that recent change I now have:
An error occurred creating the form. See Exception.InnerException for details.  The error is: Could not find any resources appropriate for the specified culture or the neutral culture.  Make sure "Rvideo.frmRvideo.resources" was correctly embedded or linked into assembly "Rvideo" at compile time, or that all the satellite assemblies required are loadable and fully signed.
0
 
Kit_Kat111Author Commented:
okay I fixed it....sorry about that guys....
Thanks for the help.

I am not done yet. but I will award points. Should I split points?
0
 
Bob LearnedCommented:
Yes, by all means share them as you see fit.

Bob
0
 
Kit_Kat111Author Commented:
well not quite equal but I will divide them.....
0
 
Kit_Kat111Author Commented:
for some reason I don't see the split points link
0
 
Bob LearnedCommented:
I can split them for you, if you tell me what you want.

Bob
0
 
Kit_Kat111Author Commented:
Thanks...I just noticed that the value was off, this topic only was worth 20....so I just did 400/100. Hope that is okay. You guys really have helpled me. thank you very much!

My next step is the error problem.....hard to find what I am looking for so I hope I get more help. ;)
0
 
Kit_Kat111Author Commented:
Do you have to use the:

        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

each time and not MsgBox like in reg VB?
0
 
Kit_Kat111Author Commented:
ignore previous post
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 12
  • 9
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now