2012年6月12日火曜日

VB 作成したもの


テキストBOXに入力があった場合と無かった場合で処理を分ける
******************************************
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim txt1 As String 'txt1という変数をString型で宣言
txt1 = TextBox1.Text 'txt1にTextBox1を代入
If txt1 = ("") Then 'もしtxt1が空白なら
MsgBox("何か書いてくれ") 'メッセージBoxに「何か書いてくれ」
Else 'そうでなければ
MsgBox("「" & txt1 & "」と入力しましたね?") 'MsgBox1にtxt1を表示
End If

End Sub
End Class
*********************************************
完成品



テキストBOXに任意の数字を入れるてボタンを押すとそこまでの数字を足す。
入力無しならメッセージ表示
例えば3なら1+2+3=6
*********************************************
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim num1 As String
Dim total1 As String
Dim i As Integer

num1 = TextBox1.Text

If num1 = ("") Then
MsgBox("数字を入力して")
Else

total1 = 0

For i = 1 To num1
total1 = total1 + i
Next

MsgBox("合計は " & total1 & "")
End If

End Sub
End Class
*****************************************
完成品










0 件のコメント:

コメントを投稿