ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] ByVal Target As Range ¥Îªk

[µo°Ý] ByVal Target As Range ¥Îªk

¦U¦ì®v¥S,®v©j,

§Ú¬OEXCEL VBAªºªì¾ÇªÌ,¦Ó§Ú¥ç³£¦³¶R®Ñ¾¤¦Û¾Ç,¦ý¦³TERM "VBA ByVal Target As Range" §Ú¤Wºô,Ú»®Ñ³£¤£¬O¦n©ú¥Õ³o¥y»yªkªº·N«ä,

½Ð¨D¦U¦ì«üÂI

ÁÂÁÂ

¦^´_ 1# mdr0465
¦h¦h¤Wºô¬d¸ß¡A§A«K·|§ó¥[©úÁA¥~­±ªº¥@¬É¤F¡C
¥H ByVal ©M ByRef ¶Ç»¼¤Þ¼Æ

ByRef and ByVal Parameters

TOP

byval object =byref object = objectªº¥»´L
byval ÅܼÆa = ÅܼÆaªº¤À¨­
byref ÅܼÆa = ÅܼÆaªº¥»´L

TOP

¥»©«³Ì«á¥Ñ c_c_lai ©ó 2016-1-28 16:07 ½s¿è

¦^´_ 1# mdr0465
Á|­Ó¹ê¨Ò»¡©ú¡A§A«K·|©úÁA¡G
  1. Sub joke()
  2.     Dim txt As String, num As Integer
  3.    
  4.     txt = "§A¦n¶Ü¡H": num = 200
  5.     Test1 txt, num    '  ¶Ç§}  (§Y jackyq ¤j¤j¤À¨Éªº "¥»´L")
  6.     MsgBox "txt = " & txt & " , num = " & num
  7.     '  µª®×¬O¡G txt = «Ü¦n¡AÁÂÁ¡I ¤j®a¥i¦n? , num = 150
  8.    
  9.     txt = "¦­À\¦Y¤F¶Ü¡H": num = 100
  10.     Test2 txt, num     '  ¶Ç­È  (§Y jackyq ¤j¤j¤À¨Éªº "¤À¨­")
  11.     MsgBox "txt = " & txt & " , num = " & num
  12.     '  µª®×¬O¡G txt = ¦­À\¦Y¤F¶Ü¡H , num = 100
  13. End Sub

  14. Sub Test1(ByRef txt As String, ByRef num As Integer)   '  ¶Ç§} (¦ì§} Address)
  15.     txt = "«Ü¦n¡AÁÂÁ¡I ¤j®a¥i¦n?"                      '   (Reference)
  16.     num = num - 50
  17. End Sub

  18. Sub Test2(ByVal txt As String, ByVal num As Integer)   '  ¶Ç­È  (¼Æ­È Value)
  19.     txt = "«D±`¦n¡I§B¤÷¨­Åé¦n»ò¡H"
  20.     num = num - 85
  21. End Sub
½Æ»s¥N½X

TOP

¦^´_ 4# c_c_lai
ÁÂÁ¤À¨É!!

TOP

¦^´_ 4# c_c_lai
jackyq ®v¥S,ÁÂÁ§A¦³¥Îªº¸ê®Æ
cc lai ÁÂÁ§A¥J²Ó´£¨Ñªºsample, ¦ý¦]¬°§Ú³£¤ñ¸ûÄø,§Ú·Q°Ý¦h¤Ö¤Ö,byref §Ú³£¤j¬ùª¾¹DÊ\¬J¥Îªk,Ê\«Y·|§ïÅܭ즳¼Æ­Èªº­È,

¦ý¬Obyval Ê\«Yªk«Y­ø·|§ïÅÜ­ÓÅÜ¥»¨­­ì¦³¬J¼Æ­È,ËÝ­n³]©wbyval ¦³¤°»ò§@¥Î©O??

ÁÂÁÂ

TOP

¦^´_ 6# mdr0465
  1. Sub Test2(ByVal txt As String, ByVal num As Integer)   '  ¶Ç­È  (¼Æ­È Value)
  2.     txt = "«D±`¦n¡I§B¤÷¨­Åé¦n»ò¡H"
  3.     num = num - 85
  4. End Sub
