itpro-blogger
Amazon.co.jp ウィジェット
木曜日, 11月 29, 2007
[VB2005]日付関数
▼質問
月末日付を求めるにはどうしたらいいの?
▼回答
下記の方法で指定した前月の月末日付が取得できるよ。
DateSerial(年, 月, 0)
他にも下記の方法で同じように取得できるよ。
DateAdd("d", -1, CDate("yyyy/mm/dd"))
月末日の求め方
Dim lastDay As Integer = System.DateTime.DaysInMonth(Now.Year, Now.Month)
#
posted by itpro-blogger @ 3:07 午後
0 comments
金曜日, 11月 23, 2007
[VB2005]複数テーブルのデータベース更新
▼質問
複数テーブルを更新する時にトランザクションの管理やエラーの時のロールバックや成功の時の
コミットはどうやるんだい?
▼回答
サンプルを示しておくから参考にしてくれ!
'接続内容設定
Dim strCon as String = "Data Source=サービス・ネーミング" & _
";User ID=ユーザ名" & _
";Password=パスワード"
'データベースコネクション確立
Dim con As OracleConnection = New OracleConnection(strConnection)
'データベースオープン
con.Open()
Dim txn As OracleTransaction = con.BeginTransaction(IsolationLevel.Serializable)
Try
'レコード削除
Call DeleteTable(con)
'削除関連情報更新
Call UpdateTable(con)
txn.Commit()
Catch ex As Exception
txn.Rollback()
Finally
'データベースクローズ
con.Close()
con.Dispose()
con = Nothing
End Try
Private Sub DeleteTable(ByVal con As OracleConnection)
Dim cmd As OracleCommand = Nothing
Dim strSql As String = "DELETE FROM テーブル名 " & _
"WHERE フィールド名 = 1"
Try
cmd = New OracleCommand(strSql, con)
cmd.ExecuteNonQuery()
Catch ex As Exception
Throw
Finally
If (Not IsNothing(cmd)) Then
cmd.Dispose()
cmd = Nothing
End If
End Try
End Sub
Private Sub UpdateTable(ByVal con As OracleConnection)
Dim cmd As OracleCommand = Nothing
Dim strSql As String = "UPDATE テーブル名 " & _
"SET フィールド名 = 0 " & _
"WHERE フィールド名 = 1"
Try
cmd = New OracleCommand(strSql, con)
cmd.ExecuteNonQuery()
Catch ex As Exception
Throw
Finally
If (Not IsNothing(cmd)) Then
cmd.Dispose()
cmd = Nothing
End If
End Try
End Sub
■参考サイト
Oracle Data Provider for .NETのクラス
http://otndnld.oracle.co.jp/document/products/oracle10g/101/doc_v12/win.101/B15519-01/OracleTransactionClass.htm
#
posted by itpro-blogger @ 6:56 午後
0 comments
木曜日, 11月 22, 2007
[VB2005]印刷関連
▼質問
Excelを使った印刷はしたことがあるんだけど、テキスト文字列を直接印刷したことはないんだ。
どうしたらいいんだい!?
▼回答
PrintDocumentコンポーネント(System.Drawing.Printing名前空間)を使えばできるよ。
サンプルを教えてやるから参考にしてくれ!
ボタンのクリックイベントに下記を記述する。
'印刷処理実行
Me.PrintDocument1.Print()
PrintDocument1コンポーネントのイベントを下記のように記述すればOK!
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim yPos As Single = 0
Dim count As Integer = 0
Dim line As String = Nothing
'フォント設定
Dim printFont As Font = New Font("MS 明朝", 10)
'ページ余白(内側部分)を取得
Dim topMargin As Single = e.MarginBounds.Top
Dim leftMargin As Single = e.MarginBounds.Left
'ページ行数取得.
Dim linesPerPage As Single = e.MarginBounds.Height / printFont.GetHeight(e.Graphics)
Dim stream As New IO.StringReader(テキスト文字列)
'文字列ストリーム印刷.
While (count < linesPerPage)
line = stream.ReadLine()
If (line Is Nothing) Then
Exit While
End If
yPos = topMargin + count * printFont.GetHeight(e.Graphics)
e.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, New StringFormat())
count += 1
End While
'追加ページの印刷があるかチェックする.
If Not (line Is Nothing) Then
e.HasMorePages = True
Else
e.HasMorePages = False
End If
stream.Close()
End Sub
■参考サイト
Windowsアプリケーションで印刷を行うには?
http://www.atmarkit.co.jp/fdotnet/dotnettips/393printdoc/printdoc.html
印刷のテストは、PDFに出力するようにすれば印刷のデバックがやり易くなるので、下記の
ソフトはお奨めだ。しかも、フリーソフトだからお得!?
XLsoft エクセルソフト : activePDF 無料 PDF 作成/変換ソフトウェア PrimoPDF 日本語版 - ホーム
http://www.xlsoft.com/jp/products/primopdf/index.html
#
posted by itpro-blogger @ 6:01 午後
0 comments
水曜日, 11月 21, 2007
[VB2005]フォルダやファイルの列挙方法
▼質問
コンボボックスに決められたフォルダのファイルを一覧で表示したいんだ。どうしたらいいの?
▼回答
次のようにすればできるよ。
For Each strPath As String In System.IO.Directory.GetFileSystemEntries("C:\temp", "*")
Dim strDir() As String = Split(strPath, "\")
ComboBox1.Items.Add(strDir.GetValue(strDir.Length - 1))
Next strPath
■参考サイト
Visual Basic 6.0 と Visual Basic .NET とのフォルダやファイルの列挙方法の違いについて
http://www.microsoft.com/japan/msdn/vbasic/migration/tips/File/
#
posted by itpro-blogger @ 8:03 午後
0 comments
土曜日, 11月 17, 2007
[VB2005]Namespace My(ApplicationEvents.vb)
▼質問
「Namespace My(ApplicationEvents.vb)」って何?
▼回答
・VB2005から新しく導入された機能らしい。
・「My」を使うと、いろいろなことがとても簡単にできるらしい。
・My.Applicationを使うと、開いているすべてのフォームにアクセスしたり、ハンドルしていない
すべての例外をキャッチしたりできるらしい。
↑これはいろいろできそうな機能である。使えそうである!
・My.Computerを使うと、ファイルやフォルダを簡単に制御したり、レジストリにアクセスしたり
できるらしい。
■参考サイト
VB Myの用法 - My, My.Application, My.Computer
http://homepage1.nifty.com/rucio/main/dotnet/shokyu/standard37.htm
#
posted by itpro-blogger @ 1:58 午後
0 comments
月曜日, 11月 12, 2007
[VBA]リストボックス(ListBox)
▼質問
複数の列を表示するリストボックス(ListBox)を作成するにはどうしたらいいの?
▼回答
ユーザフォーム(UserForm)にリストボックス(ListBox)を貼り付けて次のコードを
UserForm_Initialize()に記述する。
ListBox1.Clear
ListBox1.ColumnCount = 2
ListBox1.ColumnWidths = 20 & ";" & 10
Call ListBox1.AddItem(",", 0)
ListBox1.list(0, 0) = "列1"
ListBox1.list(0, 1) = "列2"
これでもいける?
Dim column(1, 1) As Variant
column(0, 0) = "列1": column(1, 0) = "列2"
ListBox1.column() = column
▼質問
見出しを作成するにはどうしたらいいの?
▼回答
次のコードを書いてみたがエラーが発生してしまう。なぜ?
ListBox1.ColumnCount = 2
ListBox1.RowSourceType = "Value List"
ListBox1.RowSource = "列1;列2"
ListBox1.TextColumn = 3
ListBox1.ColumnWidths = 20 & ";" & 10
ListBox1.ColumnHeads = True
エラーの内容は、RowSourceTypeで実行時エラー'13'の「型が一致しません。」が発生する。
RowSourceTypeはAccessしか使えないのかな?
今度は、RowSourceTypeをコメントにして実行してみると次行のRowSourceでエラーが発生する。
エラーの内容は、実行時エラー'380'の「RowSourceプロパティを設定できません。プロパティの
値が不正です。」と・・・。
ダメダメだー!!
諦めよう。。。(T_T)
#
posted by itpro-blogger @ 4:58 午後
0 comments
自己紹介
名前:
itpro-blogger
詳細プロフィールを表示
Links
Google News
Edit-Me
Edit-Me
archives
5月 2005
6月 2005
7月 2005
8月 2005
9月 2005
10月 2005
11月 2005
12月 2005
1月 2006
2月 2006
3月 2006
4月 2006
5月 2006
6月 2006
7月 2006
8月 2006
9月 2006
10月 2006
11月 2006
12月 2006
1月 2007
2月 2007
3月 2007
4月 2007
5月 2007
6月 2007
7月 2007
8月 2007
9月 2007
10月 2007
11月 2007
12月 2007
1月 2008
2月 2008
3月 2008
4月 2008
5月 2008
6月 2008
7月 2008
8月 2008
9月 2008
10月 2008
11月 2008
12月 2008
1月 2009
2月 2009
3月 2009
4月 2009
5月 2009
6月 2009
7月 2009
8月 2009
9月 2009
10月 2009
11月 2009
12月 2009
1月 2010
2月 2010
3月 2010
4月 2010
5月 2010
6月 2010
7月 2010
8月 2010
9月 2010
10月 2010
11月 2010
12月 2010
1月 2011
2月 2011
3月 2011
4月 2011
6月 2011
12月 2011
5月 2012
3月 2015
9月 2015
6月 2019
7月 2019
6月 2020
10月 2022