国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
VB.NET Main過(guò)程四種聲明方法總結(jié)

VB.NET Main過(guò)程的聲明可以通過(guò)四種不同的方法來(lái)進(jìn)行。編程人員在實(shí)際開發(fā)中可以看、根據(jù)自己不同的需求來(lái)進(jìn)行選擇。

AD: 2013云計(jì)算架構(gòu)師峰會(huì)課程資料下載

VB.NET編程語(yǔ)言的應(yīng)用范圍非常廣泛,其編寫方式的特殊性極大的吸引了編程人員的眼光。在學(xué)習(xí)這一語(yǔ)言的時(shí)候,我們會(huì)遇到有關(guān)VB.NET Main過(guò)程的相關(guān)概念,那么如何才能正確理解這一過(guò)程的聲明呢?大家可以在這里找到一些答案。

每個(gè) Visual Basic 應(yīng)用程序均必須包含一個(gè)稱為VB.NET Main過(guò)程。該過(guò)程為應(yīng)用程序的起始點(diǎn)并為應(yīng)用程序提供總體控制。.NET Framework 在已加載應(yīng)用程序并準(zhǔn)備將控制傳遞給它時(shí),將調(diào)用 Main 過(guò)程。除非您要?jiǎng)?chuàng)建 Windows 窗體應(yīng)用程序,否則就必須為自運(yùn)行的應(yīng)用程序編寫 Main 過(guò)程。

Main 中包含首先運(yùn)行的代碼。在 Main 中,可以確定在程序啟動(dòng)時(shí)首先加載的窗體,確定系統(tǒng)上是否已在運(yùn)行您的應(yīng)用程序副本,為應(yīng)用程序建立一組變量,或者打開應(yīng)用程序需要的數(shù)據(jù)庫(kù)。

VB.NET Main過(guò)程的要求

獨(dú)立運(yùn)行的文件(擴(kuò)展名通常為 .exe)必須包含 Main 過(guò)程。庫(kù)(例如,擴(kuò)展名為 .dll)不獨(dú)立運(yùn)行,因而不需要 Main 過(guò)程。可以創(chuàng)建的不同類型的項(xiàng)目的要求如下:

控制臺(tái)應(yīng)用程序可以獨(dú)立運(yùn)行,而且您必須提供至少一個(gè) Main 過(guò)程。

Windows 窗體應(yīng)用程序可以獨(dú)立運(yùn)行。但是,Visual Basic 編譯器會(huì)在此類應(yīng)用程序中自動(dòng)生成一個(gè) Main 過(guò)程,因而您不需要編寫此過(guò)程。

類庫(kù)不需要 Main 過(guò)程。這些類庫(kù)包括 Windows 控件庫(kù)和 Web 控件庫(kù)。作為類庫(kù)部署 Web 應(yīng)用程序。

聲明VB.NET Main過(guò)程

有四種方法可以聲明 Main 過(guò)程。它可以使用參數(shù)或不使用參數(shù),可以返回值或不返回值。

注意

如果在類中聲明 Main 過(guò)程,則必須使用 Shared 關(guān)鍵字。在模塊中,Main 不必是 Shared。

最簡(jiǎn)單的方法是聲明一個(gè)不使用參數(shù)或不返回值的 Sub 過(guò)程。

  1. Module mainModule  
  2. Sub Main()  
  3. MsgBox("The Main procedure 
    is starting the application.")  
  4. ' Insert call to appropriate
     starting place in your code.  
  5. MsgBox("The application 
    is terminating.")  
  6. End Sub  
  7. End ModuleMain 

還可以返回一個(gè) Integer 值,操作系統(tǒng)將其作為程序的退出代碼。其他程序可以通過(guò)檢查 Windows ERRORLEVEL 值來(lái)測(cè)試該代碼。若要返回退出代碼,必須將VB.NET Main過(guò)程聲明為 Function 過(guò)程而不是 Sub 過(guò)程。

  1. Module mainModule  
  2. Function Main() As Integer  
  3. MsgBox("The Main procedure 
    is starting the application.")  
  4. Dim returnValue As Integer = 0 
  5. ' Insert call to appropriate 
    starting place in your code.  
  6. ' On return, assign appropriate 
    value to returnValue.  
  7. ' 0 usually means successful 
    completion.  
  8. MsgBox("The application is 
    terminating with error level " _  
  9. & CStr(returnValue) & ".")  
  10. Return returnValue  
  11. End Function  
  12. End ModuleMain 

還可以采用一個(gè) String 數(shù)組作為參數(shù)。數(shù)組中的每個(gè)字符串均包含一個(gè)用于調(diào)用程序的命令行參數(shù)。您可以根據(jù)它們的值采取不同的操作。

  1. Module mainModule  
  2. Function Main(ByVal cmdArgs() 
    As String) As Integer  
  3. MsgBox("The Main procedure is 
    starting the application.")  
  4. Dim returnValue As Integer = 0 
  5. ' See if there are any arguments.  
  6. If cmdArgs.Length > 0 Then  
  7. For argNum As Integer = 0 To 
    UBound(cmdArgs, 1)  
  8. ' Insert code to examine cmdArgs
    (argNum) and take  
  9. ' appropriate action based on its value.  
  10. Next argNum  
  11. End If  
  12. ' Insert call to appropriate starting 
    place in your code.  
  13. ' On return, assign appropriate 
    value to returnValue.  
  14. ' 0 usually means successful completion.  
  15. MsgBox("The application is 
    terminating with error level " _  
  16. & CStr(returnValue) & ".")  
  17. Return returnValue  
  18. End Function  
  19. End Module 

可以聲明VB.NET Main過(guò)程來(lái)檢查命令行參數(shù)而不返回退出代碼,如下所示。

  1. Module mainModule  
  2. Sub Main(ByVal cmdArgs() As String)  
  3. MsgBox("The Main procedure is 
    starting the application.")  
  4. Dim returnValue As Integer = 0 
  5. ' See if there are any arguments.  
  6. If cmdArgs.Length > 0 Then  
  7. For argNum As Integer = 0 To 
    UBound(cmdArgs, 1)  
  8. ' Insert code to examine cmdArgs
    (argNum) and take  
  9. ' appropriate action based on its value.  
  10. Next argNum  
  11. End If  
  12. ' Insert call to appropriate 
    starting place in your code.  
  13. MsgBox("The application is 
    terminating."  
  14. End Sub  
  15. End Module 

VB.NET Main過(guò)程的相關(guān)操作方法就為大家介紹到這里。

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
VBA和VB應(yīng)用程序之異同和相互移植
控制AutoCAD環(huán)境(一) 控制應(yīng)用程序窗口
vb.net 獲取當(dāng)前應(yīng)用程序所在的路徑
VB如何實(shí)現(xiàn)MsgBox自動(dòng)關(guān)閉
VB操作Excel文件常用命令總結(jié)
vb打開EXCEL(vb 路徑 Excel路徑)
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服