{"id":2472,"date":"2025-04-02T08:00:00","date_gmt":"2025-04-02T00:00:00","guid":{"rendered":"https:\/\/www.wyrcad.com\/?p=2472"},"modified":"2025-04-10T08:38:24","modified_gmt":"2025-04-10T00:38:24","slug":"vb6-0-%e7%b1%bb%e6%a8%a1%e5%9d%97","status":"publish","type":"post","link":"https:\/\/www.wyrcad.com\/?p=2472","title":{"rendered":"\u5efa\u7acb\u7c7b\u6a21\u5757"},"content":{"rendered":"\n<p>&#8216; \u4e00\u3001\u7c7b\u6a21\u5757\u4ee3\u7801<\/p>\n\n\n\n<p>&#8216; \u7c7b\u540d: clsWire<br>&#8216; \u5305\u542b8\u4e2a\u53c2\u6570\u30012\u4e2a\u65b9\u6cd5\u30011\u4e2a\u4e8b\u4ef6<\/p>\n\n\n\n<p>Option Explicit<\/p>\n\n\n\n<p>&#8216; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br>&#8216; 1. \u5b9a\u4e49\u79c1\u6709\u53d8\u91cf\uff088\u4e2a\u53c2\u6570\uff09<br>&#8216; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br>Private pMaterial As String &#8216; \u6750\u6599<br>Private pLength As Double &#8216; \u957f\u5ea6<br>Private pDiameter As Double &#8216; \u76f4\u5f84<br>Private pVoltage As Double &#8216; \u7535\u538b<br>Private pCurrent As Double &#8216; \u7535\u6d41<br>Private pResistance As Double &#8216; \u7535\u963b<br>Private pTemperature As Double &#8216; \u6e29\u5ea6<br>Private pIsInsulated As Boolean &#8216; \u662f\u5426\u6709\u7edd\u7f18\u5c42<\/p>\n\n\n\n<p>&#8216; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br>&#8216; 2. \u5b9a\u4e49\u4e8b\u4ef6<br>&#8216; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br>Event StatusChanged(ByVal Message As String)<\/p>\n\n\n\n<p>&#8216; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br>&#8216; \u7c7b\u521d\u59cb\u5316\uff08\u8bbe\u7f6e\u9ed8\u8ba4\u503c\uff09<br>&#8216; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br>Private Sub Class_Initialize()<br>pMaterial = &#8220;Copper&#8221; &#8216; \u9ed8\u8ba4\u6750\u6599\u4e3a\u94dc<br>pLength = 0<br>pDiameter = 0<br>pVoltage = 0<br>pCurrent = 0<br>pResistance = 0<br>pTemperature = 25 &#8216; \u9ed8\u8ba4\u6e29\u5ea625\u00b0C<br>pIsInsulated = False<br>End Sub<\/p>\n\n\n\n<p>&#8216; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br>&#8216; \u5c5e\u6027\u5b9a\u4e49\uff088\u4e2a\u53c2\u6570\uff09<br>&#8216; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br>Public Property Get Material() As String<br>Material = pMaterial<br>End Property<br>Public Property Let Material(ByVal Value As String)<br>pMaterial = Value<br>End Property<\/p>\n\n\n\n<p>Public Property Get Length() As Double<br>Length = pLength<br>End Property<br>Public Property Let Length(ByVal Value As Double)<br>pLength = Value<br>End Property<\/p>\n\n\n\n<p>Public Property Get Diameter() As Double<br>Diameter = pDiameter<br>End Property<br>Public Property Let Diameter(ByVal Value As Double)<br>pDiameter = Value<br>End Property<\/p>\n\n\n\n<p>Public Property Get Voltage() As Double<br>Voltage = pVoltage<br>End Property<br>Public Property Let Voltage(ByVal Value As Double)<br>pVoltage = Value<br>End Property<\/p>\n\n\n\n<p>Public Property Get Current() As Double<br>Current = pCurrent<br>End Property<br>Public Property Let Current(ByVal Value As Double)<br>pCurrent = Value<br>End Property<\/p>\n\n\n\n<p>Public Property Get Resistance() As Double<br>Resistance = pResistance<br>End Property<br>Public Property Let Resistance(ByVal Value As Double)<br>pResistance = Value<br>End Property<\/p>\n\n\n\n<p>Public Property Get Temperature() As Double<br>Temperature = pTemperature<br>End Property<br>Public Property Let Temperature(ByVal Value As Double)<br>pTemperature = Value<br>End Property<\/p>\n\n\n\n<p>Public Property Get IsInsulated() As Boolean<br>IsInsulated = pIsInsulated<br>End Property<br>Public Property Let IsInsulated(ByVal Value As Boolean)<br>pIsInsulated = Value<br>End Property<\/p>\n\n\n\n<p>&#8216; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br>&#8216; \u65b9\u6cd51\uff1a\u8ba1\u7b97\u529f\u7387<br>&#8216; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br>Public Function CalculatePower() As Double<br>CalculatePower = pVoltage * pCurrent &#8216; P = V * I<br>RaiseEvent StatusChanged(&#8220;\u529f\u7387\u8ba1\u7b97\u5b8c\u6210: &#8221; &amp; CalculatePower &amp; &#8220;W&#8221;)<br>End Function<\/p>\n\n\n\n<p>&#8216; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br>&#8216; \u65b9\u6cd52\uff1a\u68c0\u67e5\u5b89\u5168\u6027<br>&#8216; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br>Public Sub CheckSafety()<br>Dim msg As String<br>If pTemperature &gt; 80 Then<br>msg = &#8220;\u8b66\u544a\uff1a\u6e29\u5ea6\u8fc7\u9ad8\uff08&#8221; &amp; pTemperature &amp; &#8220;\u00b0C\uff09\uff01&#8221;<br>ElseIf pCurrent &gt; 10 Then<br>msg = &#8220;\u8b66\u544a\uff1a\u7535\u6d41\u8d85\u8fc7\u5b89\u5168\u9608\u503c\uff01&#8221;<br>Else<br>msg = &#8220;\u7cfb\u7edf\u72b6\u6001\u6b63\u5e38&#8221;<br>End If<br>RaiseEvent StatusChanged(msg) &#8216; \u89e6\u53d1\u4e8b\u4ef6<br>End Sub<\/p>\n\n\n\n<p>&#8216; \u4e8c\u3001\u8c03\u7528<\/p>\n\n\n\n<p>&#8216; \u5728\u7a97\u4f53\u4ee3\u7801\u4e2d\uff1a<br>Dim WithEvents myWire As clsWire &#8216; \u5fc5\u987b\u4f7f\u7528 WithEvents \u6355\u83b7\u4e8b\u4ef6<\/p>\n\n\n\n<p>Private Sub Form_Load()<br>Set myWire = New clsWire<br>myWire.Voltage = 220<br>myWire.Current = 5<br>myWire.Temperature = 75<\/p>\n\n\n\n<p>&#8216; \u8c03\u7528\u65b9\u6cd5<br>Debug.Print &#8220;\u529f\u7387\uff1a&#8221; &amp; myWire.CalculatePower()<br>myWire.CheckSafety<\/p>\n\n\n\n<p>End Sub<\/p>\n\n\n\n<p>&#8216; \u5904\u7406\u4e8b\u4ef6<br>Private Sub myWire_StatusChanged(ByVal Message As String)<br>MsgBox Message, vbInformation, &#8220;\u5bfc\u7ebf\u72b6\u6001&#8221;<br>End Sub<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8216; \u4e00\u3001\u7c7b\u6a21\u5757\u4ee3\u7801 &#8216; \u7c7b\u540d: clsWire&#8216; \u5305\u542b8\u4e2a\u53c2\u6570\u30012\u4e2a\u65b9\u6cd5\u3001 &hellip; <a href=\"https:\/\/www.wyrcad.com\/?p=2472\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c\u5efa\u7acb\u7c7b\u6a21\u5757\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[24,27,17],"class_list":["post-2472","post","type-post","status-publish","format-standard","hentry","category-bianchengyuandi","tag-vb","tag-peixun","tag-biancheng"],"_links":{"self":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts\/2472","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2472"}],"version-history":[{"count":5,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts\/2472\/revisions"}],"predecessor-version":[{"id":2527,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=\/wp\/v2\/posts\/2472\/revisions\/2527"}],"wp:attachment":[{"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2472"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2472"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wyrcad.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}