アットウィキロゴ

0埋め

String.Format(wText, "0000")
wText.PadLeft(6, CChar("0"))
New String("0"c, 5)  '00000

カンマ区切り

Dim wStr_Ary() As String
wStr_Ary = wText.Split(","c)

演算子

余り Mod

半角文字をチェックする

Dim SJis As System.Text.Encoding = System.Text.Encoding.GetEncoding("Shift_JIS")
Dim wStr As String = "ABCDE"
If (wStr.Length * 2 > SJis.GetByteCount(wStr)) Then
    '半角文字あり
ELSE
    '半角文字なし    
End If

半角を全角にする

Dim St1 As String
St1 = StrConv("アイウABC", VbStrConv.Wide)

アセンブリ名を取得する

Me.GetType.Assembly.GetName

文字列を置換する

Dim str As String = "001-____"
'VisualBasic
Replace(str, "_", " ")
'System.String クラス
str.Replace("_", " ")

文字列を数値に変換

Dim wInt As Integer
If (Integer.TryParse("-12.34", wInt)) Then
Else
End If

バイト数を取得する

System.Text.Encoding.GetEncoding("Shift_JIS").GetByteCount(stTarget)

GoTo文

GoTo STEP
'処理
STEP:

フォームのコントロール名を指定して処理する

CType(Me.Controls("lbl"), System.Windows.Forms.Label).Text = "ABC"

DateDiff関数

VisalBasic
'この例では月数の差は1となる。1日(月の初めの日)を何回またいでいるかを数えている。
DateDiff(DateInterval.Month, #12/25/2004#, #1/12/2005#)

指定の文字列が含まれるかどうか調べる

Dim wStr_text As String
If (wStr_text.Contains("希望") = True) Then
End If

半角スペース埋め

【PadLeft】第2引数を省略すると、半角スペースで埋まるようになります。
wText.PadLeft(6)

ルーチン引数の省略

Public Function Gfnc_Check(ByVal Gstr_CD As String, _
                           Optional ByVal Gbln As Boolean = False) As Integer
End Function

TypeOf

For Each w_ctrl As Control In Me.Controls
     If (TypeOf w_ctrl Is CheckBox) AndAlso _
        (TryCast(w_ctrl, CheckBox).Checked = True) Then
             Exit For
     End If
Next

接続サーバー名

Dim Pobj_Con As New SqlConnection()
'db接続処理・・・・
Me.Label1.Text = "接続サーバー:" & Pobj_Con.WorkstationId

'yyyyMMdd'を日付型に変換

Dim wDate As Date
If (Date.TryParseExact("20110210", "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture, _
    Globalization.DateTimeStyles.None, wDate) = True) Then
End If

DataTable テーブル定義をして値を直接代入する

Dim DTbl As DataTable = New DataTable
Dim DRow As DataRow
DTbl.Columns.Add("ID", GetType(Integer))
DTbl.Columns.Add("Name", GetType(String))
DRow = DTbl.NewRow
DRow("ID") = 1
DRow("Name") = "名前"
DTbl.Rows.Add(DRow)

処理時間を計測

'処理開始時刻を記憶
Dim start As DateTime = Now
'処理時間を計算(現在時刻-処理開始時刻)
Dim span As TimeSpan = Now - start
MessageBox.Show(String.Format("処理時間は{0}秒です。", span.TotalSeconds))

ラベルを再描画

'Label1を再描画する
ME.Label1.Update()
' System.Windows.Forms.Application.DoEvents() を使用しない

イベントハンドラの追加

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  AddHandler Button1.Click, New EventHandler(AddressOf button2_Click)
  AddHandler Button1.Click, AddressOf button3_Click
End Sub
 
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  MessageBox.Show("Button1")
End Sub
 
Private Sub button2_Click(ByVal sender As Object, ByVal e As EventArgs)
  MessageBox.Show("Button2")
End Sub
Private Sub button3_Click(ByVal sender As Object, ByVal e As EventArgs)
  MessageBox.Show("Button3")
End Sub

アプリケーションの現在の作業ディレクトリ

IO.Directory.GetCurrentDirectory()
最終更新:2011年05月18日 12:52