Foxtable(狐表)用户栏目专家坐堂 → 怎樣轉換這段VB.net代碼為FT代碼


  共有4259人关注过本帖树形打印复制链接

主题:怎樣轉換這段VB.net代碼為FT代碼

帅哥哟,离线,有人找我吗?
jaegea
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:480 积分:3838 威望:0 精华:0 注册:2011/5/31 15:45:00
怎樣轉換這段VB.net代碼為FT代碼  发帖心情 Post By:2014/5/15 16:02:00 [只看该作者]

Option Explicit On
Imports Microsoft.Win32
Public Class SearchforUSBCom
    'Search for the virtual serial port created by usbclient.
    Public Function SearchforCom(ByRef sCom As String) As Boolean
        Dim sComValue As String
        Dim sTmpara As String
        Dim myReg As RegistryKey
        myReg = Registry.LocalMachine.OpenSubKey("HARDWARE\\DEVICEMAP\\SERIALCOMM")

        Dim sComName() As String
        sComName = myReg.GetValueNames() 'strings array composed of the key name holded by the subkey "SERIALCOMM"
        Dim i As Integer
        For i = 0 To sComName.Length - 1
            sComValue = myReg.GetValue(sComName(i)).ToString() 'obtain the key value of the corresponding key name
            If sComValue = "" Then
                Continue For
            End If

            sCom = ""
            Dim j As Integer
            If sComName(i) = "\Device\USBSER000" Then 'find the virtual serial port created by usbclient
                For j = 0 To 10
                    sTmpara = ""
                    Dim myReg2 As RegistryKey
                    myReg2 = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Enum\\USB\\VID_1B55&PID_B400\\" & j.ToString() & "\\Device Parameters")

                    If myReg2 IsNot Nothing Then
                        sTmpara = myReg2.GetValue("PortName").ToString()

                        If sComValue = sTmpara Then
                            sCom = sTmpara
                            Return True
                        End If
                    End If
                Next
            End If
        Next
        Return False
    End Function
End Class


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2014/5/15 16:06:00 [只看该作者]

 如下。全局代码那里输入

 

Public Class SearchforUSBCom
    'Search for the virtual serial port created by usbclient.
    Public Function SearchforCom(ByRef sCom As String) As Boolean
        Dim sComValue As String
        Dim sTmpara As String
        Dim myReg As Microsoft.Win32.RegistryKey
        myReg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("HARDWARE\\DEVICEMAP\\SERIALCOMM")

        Dim sComName() As String
        sComName = myReg.GetValueNames() 'strings array composed of the key name holded by the subkey "SERIALCOMM"
        Dim i As Integer
        For i = 0 To sComName.Length - 1
            sComValue = myReg.GetValue(sComName(i)).ToString() 'obtain the key value of the corresponding key name
            If sComValue = "" Then
                Continue For
            End If

            sCom = ""
            Dim j As Integer
            If sComName(i) = "\Device\USBSER000" Then 'find the virtual serial port created by usbclient
                For j = 0 To 10
                    sTmpara = ""
                    Dim myReg2 As Microsoft.Win32.RegistryKey
                    myReg2 = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Enum\\USB\\VID_1B55&PID_B400\\" & j.ToString() & "\\Device Parameters")

                    If myReg2 IsNot Nothing Then
                        sTmpara = myReg2.GetValue("PortName").ToString()

                        If sComValue = sTmpara Then
                            sCom = sTmpara
                            Return True
                        End If
                    End If
                Next
            End If
        Next
        Return False
    End Function
End Class


 回到顶部
帅哥哟,离线,有人找我吗?
Bin
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:35433 积分:178524 威望:0 精华:3 注册:2013/3/30 16:36:00
  发帖心情 Post By:2014/5/15 16:06:00 [只看该作者]

直接复制到全局代码即可

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2014/5/15 16:07:00 [只看该作者]


 回到顶部
帅哥哟,离线,有人找我吗?
jaegea
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:480 积分:3838 威望:0 精华:0 注册:2011/5/31 15:45:00
  发帖心情 Post By:2014/5/15 16:07:00 [只看该作者]

謝謝

 回到顶部
帅哥哟,离线,有人找我吗?
jaegea
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:480 积分:3838 威望:0 精华:0 注册:2011/5/31 15:45:00
  发帖心情 Post By:2014/5/15 16:13:00 [只看该作者]

把代碼改成這樣做成函數是不是一樣的效果?

 

Dim sCom As String = Args(0)
Dim sComValue As String
Dim sTmpara As String
Dim myReg As Microsoft.Win32.RegistryKey
myReg = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("HARDWARE\\DEVICEMAP\\SERIALCOMM")

Dim sComName() As String
sComName = myReg.GetValueNames() 'strings array composed of the key name holded by the subkey "SERIALCOMM"
Dim i As Integer
For i = 0 To sComName.Length - 1
    sComValue = myReg.GetValue(sComName(i)).ToString() 'obtain the key value of the corresponding key name
    If sComValue = "" Then
        Continue For
    End If
   
    sCom = ""
    Dim j As Integer
    If sComName(i) = "\Device\USBSER000" Then 'find the virtual serial port created by usbclient
        For j = 0 To 10
            sTmpara = ""
            Dim myReg2 As Microsoft.Win32.RegistryKey
            myReg2 = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Enum\\USB\\VID_1B55&PID_B400\\" & j.ToString() & "\\Device Parameters")
           
            If myReg2 IsNot Nothing Then
                sTmpara = myReg2.GetValue("PortName").ToString()
               
                If sComValue = sTmpara Then
                    sCom = sTmpara
                    Return True
                End If
            End If
        Next
    End If
Next
Return False


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2014/5/15 16:14:00 [只看该作者]

是的,亲

 回到顶部
帅哥哟,离线,有人找我吗?
Bin
  8楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:35433 积分:178524 威望:0 精华:3 注册:2013/3/30 16:36:00
  发帖心情 Post By:2014/5/15 16:14:00 [只看该作者]

YOU一点点不一样.  ByRef sCom As String  这个变量在全局代码的这种方式下是可以带值出去的.

 回到顶部
帅哥哟,离线,有人找我吗?
jaegea
  9楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:480 积分:3838 威望:0 精华:0 注册:2011/5/31 15:45:00
  发帖心情 Post By:2014/5/15 16:14:00 [只看该作者]

非常感謝,又學到了一招,哈哈

 回到顶部