Private?Sub?GetMyIP()
創(chuàng)新互聯(lián)建站是一家專注于成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作與策劃設(shè)計(jì),嵩明網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)建站做網(wǎng)站,專注于網(wǎng)站建設(shè)十年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:嵩明等地區(qū)。嵩明做網(wǎng)站價(jià)格咨詢:028-86922220
Dim?strComputer?As?String
Dim?objWMI?As?Object
Dim?colIP?As?Object
Dim?IP?As?Object
Dim?I?As?Integer
strComputer?=?"."
objWMI?=?GetObject("winmgmts://"??strComputer??"/root/cimv2")
colIP?=?objWMI.ExecQuery?_
("Select?*?from?Win32_NetworkAdapterConfiguration?where?IPEnabled=TRUE")
For?Each?IP?In?colIP
If?Not?IsNothing(IP.IPAddress)?Then
For?I?=?LBound(IP.IPAddress)?To?UBound(IP.IPAddress)
MsgBox("IP?地址:"??IP.IPAddress(I)??Chr(10)??_
"網(wǎng)卡類型:"??IP.Description(I)??Chr(10)??_
"網(wǎng)卡地址:"??IP.Macaddress(I))
Next
End?If
Next
End?Sub
求行:
RichTextBox1.GetLineFromChar(RichTextBox1.SelStart)+1
這個(gè)代碼呢,我的理解呢,是獲取在selstart的地方的行數(shù)。一般來(lái)講selstart的地方都是光標(biāo)的地方,然后會(huì)給你返回line。不過(guò)返回的時(shí)候要自己加1。不是很懂這個(gè)語(yǔ)法,有懂得可以教我一下
以上是求行數(shù)。
求列:
For i = 0 To RichTextBox1.SelStart
If RichTextBox1.GetLineFromChar(RichTextBox1.SelStart) - RichTextBox1.GetLineFromChar(RichTextBox1.SelStart - i) 0 Then Exit For
j = j + 1
Next i
這個(gè)for循環(huán)呢,講的是檢查這一行光標(biāo)前有多少個(gè)列,然后用J輸出列的個(gè)數(shù)。
因?yàn)閂B6.0沒(méi)有RichTextBox1.GetFirstCharIndexOfCurrentLine這種語(yǔ)法。所以就得自己模擬這個(gè)過(guò)程。
具體怎么檢查的呢,首先將 i 從0循環(huán)到光標(biāo)處,
如果 【光標(biāo)字符數(shù)】處的行數(shù) 減去 【光標(biāo)字符數(shù)減去 i 個(gè)字符數(shù)】處的行數(shù)小于0了,我寫(xiě)了個(gè)不為零。但此時(shí)寫(xiě)小于零就可以。那么代表著換行了,同時(shí)也代表著光標(biāo)到上一行之間有多少字。用j存儲(chǔ)循環(huán)次數(shù),得出對(duì)應(yīng)列數(shù)。(我們中文習(xí)慣是叫第一列,但程序?qū)嶋H上是第零列,但在循環(huán)的時(shí)候就注意到并解決這個(gè)問(wèn)題了)
如果你替換寫(xiě)法,例如
If RichTextBox1.GetLineFromChar(RichTextBox1.SelStart) - RichTextBox1.GetLineFromChar(RichTextBox1.SelStart + i) 0 Then Exit For
j = j + 1
Next i
這個(gè) J 就對(duì)應(yīng)著光標(biāo)到該行結(jié)尾有幾個(gè)字符了,如果有需要可以使用,但一般不需要。
那么就像上面說(shuō)的那樣,行列都求出來(lái)了,最后用事件和TEXT或者caption表現(xiàn)出來(lái)就好了
至于說(shuō)總行數(shù)
RichTextBox1.GetLineFromChar(Len(RichTextBox1.Text)) + 1
通過(guò)對(duì)最后一個(gè)字符的位置(總長(zhǎng)度)的行來(lái)判斷唄,不過(guò)也得加一。
.net不能獲得【指定】網(wǎng)卡的信息,給個(gè)思路,先遍歷所有網(wǎng)卡,然后找到你需要的的那個(gè)網(wǎng)卡的信息。
用 vb.net socket通信
Dim th As Threading.Thread
2 Dim tcpl As System.Net.Sockets.TcpListener
3
4 Private Sub Form1_Load()Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
5 th = New System.Threading.Thread(New System.Threading.ThreadStart(AddressOf MyListen))
6 th.Start()
7 End Sub
8
9 Public Sub SendMessage()Sub SendMessage(ByVal IP As String, ByVal SendMsg As String)
10 Try
11 If IP "" Then
12 Dim tcpc As New System.Net.Sockets.TcpClient(IP, 5656)
13 Dim tcpStream As Net.Sockets.NetworkStream = tcpc.GetStream
14 Dim reqStream As New IO.StreamWriter(tcpStream)
15 reqStream.Write(SendMsg)
16 reqStream.Flush()
17 tcpStream.Close()
18 tcpc.Close()
19 End If
20 Catch ex As Exception
21 MsgBox(ex.Message.ToString)
22 End Try
23 End Sub
24 Private Sub MyListen()Sub MyListen()
25 Try
26 Dim ipAddress As System.Net.IPAddress = System.Net.Dns.Resolve(System.Net.Dns.GetHostName).AddressList(0)
27 tcpl = New System.Net.Sockets.TcpListener(ipAddress, 5656)
28 tcpl.Start()
29 While True
30 Dim s As System.Net.Sockets.Socket = tcpl.AcceptSocket()
31 Dim MyBuffer(1024) As Byte
32 Dim i As Integer
33 i = s.Receive(MyBuffer)
34 If i 0 Then
35 Dim lstrRec As String
36 Dim j As Integer
37 For j = 0 To i - 1
38 TextBox1.Text += Chr(MyBuffer(j)) ","
39 Next
40 End If
41 End While
42 Catch ex As Exception
43 MsgBox(ex.Message.ToString)
44 End Try
45 End Sub
46
47 Private Sub Button1_Click()Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
48 SendMessage("192.168.0.61", TextBox2.Text)
49 End Sub