| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 803 人关注过本帖
标题:控件封装问题
只看楼主 加入收藏
yyttdd63
Rank: 1
等 级:新手上路
帖 子:65
专家分:5
注 册:2008-8-29
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:8 
控件封装问题
Public ip As String
Public port As String
。。。。。。。。。。。。

'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
'
'  本块作用:属性
'
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
'控件状态
'0未连接,1连接,2异常
Public Property Get State() As Integer
    Select Case winclient.State
        Case 0
            State = 0
        Case 7
            State = 1
        Case Else
            State = 2
    End Select
End Property


'服务器IP地址
Public Property Get ServerIP() As String
    ServerIP = winclient.RemoteHost
End Property

Public Property Let ServerIP(ByVal vNewValue As String)
    If State = 0 Then winclient.RemoteHost = vNewValue
End Property

'服务器端口
Public Property Get ServerProt() As Long
     ServerProt = winclient.RemotePort
End Property

Public Property Let ServerProt(ByVal vNewValue As Long)
    If State = 0 Then winclient.RemotePort = vNewValue
End Property


Public Sub start(MDBSTR As String, LOCALPROT As String)
     ip = MDBSTR
     port = LOCALPROT
    '  winclient.RemoteHost = ip
    '  winclient.RemotePort = port
End Sub
'控件自身事件
'-----------------------------------------------------------------------

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
ServerIP = PropBag.ReadProperty("ServerIP", "")
ServerProt = PropBag.ReadProperty("ServerProt", 0)

End Sub
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
PropBag.WriteProperty "ServerIP", ServerIP, ""
PropBag.WriteProperty "ServerProt", ServerProt, 0

End Sub
Private Sub UserControl_Resize()
UserControl.Width = 40 * 15
UserControl.Height = 40 * 15
End Sub
封装的控件部分内容

新建窗体中调用
Private Sub Form_Load()
   netdataclent1.start "127.0.0.1", "8888"
   
End Sub

ip  port 无内容
不知是那里写错了
请高手指教
谢谢
搜索更多相关主题的帖子: 服务器 IP地址 
2011-05-30 01:03
记叙、继续
Rank: 4
等 级:业余侠客
帖 子:56
专家分:226
注 册:2011-5-17
收藏
得分:10 
额,你在编译时候出错在那里?
2011-05-30 01:55
yyttdd63
Rank: 1
等 级:新手上路
帖 子:65
专家分:5
注 册:2008-8-29
收藏
得分:0 
加一个form1窗体,添加控件,窗体中调用
Private Sub Form_Load()
   netdataclent1.start "127.0.0.1", "8888"
   
End Sub

msgbox  ip  port 无内容

不知是控件那里写错了
请高手指教
谢谢
2011-05-30 08:07
yyttdd63
Rank: 1
等 级:新手上路
帖 子:65
专家分:5
注 册:2008-8-29
收藏
得分:0 
在线等啊
2011-05-30 08:16
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4947
专家分:30084
注 册:2008-10-15
收藏
得分:0 
msgbox  netdataclent1.ip & ":" &  netdataclent1.port

也没内容??

授人于鱼,不如授人于渔
早已停用QQ了
2011-05-30 09:00
yyttdd63
Rank: 1
等 级:新手上路
帖 子:65
专家分:5
注 册:2008-8-29
收藏
得分:0 
有内容,但无法发送字符,问题还是存在
2011-05-30 10:06
wube
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:23
帖 子:1820
专家分:3681
注 册:2011-3-24
收藏
得分:0 
程序代码:
Option Explicit
'Default Property Values:
Const m_def_State = 0
Const m_def_ServerIP = "0"
Const m_def_ServerProt = "0"
'Property Variables:
Dim m_State As Integer
Dim m_ServerIP As String
Dim m_ServerProt As String

'警告! 切勿移除或修改以下的注解行!
'MemberInfo=7,0,0,0
Public Property Get State() As Integer
    State = m_State
End Property

Public Property Let State(ByVal New_State As Integer)
    m_State = New_State
    PropertyChanged "State"
End Property

'警告! 切勿移除或修改以下的注解行!
'MemberInfo=13,0,0,0
Public Property Get ServerIP() As String
    ServerIP = m_ServerIP
End Property

Public Property Let ServerIP(ByVal New_ServerIP As String)
    m_ServerIP = New_ServerIP
    PropertyChanged "ServerIP"
End Property

'警告! 切勿移除或修改以下的注解行!
'MemberInfo=13,0,0,0
Public Property Get ServerProt() As String
    ServerProt = m_ServerProt
End Property

Public Property Let ServerProt(ByVal New_ServerProt As String)
    m_ServerProt = New_ServerProt
    PropertyChanged "ServerProt"
End Property

'警告! 切勿移除或修改以下的注解行!
'MemberInfo=13
Public Function start(MDBSTR As String, LOCALPROT As String) As String
    Select Case Me.State    '你Select的条件是啥我看不懂~
        Case 0
            State = "00000"
        Case 7
            State = "11111"
        Case Else
            State = "22222"
    End Select
    start = State        '之后又不回传值~我更看不懂你要做啥~
End Function

'初始化使用者控制项的属性
Private Sub UserControl_InitProperties()
    m_State = m_def_State
    m_ServerIP = m_def_ServerIP
    m_ServerProt = m_def_ServerProt
End Sub

'由储存区载入属性值
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
    m_State = PropBag.ReadProperty("State", m_def_State)
    m_ServerIP = PropBag.ReadProperty("ServerIP", m_def_ServerIP)
    m_ServerProt = PropBag.ReadProperty("ServerProt", m_def_ServerProt)
End Sub

'将属性值写回储存区
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
    Call PropBag.WriteProperty("State", m_State, m_def_State)
    Call PropBag.WriteProperty("ServerIP", m_ServerIP, m_def_ServerIP)
    Call PropBag.WriteProperty("ServerProt", m_ServerProt, m_def_ServerProt)
End Sub


这样可以运行~但是意义为何?你丢进去的IP和Port都没用到~丢心酸的吗?
你源码的.RemoteHost定义在哪?winclient又是从哪冒出来的?

不要選我當版主
2011-05-30 23:11
yyttdd63
Rank: 1
等 级:新手上路
帖 子:65
专家分:5
注 册:2008-8-29
收藏
得分:0 
谢谢
2011-06-14 00:52
快速回复:控件封装问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.058516 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved