Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Anonymous
Anonymous asked in 電腦與網際網路程式設計 · 2 decades ago

VB的public如何使用?

VB的public如何使用...........................?

1 Answer

Rating
  • 2 decades ago
    Favorite Answer

    應該是如何宣告吧?例如 dim i as Integer這個宣告改成Public i as Integer即可,變數的宣告是有效用範圍的,必須視你宣告的範圍而定,例如~~

    Private Sub A()

    Public i as Integer

    dim j as integer

    I=10

    j=5

    ..........

    end sub()

    Private sub B()

    print i

    print j

    end sub()

    如果執行B函數時結果是i=10,j=0,因為i被宣告成公用變數而j並沒有,這個就是Public的用途,而這種宣告的方式是公用的區域變數,不能跨表單;如果要跨表單的話,宣告就必須變成~~

    Public i as Integer

    Private Sub A()

    dim j as integer

    I=10

    j=5

    ..........

    end sub()

    Public的宣告不被包含在Private Sub A()和end sub之間的話,那這樣的宣告就變成了全域的公用變數!

Still have questions? Get your answers by asking now.