?
Solved

Need to minus one second to file name and display - HELP!

Posted on 2006-03-26
8
Medium Priority
?
228 Views
Last Modified: 2010-04-23
Okay all of this is working but now I need to get button called "previous" to work. I need to minus one second to the file and then display the pictures with that change. I really have no idea how to do this.

file is broken up like this:
Cam1-20060224165650-01.jpg

Cam1     -2006   02       24         1656  50                         -01.jpg
(camera)- year month  day and military time with seconds -01.jpg

so adding it will be Cam1-200602224165651-01.jpg


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("-"))

        For i As Integer = 1 To 8

            Dim pcb As PictureBox = ApplicationControls.FindControl(Me, "pcbCam" & i)
         
            If Not pcb Is Nothing Then

                If File.Exists(String.Format(folder, i)) Then
                    pcb.Image = Image.FromFile(String.Format(folder, i))
                Else
                    pcb.Image = Image.FromFile("C:\Projects\Darryl\Queue Review Files\noimage.jpg")
                End If
            End If

        Next i
0
Comment
Question by:Kit_Kat111
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 18

Expert Comment

by:armoghan
ID: 16298803
If you have the date object ..
just subtract 1 second frmo it
like

Dim oneSecondLessDate As Date = originalDate.Subtract(New TimeSpan(0, 0, 1))
0
 
LVL 18

Expert Comment

by:armoghan
ID: 16298839
Overall it is like

Dim originalDateAs Date = DateTime.ParseExact("20060224165650", "yyyyMMddHHmmss", Nothing)
Dim oneSecondLessDate As Date = originalDate.Subtract(New TimeSpan(0, 0, 1))
0
 

Author Comment

by:Kit_Kat111
ID: 16300954
Actually I just want to add a 1 to the end section of the file name, not an actual date or time.


Cam1-20060224165650-01.jpg
Cam1     -2006   02       24         1656  50                         -01.jpg

Sorry for the confusion.
                                                         +1
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 5

Expert Comment

by:xersoft
ID: 16302839
Is this what you are trying to do?

        Dim file1 As New IO.FileInfo("c:\TestFolder\Cam1-20060224165650.jpg")
        Dim File2 As New IO.FileInfo(IO.Path.Combine(IO.Path.GetDirectoryName(file1.FullName), IO.Path.GetFileNameWithoutExtension(file1.FullName) & "-01" & IO.Path.GetExtension(file1.FullName)))

        MsgBox(file1.FullName & vbCrLf & File2.FullName)
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16307026
I believe that this is what you are after:

Imports System.Text.RegularExpressions

Public Class FileOperations

  Public Shared Function IncrementFileName(ByVal fileName As String) As String

    ' Example:  Rename Cam1-20060224165650-01.jpg to Cam1-20060224165650-02.jpg
    Dim pattern As String = "(?<file>Cam\d-\d{14}-)(?<index>\d{2})(?<ext>[A-Za-z.]+)"

    Dim match As Match = Regex.Match(fileName, pattern)

    If match.Success Then
      Dim file As String = match.Groups("file").Value
      Dim index As Integer = Val(match.Groups("index").Value)
      Dim ext As String = match.Groups("ext").Value

      fileName = file & (index + 1).ToString("00") & ext

    End If

    Return fileName

  End Function

End Class

Sample:
    MsgBox(FileOperations.IncrementFileName("Cam1-20060224165650-01.jpg"))

Bob
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 16311112
Simpler form without regular expressions:

  Private Function IncrementFileName(ByVal fileName As String, ByVal start As Integer, ByVal length As Integer) As String

    Dim builder As New System.Text.StringBuilder(fileName)
    Dim index As Integer = Val(fileName.Substring(start, length)) + 1

    builder.Remove(start, length)
    builder.Insert(start, index.ToString("00"))

    Return builder.ToString()

  End Function

Sample:
   MsgBox(IncrementFileName("Cam1-20060224165650-01.jpg", 20, 2))

Bob
0
 

Author Comment

by:Kit_Kat111
ID: 16386430
Sorry I haven't forgotten about this question just have been dragged away on something unexpected. I will try your suggestion and post back tomorrow.

Thank you for your assistance with my problem, and also for your patience.
0
 

Author Comment

by:Kit_Kat111
ID: 16559032
Thank you very much!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Integration Management Part 2
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question