如何用VB做超连接?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何用VB做超连接?相关的知识,希望对你有一定的参考价值。
在网页搜到的都是连接到网址的,我编个 本地超连接 的,点击连接后可以打开本地的某个应用程序。
参考技术A 用一个LABEL框,把label框的autosize改为TURE,backstyle改为0,forecolor改为蓝色,字体加下划线然后用下面的代码就OK了
Private
Declare
Function
ShellExecute
Lib
"shell32.dll"
Alias
"ShellExecuteA"
_
(ByVal
hwnd
As
Long,
ByVal
lpOperation
As
String,
ByVal
lpFile
As
String,
_
ByVal
lpParameters
As
String,
ByVal
lpDirectory
As
String,
ByVal
nShowCmd
As
Long)
As
Long
Private
Sub
Label1_Click()
Dim
HttpJump
Dim
MyUrl
As
String
MyUrl
=
"
http://wenwen.soso.com
"
HttpJump
=
ShellExecute(0&,
vbNullString,
MyUrl,
vbNullString,
vbNullString,
vbNormalFocus)
End
Sub 参考技术B 用shell函数直接调用你需要打开的可执行应用程序即可
Private
Sub
Command1_Click()
Call
Shell("cmd.exe",
vbNormalFocus)
'此处只需将"cmd.exe"换为你需要打开的可执行程序的绝对路径即可
End
Sub
如何用vb开发程序直接通过以太网tcp协议访问s7-1200的存储区域
tcp协议是一个世界公开的协议,既然你在vb端能搞定如何进行数据通讯,1200就很简单了。在1200侧你只需建立一个tcp的连接即可,连接类型为未指定,之后按照你自己的要求确定谁是客户机,谁是服务器就好了,具体的建立连接的步骤可以参照1200的文档,你可以在下面的文档的通讯一章找到如何建立TCP连接的过程
西门子 S7-1200 PLC Smart Plus 技术参考Version 1.8 参考技术A
VB6.0还是VB.NET?
在此写一段VB.NET的代码:
Dim Handle1 As Int32Dim EntLink As Boolean
Dim PLC As New WinTcpS7_1K.PlcClient
Private Sub butLink_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butLink.Click
Dim re As Short
Dim restr As String = ""
re = PLC.EntLink(Trim(txtLocalIP.Text), Val(txtLocalPort.Text), Trim(txtRemoteIP.Text), Val(txtRemotePort.Text), 0, 1, "DEMO", Handle1)
txtReLink.Text = re.ToString
If re = 0 Then
EntLink = True
MsgBox("PLC联接成功!")
Else
EntLink = False
MsgBox("PLC联接失败: " & restr)
End If
End Sub
Private Sub butClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butClose.Click
Dim re As Short
re = PLC.DeLink(Handle1)
txtReClose.Text = re.ToString
EntLink = False
End Sub
Private Sub butRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butRead.Click
Dim i As Short
Dim re As Short
Dim RD() As Object
ReDim RD(Val(txtReadCnt.Text - 1))
If Not EntLink Then
MsgBox("还未与PLC建立联接!")
Exit Sub
End If
Dim var1 As Integer = cmbReadType.SelectedIndex + 1
Dim typ As WinTcpS7_1K.PlcClient.DataType = var1
Select Case cmbReadMry.SelectedIndex
Case 0 : re = PLC.CmdRead(Handle1, WinTcpS7_1K.PlcClient.PlcMemory.DI, typ, CUShort(Val(txtReadBlock.Text)), CUShort(Val(txtReadAdd.Text)), CUShort(Val(txtReadCnt.Text)), RD)
Case 1 : re = PLC.CmdRead(Handle1, WinTcpS7_1K.PlcClient.PlcMemory.DQ, typ, CUShort(Val(txtReadBlock.Text)), CUShort(Val(txtReadAdd.Text)), CUShort(Val(txtReadCnt.Text)), RD)
Case 2 : re = PLC.CmdRead(Handle1, WinTcpS7_1K.PlcClient.PlcMemory.MR, typ, CUShort(Val(txtReadBlock.Text)), CUShort(Val(txtReadAdd.Text)), CUShort(Val(txtReadCnt.Text)), RD)
Case 3 : re = PLC.CmdRead(Handle1, WinTcpS7_1K.PlcClient.PlcMemory.DR, typ, CUShort(Val(txtReadBlock.Text)), CUShort(Val(txtReadAdd.Text)), CUShort(Val(txtReadCnt.Text)), RD)
End Select
txtReRead.Text = re.ToString
lstRead.Items.Clear()
For i = 0 To UBound(RD) Step 1
If Not IsNothing(RD(i)) Then
lstRead.Items.Add(RD(i))
Else
lstRead.Items.Add("0")
End If
Next i
End Sub
Private Sub butWrite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butWrite.Click
Dim i As Short
Dim re As Short
Dim temp() As String
Dim WD() As Object
If Not EntLink Then
MsgBox("还未与PLC建立联接!")
Exit Sub
End If
ReDim WD(Val(txtWriteCnt.Text) - 1)
temp = Split(txtWrite.Text, vbCrLf)
For i = 0 To UBound(WD) Step 1
If i > UBound(temp) Then
WD(i) = 0
Else
WD(i) = Trim(temp(i))
End If
Next i
Dim var1 As Integer = cmbWriteType.SelectedIndex + 1
Dim typ As WinTcpS7_1K.PlcClient.DataType = var1
Select Case cmbWriteMry.SelectedIndex
Case 0 : re = PLC.CmdWrite(Handle1, WinTcpS7_1K.PlcClient.PlcMemory.DI, typ, CUShort(Val(txtWriteBlock.Text)), CUShort(Val(txtWriteAdd.Text)), CUShort(Val(txtWriteCnt.Text)), WD)
Case 1 : re = PLC.CmdWrite(Handle1, WinTcpS7_1K.PlcClient.PlcMemory.DQ, typ, CUShort(Val(txtWriteBlock.Text)), CUShort(Val(txtWriteAdd.Text)), CUShort(Val(txtWriteCnt.Text)), WD)
Case 2 : re = PLC.CmdWrite(Handle1, WinTcpS7_1K.PlcClient.PlcMemory.MR, typ, CUShort((txtWriteBlock.Text)), CUShort(Val(txtWriteAdd.Text)), CUShort(Val(txtWriteCnt.Text)), WD)
Case 3 : re = PLC.CmdWrite(Handle1, WinTcpS7_1K.PlcClient.PlcMemory.DR, typ, CUShort(Val(txtWriteBlock.Text)), CUShort(Val(txtWriteAdd.Text)), CUShort(Val(txtWriteCnt.Text)), WD)
End Select
txtReWrite.Text = re.ToString
End Sub
以上是关于如何用VB做超连接?的主要内容,如果未能解决你的问题,请参考以下文章