重要なお知らせ

「教えて! goo」は2025年9月17日(水)をもちまして、サービスを終了いたします。詳細はこちら>

【GOLF me!】初月無料お試し

学生で、visual basic を勉強しているものです
Button1をクリックするとスクリーンショットを1秒ごとに撮り、
"c:\iMonitoring"に保存するというプログラムを書いています
(Button2をクリックすると止まる)

写真の名前を撮った時刻にしたいのですがエラーが出てうまくいきません
どうしていいか分からばいので教えてください

(コードです)
*********************************************************************************
Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = False
System.IO.Directory.CreateDirectory("C:\iMonitoring")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Enabled = True
End Sub


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Timer1.Enabled = False
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim x As String = Now().ToString()
Dim a As String = "C:\iMonitoring\"
Dim b As String = ".bmp"
Dim y As String = (a & x & b)
'Imports System.Drawing
'Imports System.Windows.Forms

'Bitmapの作成
Dim bmp As New Bitmap(Screen.PrimaryScreen.Bounds.Width, _
Screen.PrimaryScreen.Bounds.Height)
'Graphicsの作成
Dim g As Graphics = Graphics.FromImage(bmp)
'画面全体をコピーする
g.CopyFromScreen(New Point(0, 0), New Point(0, 0), bmp.Size)
'解放
g.Dispose()
'保存
bmp.Save(y)
End Sub
End Class

「Visual Basic でスクリーンシ」の質問画像

A 回答 (2件)

VBはよくわかりませんけど…



>Dim x As String = Now().ToString()
でxに「ファイル名、フォルダ名に使えない文字」とか入っていませんか?
# '/'や':'はファイル名やフォルダ名には使えませんが…。
    • good
    • 0
この回答へのお礼

ありがとうございます
その通りでした!!

Now().ToString("HHmmss")

このようにしたら解決しました^^

お礼日時:2013/03/17 15:24

こんにちは




Dim y As String = (a & x & b)→ Dim y As String = (a & "x" & b)のようにするとどうでしょうか?
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!