VB.NET中的函數(shù)應(yīng)用方式是一個(gè)比較基礎(chǔ)的知識(shí)點(diǎn)。我們可以通過(guò)實(shí)踐來(lái)積累經(jīng)驗(yàn),充分掌握這些函數(shù)的應(yīng)用方法。在這里我們就先為大家詳細(xì)介紹幾個(gè)VB.NET基本函數(shù)的應(yīng)用方法,希望能給大家?guī)?lái)一些幫助。
判斷該窗體是否已經(jīng)打開
- Public Function OpenForm
(ByVal myform As Form, ByVal
MdiForm As Form) As Boolean- Dim form As Form
- For Each form In MdiForm.
MdiChildren- If form.Text = myform.
Text Then- form.Activate()
- Return True
- End If
- Next
- Return False
- End Function
系統(tǒng)退出時(shí)的代碼
- Public Sub ExitSystem
(ByVal Form_Name As String)- If Form_Name = "Exit" Then
- ' If MsgBox("您真的要退出文件管理系統(tǒng)嗎?",
MsgBoxStyle.YesNo + MsgBoxStyle.
Question, "退出系統(tǒng)") =
MsgBoxResult.Yes Then- Application.Exit()
- End
- 'End If
- End If
- End Sub
判斷字符是否為數(shù)字型,當(dāng)為數(shù)字時(shí)返回True,不為時(shí)返回False
- Public Function IsNumeric
(ByVal strText As String)
As Boolean- Dim charstr As Char
- For Each charstr In strText
- If Not Char.IsNumber
(charstr) Then- Return False
- End If
- Next
- Return True
- End Function
加密函數(shù)
- Function EnPas(ByVal CodeStr
As String) As String- Dim CodeLen As Integer = 30
- Dim CodeSpace, Been, NewCodeInt
As Integer- Dim EnPasStr As String = ""
- Dim NewCode As String
- CodeSpace = CodeLen - CodeStr.Length
- If Not CodeSpace < 1 Then
- For cecr As Integer = 1 To CodeSpace
- CodeStrCodeStr = CodeStr & Chr(21)
- Next
- End If
- NewCodeInt = 1
- NewCode = 1
- For cecb As Integer = 1 To CodeLen
- Been = CodeLen + Asc(CodeStr.
Substring(cecb - 1, 1)) * cecb- NewCodeNewCode = NewCode * Been
- Next
- CodeStr = NewCode
- NewCode = Nothing
- For cec As Integer = 1 To CodeStr.Length
- Try
- NewCodeNewCode = NewCode &
CfsCode(CodeStr.Substring(cec - 1, 3))- Catch ex As Exception
- Try
- NewCodeNewCode = NewCode & CfsCode
(CodeStr.Substring(cec - 1, 2))- Catch exs As Exception
- NewCodeNewCode = NewCode & CfsCode
(CodeStr.Substring(cec - 1, 1))- End Try
- End Try
- Next
- For cec As Integer = 20 To NewCode.
Length - 18 Step 2- EnPasStrEnPasStr = EnPasStr & NewCode.
Substring(cec - 1, 1)- Next
- Return EnPasStr
- End Function
加密子函數(shù)
- Function CfsCode(ByVal Word
As String) As String- Dim CfsCodeStr As String = ""
- For cc As Integer =
1 To Word.Length- CfsCodeStrCfsCodeStr =
CfsCodeStr & Asc(Word.
Substring(cc - 1, 1))- Next
- CfsCodeStr = Hex(CfsCodeStr)
- Return CfsCodeStr
- End Function
打開某一個(gè)程序 程序的路徑
- Public Function Openfile
(ByVal FilePath As String)
As Boolean- Try
- System.Diagnostics.Process.
Start(FilePath)- Return True
- Catch ex As Exception
- MsgBox(ex.Message)
- Return False
- Exit Function
- End Try
- End Function
- #Region " XML文件操作部分(系統(tǒng)設(shè)置) "
- Public Sub RendXml(ByVal
filename As String)- Dim falg As Boolean = True
- Dim fi As System.IO.FileInfo
- fi = New System.IO.FileInfo(filename)
- If fi.Exists Then
- Dim doc As New XmlDocument
- doc.Load(filename)
- Dim nodeRoot = doc.DocumentElement
連接數(shù)據(jù)庫(kù)的IP、數(shù)據(jù)庫(kù)名稱、用戶名、密碼
- Sys_Data_Source = nodeRoot.
SelectSingleNode("Sys_Data_Source")
.InnerText- Sys_Data_Catalog = nodeRoot.
SelectSingleNode("Sys_Data_Catalog")
.InnerText- Sys_Data_User = nodeRoot.
SelectSingleNode("Sys_Data_User")
.InnerText- Sys_Data_Password = nodeRoot.
SelectSingleNode("Sys_Data_Password")
.InnerText- Else
- MessageBox.Show("系統(tǒng)初始化出錯(cuò),
請(qǐng)與系統(tǒng)管理員聯(lián)系??!", "嚴(yán)重警告",
MessageBoxButtons.OK, MessageBoxIcon.Error)- End
- End If
- End Sub
- #End Region
VB.NET基本函數(shù)的相關(guān)概念就為大家介紹到這里。
聯(lián)系客服