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

1F ŒÄoŒ³

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

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

2F ƒvƒƒV[ƒWƒƒì¬

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

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

3F Šm”F

‚P‚Å쬂µ‚½ƒRƒ}ƒ“ƒhƒ{ƒ^ƒ“‚ðƒNƒŠƒbƒN‚µ‚Ă݂ĉº‚³‚¢Bu‚Pv‚Æ•\Ž¦‚³‚ꂽƒƒ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‚Æ•Ï‚í‚炸u1v‚Ì‚Ü‚Ü‚Å‚·B

@

[ByRef]

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

1F ŒÄoŒ³

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

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

2F ƒvƒƒV[ƒWƒƒì¬

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

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

3F Œ‹‰Ê

1‚Å쬂µ‚½ƒRƒ}ƒ“ƒhƒ{ƒ^ƒ“‚ðƒNƒŠƒbƒN‚µ‚Ä‚Ý‚Ä‚­‚¾‚³‚¢B¡“x‚Íu100v‚Æ•\Ž¦‚³‚ꂽƒƒ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Œã‚Ì’lu100v‚É‚È‚è‚Ü‚·B

@

[‰ž—p]

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

1F ŒÄoŒ³

ƒtƒH[ƒ€‚ɃRƒ}ƒ“ƒhƒ{ƒ^ƒ“‚ð’ljÁ‚µAƒNƒŠƒbƒNƒCƒxƒ“ƒgƒvƒƒV[ƒWƒƒ‚ɉº‹L‚̃R[ƒh‚ð‹Lq‚µ‚ĉº‚³‚¢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	  
	  

2F ƒvƒƒV[ƒWƒƒì¬

‰º‹L‚̃R[ƒh‚ð‹Lq‚µ‚ĉº‚³‚¢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

3F Œ‹‰Ê

‚±‚Ìê‡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

@