3

i have start a new application and on each 30 secs it will save a picture to the temporarily dir but i need to save each photo with a different name like MDAL1Image1.jpg , MDAL1Image2.jpg , etc but i get this error

{"Conversion from string "C:\Mediamemebuilderpro\MDAL1Imag" to type 'Double' is not valid."}

This is the line i get the error

PB1.Save("C:\Mediamemebuilderpro\" + "MDAL1Image" + nametosave + ".jpg", System.Drawing.Imaging.ImageFormat.Bmp)
    timetosavetemp = 0

This is the code i get the error

Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
    timetosavetemp = timetosavetemp + 1
    If timetosavetemp >= 30 Then
        Dim nametosave = 1
        nametosave = nametosave + 1
        Dim PB1 As New Bitmap(PictureBox1.Image)

        PB1.Save("C:\Mediamemebuilderpro\" + "MDAL1Image" + nametosave + ".jpg", System.Drawing.Imaging.ImageFormat.Bmp)
        timetosavetemp = 0

    End If
End Sub
ines
  • 117
  • 10
  • Possible duplicate of [The difference between + and & for joining strings in VB.NET](https://stackoverflow.com/questions/734600/the-difference-between-and-for-joining-strings-in-vb-net) – Visual Vincent Jul 30 '17 at 12:31

1 Answers1

3

construct the file name using String.Format, changing the segments as needed.

Dim filename As String = "MDAL1Image" 'Change as needed
Dim path As String = String.Format("C:\Mediamemebuilderpro\{0}{1}.jpg", filename, nametosave)
PB1.Save(path, System.Drawing.Imaging.ImageFormat.Bmp)

When using ... "MDAL1Image" + nametosave + ... it is trying to perform a binary operation on nametosave which is a double, and "MDAL1Image", which is a string. It is unable to interpret the string as a valid double value.

Nkosi
  • 235,767
  • 35
  • 427
  • 472
  • tanks that solved the problem but what i need its to assign new name for each photo but its only save one photo. – ines Jul 30 '17 at 11:48
  • 1
    The value of `nametosave` is not remembered between ticks. You probably want to get a datetime stamp out and use that instead. This might help you: https://stackoverflow.com/questions/14294156/how-to-get-current-timestamp – Nick.Mc Jul 30 '17 at 11:55