Top What's New Develop Technic Contact
ƒƒ“ƒ|ƒCƒ“ƒg

[VB]

ByVal‚ÆByRef

[“®ìŠÂ‹«]

Microsoft Vusual Basic 6.0(SP5)

[ŠT—v]

ƒTƒuƒ‹[ƒ`ƒ“‚âƒtƒ@ƒ“ƒNƒVƒ‡ƒ“‚Å—p‚¢‚éByVal‚ÆByRef‚ÌŽg‚¢•û‚Å‚·B

[ByVal]

’l“n‚µBŽQÆŒ³‚ɂ͉e‹¿‚ð—^‚¦‚Ü‚¹‚ñB

1F ŒÄoŒ³

ƒtƒH[ƒ€‚ɃRƒ}ƒ“ƒhƒ{ƒ^ƒ“‚ð”z’u‚µAƒNƒŠƒbƒNƒCƒxƒ“ƒgƒvƒƒV[ƒWƒƒ‚ɉº‹L‚̃R[ƒh‚ð‹Lq‚µ‚ĉº‚³‚¢B

Dim l_arg As Long
l_arg = 1
Call msb_ByVal(l_arg)
MsgBox l_arg
	  

2F ƒvƒƒV[ƒWƒƒì¬

ƒ‚ƒWƒ…[ƒ‹“à‚ɉº‹L‚̃R[ƒh‚ð‹Lq‚µ‚ĉº‚³‚¢B

Private Sub msb_ByVal(ByVal a_arg As Long)
	a_arg = a_arg * 100
End Sub  
	  

3F Šm”F

‚P‚ō쐬‚µ‚½ƒRƒ}ƒ“ƒhƒ{ƒ^ƒ“‚ðƒNƒŠƒbƒN‚µ‚Ă݂ĉº‚³‚¢Bu‚Pv‚Æ•\Ž¦‚³‚ꂽƒƒbƒZ[ƒWƒ{ƒbƒNƒX‚ªo‚é‚Í‚¸‚Å‚·BŒÄ‚яo‚³‚ꂽmsb_ByVal“à‚ł́Aa_arg‚Ì’l‚Í 1* 100 = 100 ‚É‚È‚è‚Ü‚·‚ªA‚±‚̏ꍇˆø”‚Ì’l‚́AŒÄoŒ³‚ɉe‹¿‚ð—^‚¦‚Ü‚¹‚ñ‚̂ŁAŒÄoŒ³‚Ìl_arg‚Ì’l‚͌Ăяo‚·‘O‚Æ•Ï‚í‚炸u1v‚Ì‚Ü‚Ü‚Å‚·B

@

[ByRef]

ŽQÆ“n‚µBŽQÆŒ³‚ɉe‹¿‚ð—^‚¦‚Ü‚·B

1F ŒÄoŒ³

ƒtƒH[ƒ€‚ɃRƒ}ƒ“ƒhƒ{ƒ^ƒ“‚ð’ljÁ‚µAƒNƒŠƒbƒNƒCƒxƒ“ƒgƒvƒƒV[ƒWƒƒ‚ɉº‹L‚̃R[ƒh‚ð‹Lq‚µ‚ĉº‚³‚¢B

Dim l_arg As Long
l_arg = 1
Call msb_ByRef(l_arg)
MsgBox l_arg
      

2F ƒvƒƒV[ƒWƒƒì¬

‰º‹L‚̃R[ƒh‚ð‹Lq‚µ‚ĉº‚³‚¢B

Private Sub msb_ByRef(ByRef a_arg As Long)
	a_arg = a_arg * 100
End Sub
      

3F Œ‹‰Ê

1‚ō쐬‚µ‚½ƒRƒ}ƒ“ƒhƒ{ƒ^ƒ“‚ðƒNƒŠƒbƒN‚µ‚Ä‚Ý‚Ä‚­‚¾‚³‚¢B¡“x‚́u100v‚Æ•\Ž¦‚³‚ꂽƒƒbƒZ[ƒWƒ{ƒbƒNƒX‚ªo‚é‚Í‚¸‚Å‚·BŒÄ‚яo‚³‚ꂽmsb_ByRefl“à‚ł́Aæ‚Ù‚Ç‚Æ“¯—l‚Éa_arg‚Ì’l‚Í1*100=100‚É‚È‚è‚Ü‚·‚ªA¡‰ñ‚̈ø”‚Ì’l‚͌ďoŒ³‚ɉe‹¿‚ð—^‚¦‚Ü‚·‚̂ŁAŒÄoŒ³‚Ìl_arg‚Ì’l‚͕ύXŒã‚Ì’lu100v‚É‚È‚è‚Ü‚·B

@

[‰ž—p]

ƒtƒ@ƒ“ƒNƒVƒ‡ƒ“‚ð—p‚¢‚½‰ž—p‚Å‚·B

1F ŒÄoŒ³

ƒtƒH[ƒ€‚ɃRƒ}ƒ“ƒhƒ{ƒ^ƒ“‚ð’ljÁ‚µAƒNƒŠƒbƒNƒCƒxƒ“ƒgƒvƒƒV[ƒWƒƒ‚ɉº‹L‚̃R[ƒh‚ð‹Lq‚µ‚ĉº‚³‚¢B

Dim l_arg1 As Long
Dim l_arg2 As Long
Dim l_rst As Long

l_arg1 = 1
l_arg2 = 1
l_rst = mfn_Lesson(l_arg1, l_arg2)

MsgBox "l_arg1=" & l_arg1 & vbNewLine & _
		"l_arg2=" & l_arg2 & vbNewLine & _
		"l_rst =" & l_rst	  
	  

2F ƒvƒƒV[ƒWƒƒì¬

‰º‹L‚̃R[ƒh‚ð‹Lq‚µ‚ĉº‚³‚¢B

Private Function mfn_Lesson(ByVal a_arg1 As Long, ByRef a_arg2 As Long) As Long
	a_arg1 = a_arg1 * 100
	a_arg2 = a_arg2 * 100
	mfn_Lesson = a_arg1 + a_arg2
End Function
	  

‚±‚Ì’iŠK‚ŁAƒƒbƒZ[ƒWƒ{ƒbƒNƒX‚Ì’l‚ª—\‘z‚µ‚Ä‚Ý‚Ä‚­‚¾‚³‚¢B—\‘z‚ªo—ˆ‚½‚çAŽÀs‚µ‚Ä‚Ý‚Ü‚µ‚傤B

3F Œ‹‰Ê

‚±‚̏ꍇAƒtƒ@ƒ“ƒNƒVƒ‡ƒ“ƒ‚ƒWƒ…[ƒ‹“à‚Å‚Ì’l‚Í‚»‚ꂼ‚ê a_arg1 = 100, a_arg2 = 100, mfn_Lesson = 100 + 100 = 200 ‚Æ‚È‚è‚Ü‚·B‚µ‚©‚µAa_arg1 ‚Í ByVal ‚Å’è‹`‚³‚ê‚Ä‚¢‚é‚̂Ńtƒ@ƒ“ƒNƒVƒ‡ƒ““à‚ŕύX‚³‚ꂽ’l‚ð•ÛŽ‚Å‚«‚Ü‚¹‚ñBŒ‹‰ÊA

l_arg1 = 1
l_arg2 = 100
l_rst = 200	  
	  

‚Æ‚È‚è‚Ü‚·B—\‘z‚Í“–‚½‚Á‚Ä‚¢‚Ü‚µ‚½‚©H

@