从服务器到客户端存储变量值
Store Variable value from server to client
我正在使用此代码连接到服务器。
'客户端连接代码
sockMain.RemoteHost = 192.168.1.125
sockMain.RemotePort = 12345
sockMain.Connect
'向客户端发送消息的服务器端代码
sockMain.SendData txtSend.text
现在,如果我写 :: a="127",并将它从服务器发送到客户端,那么这条消息将显示在客户端的文本框中,现在我该如何使用这条消息,a="127 " 存储变量值 ?
您不能按照描述的方式在运行时在已编译的 VB6 应用程序中按字面意思创建新的命名变量。但是,您当然可以提取文本框中值的 数字部分 并将该值 分配 到应用程序中的局部变量。
如果您想捕获文本框中值的数字部分,并且您知道文本格式将始终采用 "a=somenumber," 形式,您可以去掉前两个字符以消除 "a=" 部分,然后在剩余的字符串上使用 VB `Val' 函数来捕获数值:
' Generalized example for pulling integer portion from
' a textbox of the form 'a=12345'; amend as appropriate. Untested.
Dim a as integer
Dim receivedData as String
' Assuming txtBox1 as the name of the textbox in the client
receivedData = txtBox1.Text
receievedData = mid$(value,3)
a = Val(receivedData)
`
我正在使用此代码连接到服务器。 '客户端连接代码
sockMain.RemoteHost = 192.168.1.125
sockMain.RemotePort = 12345
sockMain.Connect
'向客户端发送消息的服务器端代码
sockMain.SendData txtSend.text
现在,如果我写 :: a="127",并将它从服务器发送到客户端,那么这条消息将显示在客户端的文本框中,现在我该如何使用这条消息,a="127 " 存储变量值 ?
您不能按照描述的方式在运行时在已编译的 VB6 应用程序中按字面意思创建新的命名变量。但是,您当然可以提取文本框中值的 数字部分 并将该值 分配 到应用程序中的局部变量。
如果您想捕获文本框中值的数字部分,并且您知道文本格式将始终采用 "a=somenumber," 形式,您可以去掉前两个字符以消除 "a=" 部分,然后在剩余的字符串上使用 VB `Val' 函数来捕获数值:
' Generalized example for pulling integer portion from
' a textbox of the form 'a=12345'; amend as appropriate. Untested.
Dim a as integer
Dim receivedData as String
' Assuming txtBox1 as the name of the textbox in the client
receivedData = txtBox1.Text
receievedData = mid$(value,3)
a = Val(receivedData)
`