0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

僕のVB(言語レベル)

Last updated at Posted at 2020-04-06

自分用の備忘録

データ型

データ型一覧

'文字列型
Dim char = "文字列型"

'文字型
Dim c = "A"C

'日付型
Dim date = #14/3/2020#

'10進型
Dim deci = 1234.56D

'整数型
Dim inte = 256I

'長整数
Dim lon = 5000000000000L

'単精度浮動小数点型
Dim sin = 3.14F

'倍精度浮動小数点型
Dim dou = 3.14R

データ型変換

'文字から整数
C2I = CInt(Char)

'数字等から文字
I2C = inte.toStrig(表示形式)

'キャスト
キャスト後の型の変数 = Ctype(変換する対象の変数,キャスト後の型)

配列

'配列の宣言
Dim 変数(インデックス最大値) As データ型
'多次元配列
Dim 変数(インデックスの最大値1,インデックスの最大値2,インデックスの最大値3) As データ型 

タプル

'タプルの宣言1
Dim member As (Integer,String)
'タプルの宣言2
Dim member As (number As Integer,name As String)

制御文

条件分岐

'''If文'''
If 条件1 Then 処理  'And,Or,AndAlso,OrElse
ElseIF 条件2 Then 処理
Else
End If

'''Case式'''
Select Case 変数
Case    
    処理1
Case ,値 '「もしくは」
    処理2
Case  To   '「値~値の範囲だったら」
    処理3
Case Is <   '「変数が値未満だったら」
CaseElse
    処理3

繰り返し

後判断Until「~まで」
Do 
    処理
Loop Until 条件
後判断While「~の間」
Do 
    処理
Loop While 条件
前判断Until「~まで」
Do Until 条件
    処理
Loop
前判断While「~の間」
Do While 条件
    処理
Loop

Exit Doで処理を抜ける。

For~Nextによる繰り返し
'例
For 変数 初期値 To 終値 Step 増分 '「Step 増分」は増分が1であれば省略可能
    処理
Next

こんな書き方もある

For 変数 As Integer = 始値 To 終値
    処理
Next
For Each
For Each 変数 As  In コレクション
    処理
Next 変数(省略可)

Exit Forで処理を中抜け

制御系で使いそうな関数

'文字を整数に変換できるか判断する
Integer.TryParse(変換前変数,変換後変数) '数値に変換できれば、変換後変数に変換した値が入る

'配列の最大インデックスを取得する。
Ubound(Sales)

プロシージャ

'返り値がない
Sub プロシージャ名(引数 As 型名,,,)
    処理
End Sub

Exit Sub '中抜け


'返り値がある1
Function プロシージャ名(引数 As 型名,,,) As 返り値の型
    処理
    Return 変数
End Function

'返り値がある2
Function プロシージャ名(引数 As 型名,,,) As 返り値の型
    処理
    プロシージャ名 = 
End Function

プロシージャの引数について

引数の頭にByRefと付けると参照渡しになる。
Optional 引数名 As 型 = 規定値とすることで省略可能な引数とすることができる。なんとなくPythonの書き方に似ている気がする。

Functionの返り値について

タプルを使用すると複数の返り値を指定できる。

クラス

宣言
Class Person
    private height As Double
    private weigth As Double
End Class
カプセル化(getter,setterの定義)
Class Person
    private mHeight As Double
    private mWeigth As Double
    
    public Property Height As Double
        Get
            Return mHeight
        End Get
        Set(value As Double)
            mWeigth = value
        End Set
    End Property
End Class

'自動実装プロパティバージョン
Public Class Person
    Property Height As Double
    ProPerty Weigth As Double
End Class
コンストラクター
public Class Person
    public Property Height As Double
    'コンストラクター
    Sub New(value As Integer)
        Me.Height = Value
    End Sub
共有メンバー
Public Class Person
    '共有メソッド
    Public Shared Function GetHeight() As Double
        GetHeight = 169.5
End Class
オーバーライドとその関連
Class Adult
    Inherits Person
    'オーバーライド
    public Overrides Function GetHeight() As Double
        return 180
    End Function
End Class
インターフェース
Public Interface Baby
    Sub cry()
    Function break(item As String) As String
End Interface


'インターフェースを利用する際
Class Adult
    implements Baby
    Sub cry(Value As String) implements Baby.cry
End Class

その他関数

処理

'このメソッドから退出
Exit Sub

画面制御

'カーソルをコントロールに移動
txtText.Focus()

'テキスト全体を選択
txtText.selectAll()
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?