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

Visual Basic ·s¤â±Ð¾Ç ¤§ µ{§Ç»P¨ç¼Æ

Visual Basic ·s¤â±Ð¾Ç ¤§ µ{§Ç»P¨ç¼Æ

¥»©«³Ì«á¥Ñ §b§b ©ó 2010-5-29 18:09 ½s¿è

µ{§Ç»P¨ç¼Æ

  • µ{§Ç
    ¤@¯ë¦Ó¨¥,¦pªG§Ú­Ì±`°µ¬Y¤@¥ó¨Æ,¨º³o¥ó¨Æ±¡ªºµ{¦¡½X´N¥i¥H¼g¦b¤@­Óµ{§Ç¤¤,¨C·í§Ú­Ì­n°µ³o¥ó¨Æ®É´N¥i¥H©I¥s³o­Óµ{§Ç
    µ{§Ç¤@¯ë¦Ó¨¥·|¦³¤U¦Cªº»yªk
    1. Sub µ{§Ç¦WºÙ()
    2. '§A­n°µªº¨Æ
    3. End
    ½Æ»s¥N½X
    ¥H¤Uµ{¦¡½X¥i¥H¨D¥X1+2+3....+10
    1. Public Class Form1
    2.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    3.         ¨DÁ`©M()
    4.     End Sub

    5.     Sub ¨DÁ`©M()
    6.         Dim Á`©M As Integer = 0
    7.         For i As Integer = 0 To 10
    8.             Á`©M = Á`©M + i
    9.         Next
    10.         MessageBox.Show(Á`©M.tostring)
    11.     End Sub
    12. End Class
    ½Æ»s¥N½X
    §Ú­Ì©I¥sµ{§Ç®É¥u­n¦bµ{¦¡½X¤WÁä¤Jµ{§Ç¦WºÙ´N¥i¥H¤F,³o¼Ëªº¸Ü,¦pªG§Ú­Ì·Q­n1¨ì10ªº¥[Á`,´N¥i¥H¤@ª½§Q¥Î¨DÁ`©M³o­Óµ{§Ç¤F,³o¼Ë¤£¬O«Ü¤è«K¶Ü
    ¦ý´N¦³¤H·Q¨ì¤F,§Ú³o¼Ë¥u¯à¨D1¥[¨ì10,¨º»ò§Ú·Q¤@¥[¨ì¥ô·N¼Æ©O©ÎªÌ¬O³sÄòªº¾ã¼ÆÁ`©M©O¨º­n«ç»ò¿ì,·íµM,³o¸Ì´N¸Ì¨Ñ¤F©w¸q³oºØµ{§Çªº»yªk
    Sub µ{§Ç¦Wµ{(byval ÅܼÆ1 as «¬ºA ,byval ÅܼÆ2 as «¬ºA,.........,byval ÅܼÆn as «¬ºA )
    End sub

    ¦]¦¹§Ú­Ì´N¥i¥H¦b©I¥sµ{§Ç®É§Q¥Î¶Ç¤JÅܼƪº¤èªkÅýµ{§Ç¤º³¡¥i¥H§Q¥Î³o­ÓÅܼƨӰµ¨Æ¥H¤U¬°½d¨Ò
    1. Public Class Form1
    2.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    3.         ¨DÁ`©M(-10, 100)
    4.     End Sub

    5.     Sub ¨DÁ`©M(ByVal °_©l­È As Integer, ByVal ²×¤î­È As Integer)
    6.         Dim Á`©M As Integer = 0
    7.         For i As Integer = °_©l­È To ²×¤î­È
    8.             Á`©M = Á`©M + i
    9.         Next
    10.         MessageBox.Show(Á`©M.ToString)
    11.     End Sub

    12. End Class
    ½Æ»s¥N½X
    ¨Æ¹ê¤W¶Ç¤JÅܼƤÀ¬°¤GºØ,¤@ºØ¬O¶Ç­È,¥t¤@ºØ¬O¶Ç§},§Ú­Ì¤W­±¥Îªº¬O¶Ç­È,°_©l­È¬O-10,²×¤î­È¬O100
    ³o¤GºØ¦³¤°»ò¤£¦P©O,¥H¤U¬°µ{¦¡½X
    1. Public Class Form1
    2.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    3.         Dim °_©l­È As Integer = -10
    4.         Dim ²×¤î­È As Integer = 100
    5.         Dim Á`©M As Long = 0

    6.         ¨DÁ`©M(°_©l­È, ²×¤î­È, Á`©M)

    7.         MessageBox.Show("°_©l­È =" & °_©l­È & vbCrLf & "²×¤î­È = " & ²×¤î­È & vbCrLf & "Á`©M=" & Á`©M.ToString)

    8.     End Sub

    9.     Sub ¨DÁ`©M(ByVal °_©l­È As Integer, ByVal ²×¤î­È As Integer, ByRef Á`©M As Long)

    10.         For i As Integer = °_©l­È To ²×¤î­È
    11.             Á`©M = Á`©M + i
    12.         Next

    13.         °_©l­È = 1000
    14.         ²×¤î­È = 1000
    15.         MessageBox.Show("°_©l­È =" & °_©l­È & vbCrLf & "²×¤î­È = " & ²×¤î­È & vbCrLf & "Á`©M=" & Á`©M.ToString)
    16.     End Sub

    17. End Class
    ½Æ»s¥N½X
    §Ú­Ì¥Ñµ²ªG«Ü§Öªº´N¥i¥H¤F¸Ñ,Á`©M³o­ÓÅܼƧڭ̬O¶Ç§}ªº,¤]´N¬O»¡,¦b¥D«ö¶sµ{§Ç¤¤ªºÁ`©MÅܼƨä¹ê¬O©Mµ{§Ç ¨DÁ`©M ¤¤ªºÁ`©MÅܼƬO¦@¥Î¦P¤@¦ì§}
    ¦]¦¹·í§Ú­Ì­×§ï¤F¨DÁ`©Mµ{§Ç¤¤ªºÁ`©MÅܼƨº´N·|³s¦P«ö¶sµ{§Ç¤ºªºÁ`©MÅܼƤ@°_­×§ï,¤]´N¬O¶Ç§}(byref)
    µM¦Ó,¶Ç­È(byval)¬O¤£¤@¼Ëªº,§Ú­Ì¦b¨DÁ`©Mµ{§Ç¤¤­×§ï¤F°_©l­È©M²×¤î­Èªº­È,µ²ªG«ö¶s¤ºªº°_©l­È©M²×¤î­Èªºµ²ªG¨ÌµM¤£ÅÜ ,¤ñ¸û²³æªº»¡ªk¬O
    ¦pªG§A·Q­n§A¶Ç¤Jµ{§Ç¤¤ªºÅܼƭȦbµ{§Çµ²§ô«á·|§ïÅܨ䵲ªG¨º´NÀ³¸Ó¶Ç§}(byref),¦pªG¤£·Q,¨º´NÀ³¸Ó¶Ç­È(byval),¥t¥~,¦pªG§A¶Çªº¬O°Ñ¦Ò«¬§O,¨º¤£½×¬O¶Ç­È©Î¬O¶Ç§}³£¤@¼Ë¬O°Ñ¦Ò¨ì¦ì§}
    1. Public Class Form1

    2.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    3.         Dim °}¦C() As Integer = {1, 2, 3, 4, 5}
    4.         ­×§ï°}¦C­È(°}¦C)
    5.         For Each ¤¸¯À As Integer In °}¦C
    6.             MessageBox.Show(¤¸¯À.ToString)
    7.         Next
    8.     End Sub

    9.     Sub ­×§ï°}¦C­È(ByVal ­×§ï«á°}¦C() As Integer)
    10.         For i As Integer = 0 To ­×§ï«á°}¦C.GetUpperBound(0)
    11.             ­×§ï«á°}¦C(i) = i + 10
    12.         Next i
    13.     End Sub
    14. End Class
    ½Æ»s¥N½X
    ¥Ñ¥H¤Wªºµ²ªG¥iª¾,´Nºâ¬O¶Ç­È,¹ï©ó°}¦C¦Ó¨¥,¤@¼Ë·|­×§ï°}¦C¤¤ªº­È,¥u¦]¬°°}¦C¬O°Ñ¦Ò«¬§O

  • ¨ç¼Æ
    µ{§Ç¹ê»Ú¤W¨Ã¤£¯à¶Ç¦^­È,§Ú­Ì¦³®É­Ô¦bµ{§Ç°õ¦æ§¹®É·Q­n¦³¤@¨Ç­È¦^¶Ç,³o®É­Ô´N»Ý­n¨ç¼Æ
    ©w¸q¨ç¼Æªº»yªk¦p¤U

        Function ¨ç¼Æ¦WºÙ(ByVal ¤Þ¼Æ¤@ As «¬ºA, ByVal ¤Þ¼Æ¤G As «¬ºA) As «¬ºA
            Return ÅܼÆ
        End Function

    ©Mµ{§Ç¤£¦Pªº¬O,¨ç¼Æ¤@©w­n¶Ç¦^­È,¸Ó¦^­Èªº«¬ºA¤@©w­n©M¨ç¼Æ¥»¨­©w¸qªº«¬ºA¬Û¦P
    §Ú­Ì§ï¼g¤W­±ªº¨Ò¤l¦p¤U
    1. Public Class Form1
    2.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    3.         MessageBox.Show(¨DÁ`©M(-10, 100).ToString)
    4.     End Sub
    5.     Function ¨DÁ`©M(ByVal °_©l­È As Integer, ByVal ²×¤î­È As Integer) As Integer
    6.         Dim Á`©M As Integer = 0
    7.         For i As Integer = °_©l­È To ²×¤î­È
    8.             Á`©M = Á`©M + i
    9.         Next
    10.         Return Á`©M
    11.     End Function
    12. End Class
    ½Æ»s¥N½X
    «Ü²M·¡ªº§Ú­Ì¥i¥H¬Ý¨ì¨ç¼Æ¥»¨­´N¥i¥H¦³­È

    ¥t¥~,¨ç¼Æ¥»¨­¥ç¦^¶Ç°}¦C¥H¤U¬°¨Ò
    1. Public Class Form1

    2.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    3.         For Each ¤¸¯À In ¦^¶Ç¦h­Ó­È()
    4.             MessageBox.Show(¤¸¯À.ToString)
    5.         Next

    6.     End Sub

    7.     Function ¦^¶Ç¦h­Ó­È() As Integer()

    8.         Dim ¦^¶Ç°}¦C() As Integer = {1, 2, 3, 4, 5}
    9.         Return ¦^¶Ç°}¦C

    10.     End Function

    11. End Class
    ½Æ»s¥N½X


µ{§Ç©M¨ç¼Æ³£¥i¥H¦³¦h¸ü,©Ò¿×ªº¦h¸ü´N¬O¦P¼Ëªº ¨ç¼Æ/µ{§Ç ¦WºÙ ,¦ý¤º³¡©w¸q¤£¦P
,·|¦³³oºØªº¤èªk¥D­n¬O¤è«K§Ú­Ì¥u­n©w¤@­Ó ¨ç¼Æ/µ{§Ç ¦WºÙ ´N¥i¥H°µ¥X¤£¦Pªº¤èªk
¦h¸üªº»yªk¬°¥u­n¦b ¨ç¼Æ/µ{§Ç ¤§«e¥[¤@­ÓOverloads ´N¥i¥H
  1. Public Class Form1
  2.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  3.         Dim À\¨ã As String = "¸_¤l"
  4.         ¶¼­¹(À\¨ã)
  5.         ¶¼­¹()
  6.     End Sub

  7.     Sub ¶¼­¹(ByVal À\¨ã As String)
  8.         MessageBox.Show("¥xÆW¤H¥Î" & À\¨ã & "¦Y¶º")
  9.     End Sub

  10.     Overloads Sub ¶¼­¹()
  11.         MessageBox.Show("¦L«×¤H¥Î¥k¤â±N¶º®º¦¨¤@¹Î¨Ó¦Y")
  12.     End Sub
  13. End Class
½Æ»s¥N½X

¨ä¹ê§Ú³Ìªñ¦b·s¾Çvb2010
¹ï©ó¼Ó¥D¤å¤¤´£¨ìªº
Sub µ{§Ç¦Wµ{(byval ÅܼÆ1 as «¬ºA ,byval ÅܼÆ2 as «¬ºA,.........,byval ÅܼÆn as «¬ºA )
¦³¨ÇºÃ°Ý~
³oÃä¼Ó¥Dªº¤å¤¤¬O±N[byval ÅܼÆ1 as «¬ºA]¥ý·Rsub¤¤¥ý«ü©w
  ³o»P¦bµ{¦¡¤¤¥h«ü©w Dim  ÅܼÆ1 as integer(«¬ºA)
  ¦³¦ó®t²§©Ê©O??
¾Ç²ß¤~¯à´£¤É¦Û¤v

TOP

VB»PExcel VBA »yªk¦n¹³.
¤£¦n·N«ä§Ú¬O·s¤â,½Ð°Ý¤GªÌ®t¦b¨º¸Ì©O?

TOP

¨ä¹ê§Ú³Ìªñ¦b·s¾Çvb2010
¹ï©ó¼Ó¥D¤å¤¤´£¨ìªº
Sub µ{§Ç¦Wµ{(byval ÅܼÆ1 as «¬ºA ,byval ÅܼÆ2 as «¬ºA,.. ...
hugh0620 µoªí©ó 2011-6-20 13:32

sub «á­±byval ±µªºÅܼÆ, ¬O¥i¥H±µ¨ü¥~¨Ó¸ê®Æ¶Ç»¼, ¦ýÅܼƭȭY¦b sub ¸Ì­±¦³³Q²§°Ê, ¬O¤£·|¶Ç¦^¥h. ­Y­n¶Ç¦^¥h, ½Ð§ï¦¨ byRef.
¦Ó¦b sub ¸Ì­±©Ò«Å§iªºÅܼÆ,  ¤j³£¬O°Ï°ìÅܼÆ.

TOP

sub «á­±byval ±µªºÅܼÆ, ¬O¥i¥H±µ¨ü¥~¨Ó¸ê®Æ¶Ç»¼, ¦ýÅܼƭȭY¦b sub ¸Ì­±¦³³Q²§°Ê, ¬O¤£·|¶Ç¦^¥h. ­Y­n¶Ç ...
alumi µoªí©ó 2012-6-1 00:56



´±°Ý¤j¤j
©Ò¥H±µ¦bsub«á­±ªºÅܼƬO³q¥Î¦b¥þ°ìªº¶Ü
¤pªº¤]¬O¦Û¾Çªº·s¤â
³Â·Ð«ü±Ð

TOP

½Ð°Ý¤j¤j¡G
§Ú½Æ»s¤F³Ì«á¤@­Ó"À\¨ã"ªº»yªk¡A¨Ã¶K¨ìModule1¡A¦ý...¦bExcelªí®æ³£¬OªÅ¥Õªº°Ú...
¬O¦³¹ïÀ³ªº®æ¤l(¦pA1 ©Î A2)¶Ü?  ÁÙ¬O§Ú»Ý­n«ö¤°»ò«öÁä¶Ü@@?

TOP

        ÀR«ä¦Û¦b : «Ý¤H°h¤@¨B¡A·R¤H¼e¤@¤o¡A´N·|¬¡±o«Ü§Ö¼Ö¡C
ªð¦^¦Cªí ¤W¤@¥DÃD