½Æ»s¥N½X
¤@¯ë¹ê°È¤W°£«D¶·¦P¨B§ó·sÅÜ¼Æ­È (ByRef)¡A§_«h³£¬O«Å§i¦¨¶Ç¤J­È (ByVal)¡G
¥H¤W½d¨Ò§Yµ¥©ó¥­±`²ßºD¨Ï¥Îªº¡G
  1. Sub Test2(txt As String, num As Integer)   '  ¶Ç­È  (¼Æ­È Value)
  2.     txt = "«D±`¦n¡I§B¤÷¨­Åé¦n»ò¡H"
  3.     num = num - 85
  4. End Sub
½Æ»s¥N½X
¦p¦¹»¡©ú¡A©ú¥Õ§_¡H

TOP

byval ¥Î¨Ó«OÅ@¥»´Lªº
¦pªG¥»´L¸ê®Æ«Ü­«­n
¤£¤¹³\³Q¤H«§ï ( read  only )
´N¥i¥H¬£¤À¨­¥X¥h©ßÀYÅSÁy
¸U¤@¤À¨­¦b¥~¦a³Q¥L¤HÅQ­â
¬Æ¦Ü³Q±þ¦º
¬Æ¦ÜÁÙ¦ºªº«ÜºG
¥»´L¨ÌµM·|§¹¦nµL¯Ê

TOP

¥»©«³Ì«á¥Ñ mdr0465 ©ó 2016-1-28 18:08 ½s¿è

cc lai®v¥S,
¯uªºÁÂÁ§A­@¤ßªº¸ÑÄÀ,§Ú¥ç³£¦³¤Wºô¦A¤F¸Ñbyval »yªk
¥H§Ú©Ò²z¸Ñ,byval ¬O¤£·|¼vÅTµ{¦¡¤¤¦³¬J¼Æ­È,
¦pªG§ÚµL²z¥Ñ¿ù»~ªº¸Ü,
ËÝtest2 ªº
txt = "«D±`¦n¡I§B¤÷¨­Åé¦n»ò¡H"
    num = num - 85
¬O¤£·|¥X²{ªº,¦ý¬O¥Îbyval¬O¨S¦³¼vÅT­ì¦³ªº¼Æ­ÈÅܧ󪺱¡ªp¤U¬°¤°»ò§Ú­ÌÁÙ­n¼g
txt = "«D±`¦n¡I§B¤÷¨­Åé¦n»ò¡H"
    num = num - 85

¦Ó¤£¼g¨ä¥Lªº¦r¥y©O??

¤£¦n·N«ä,§Ú¸£µ¬¯uªº«Ü²Â,©Ò¥H·Q½Ð±Ð¦U¦ì¸Ñµª¦h¤Ö¤Ö°ÝÃD.....
ÁÂÁÂ

TOP

¥»©«³Ì«á¥Ñ c_c_lai ©ó 2016-1-28 18:39 ½s¿è

¦^´_ 9# mdr0465
¦b¨ç¦¡¸Ì¤Þ¤J°Ñ¼Æ¦p¬°¶Ç­È¡A«hµL½×¸Ó°Ñ¼Æ¦b¸Ó
¨ç¦¡¸Ì¦p¦óÅܤƳ£¤£·|§ïÅܸӰѼƶǤJ®Éªº¤Þ¤Jªì©l­È¡A
¸Ó½d¨Ò¤º¤§Á|¨Ò¡A¥u¬O§i¶D§A¡Atxt ©Î num ¦b¨ç¦¡¸Ì¤£ºÞ
¥¦«ç»ò²§°Ê³£¤£·|§ïÅܶǤJ·í®Éªºªì©l­È (­ì­È)¡C
¦pªG¥Î¥Õ¸Ü»¡ªº¸Ü¡A´N¦p jackyq  ¤j¤j»¡ªº¡C

TOP

        ÀR«ä¦Û¦b : ¬°¦Û¤v§äÂǤfªº¤H¥Ã»·¤£·|¶i¨B¡C
ªð¦^¦Cªí ¤W¤@¥DÃD