⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clientform.frm

📁 这些是我特地制作的分布式计算的示例程序
💻 FRM
📖 第 1 页 / 共 2 页
字号:
   Begin VB.Label Label2 
      Caption         =   "服务端端口"
      BeginProperty Font 
         Name            =   "楷体_GB2312"
         Size            =   12
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   3240
      TabIndex        =   2
      Top             =   240
      Width           =   1215
   End
   Begin VB.Label Label1 
      Caption         =   "服务端IP"
      BeginProperty Font 
         Name            =   "楷体_GB2312"
         Size            =   12
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   120
      TabIndex        =   0
      Top             =   240
      Width           =   1095
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'分布式计算开发示例
'原作者 郝佳男
Private Sub Command1_Click()
'Disable the button
Command1.Enabled = False
'Set Notask flag to false
NoTask = False
'determine whether winscoket is closed
If Winsock1.State <> sckClosed Then
    'close it
    Winsock1.Close
    'release control
    'DoEvents
End If
'Set remote host by text
Winsock1.RemoteHost = Text1.Text
'Set remote port by text
Winsock1.RemotePort = CInt(Text2.Text)
'Display the information
xx "连接中..."
'Connect it
Winsock1.Connect

End Sub

Private Sub Command2_Click()
'exit program
Dim id As Long
'judge the status
If Command1.Enabled = False Then
'computing...
    'show a warning box
    id = MsgBox("计算还未结束", vbYesNo, "警告")
    'judge user operate
    If id = vbYes Then
        'exit
        End
    Else
       'other...
    End If
Else
'idle
    'exit
    End
End If

End Sub


Private Sub Form_Load()
'event when form is ready
'init begin pos
BeginPos = 0
'init endpos
EndPos = 0
'show the window
Form1.Show

End Sub

Private Sub Winsock1_Close()
'event when remote is closed
'Display the information
xx "连接已断开"
'judge if the winsocket is closed
If Winsock1.State <> sckClosed Then
'not closed
    'close it
    Winsock1.Close
End If
'judge by the auto-connect and notask flag
If Form1.Check1.Value = 1 And Not NoTask And Not js Then
'auto connect is true
    'judge if winsock is closed
    If Form1.Winsock1.State <> sckClosed Then
    'not closed
        'close it
        Form1.Winsock1.Close
    End If
    'Set remote host by text
    Form1.Winsock1.RemoteHost = Form1.Text1.Text
    'Set remote port by text
    Form1.Winsock1.RemotePort = CInt(Form1.Text2.Text)
    'Display the information
    xx "连接中..."
    'zht = 1
    'connect it
    Form1.Winsock1.Connect
Else
'auto connect is false
    'recover the button
    Command1.Enabled = True
End If

End Sub

Private Sub Winsock1_Connect()
Dim s As String
'event when connected
'display the information
xx "已连接"
'zht = 2
'judge the status
If BeginPos = 0 Then
'never complete a compution
    'REQUEST
    'send the packet
    Winsock1.SendData "REQUEST"
Else
'have a result
    'RETURN
    xx "上传数据"
    'get the packet data
    s = GetReturn
    'send the packet
    Winsock1.SendData s
End If

End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
'event when receive stream
Dim s$, s1$, s2$
Dim i As Long
'get buffer
Winsock1.GetData s$
xx s$
'judge packet meaning
If s$ = "NOTASK" Then
'no task to get
    'dislpay the information
    xx "没有可以分配的任务"
    'set notask flag to true
    NoTask = True
    'recover the command1 status
    Command1.Enabled = True
ElseIf Left$(s$, 4) = "TASK" Then
'a task is returned
    'get the split char position
    i = InStr(1, s$, " ")
    'judge if the packet is error
    If i = 0 Then
    'something is error
        'display the information
        xx "数据错误"
        'display the information
        xx "连接已断开"
        'judge if winsocket is closed
        If Winsock1.State <> sckClosed Then
        'not closed
            'close it
            Winsock1.Close
        End If
        'judge the auto-connect
        If Form1.Check1.Value = 1 Then
        'auto connect is true
            'judge if winsock is closed
            If Form1.Winsock1.State <> sckClosed Then
            'not closed
                'close it
                Form1.Winsock1.Close
            End If
            'Set remote host by text
            Form1.Winsock1.RemoteHost = Form1.Text1.Text
            'Set remote port by text
            Form1.Winsock1.RemotePort = CInt(Form1.Text2.Text)
            'Display the information
            xx "连接中..."
            'zht = 1
            'connect it
            Form1.Winsock1.Connect
        Else
        'auto connect is false
            'recover the button
            Command1.Enabled = True
        End If
        
    Else
    'position is right
        'get beginpos string
        s1$ = Mid$(s, 5, i - 5)
        'get endpos string
        s2$ = Mid$(s, i + 1)
        'convert to long
        BeginPos = CLng(s1)
        'convert to long
        EndPos = CLng(s2)
        'set begin time
        BeginTime = Now
        'set beginpos label
        Label7.Caption = CStr(BeginPos)
        'set endpos label
        Label8.Caption = CStr(EndPos)
        'set begintime label
        Label9.Caption = CStr(BeginTime)
        'set computing status is true
        js = True
        'begin to compute
        Call BBPstart(BeginPos, EndPos, 1)
    End If
Else
'something is error
    'display the information
    xx "数据错误"
    'display the information
    xx "连接已断开"
    'judge if winsocket is closed
    If Winsock1.State <> sckClosed Then
    'not closed
        'close it
        Winsock1.Close
    End If
    'judge the auto-connect
    If Form1.Check1.Value = 1 Then
    'auto connect is true
        'judge if winsock is closed
        If Form1.Winsock1.State <> sckClosed Then
        'not closed
            'close it
            Form1.Winsock1.Close
        End If
        'Set remote host by text
        Form1.Winsock1.RemoteHost = Form1.Text1.Text
        'Set remote port by text
        Form1.Winsock1.RemotePort = CInt(Form1.Text2.Text)
        'Display the information
        xx "连接中..."
        'zht = 1
        'connect it
        Form1.Winsock1.Connect
    Else
    'auto connect is false
        'recover the button
        Command1.Enabled = True
    End If
End If

End Sub

Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
'event when error is raised
Dim s As String
'copy error message
s = "Winsock错误:" + Description
'display the information
xx s
'judge if winsock is closed
If Form1.Winsock1.State <> sckClosed Then
'not closed
    'close it
    Form1.Winsock1.Close
End If
'recover the button
Command1.Enabled = True

End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -