刚才看了一个实例,也是这样,差不多的 可是我看另外一个实例怎么没有类似的代码呢? Private Sub cmdAddServer_Click() Dim nServerHandle As Long Dim sServerHandle As String Dim TheListItem As ListItem Dim sServerName As String Dim sNetworkNode As String ' Display the Add Server Dialog nServerHandle = TheServers.DialogAddServer(sServerName, sNetworkNode) If nServerHandle > 0 Then ' Add the server to the Servers listview sServerHandle = CStr(nServerHandle) Set TheListItem = listviewServers.ListItems.Add(, , sServerName) TheListItem.Tag = nServerHandle TheListItem.EnsureVisible TheListItem.Selected = True ElseIf nServerHandle < 0 Then MsgBox ("There was an error while adding the server: " & Hex(nServerHandle)) End IfEnd Sub 请问这段代码怎么创建的新窗体呢??
TheServers.DialogAddServer这个方法.(他不是VB中自带的标准方法.)
不是的,这是函数声明 Public Function DialogAddServer(sServerName As String, sNetworkNode As String) As Long Dim ServerObject As CServer DialogAddServer = 0 ' Check for maximum servers If m_NextServerHandle > 15 Then MsgBox ("The maximum number of servers has been reached.") Exit Function End If ' Call DialogCreateServer to display the Add Server dialog. It will return a ' CServer object which we do not need since the collection will create ' a CServer object when AddServer is called. Set ServerObject = DialogCreateServer(sServerName, sNetworkNode) If Not ServerObject Is Nothing Then Set ServerObject = Nothing DialogAddServer = AddServer(sServerName, sNetworkNode) End IfEnd Function 没有创建窗体的代码啊
Public Function DialogCreateServer(sServerName As String, sNetworkNode As String) As CServer Set DialogCreateServer = Nothing ' Initialize and show the AddServer dialog Load frmAddServer frmAddServer.Show (1) If frmAddServer.m_bOK Then ' Fill in all of the output variables sServerName = frmAddServer.m_sProgId sNetworkNode = frmAddServer.m_sNetworkNode ' Create a server object to pass back Dim ServerObject As CServer Set ServerObject = New CServer Set DialogCreateServer = ServerObject End If Unload frmAddServerEnd Function 晕,原来在这里
Dim X As Long, Y As Long, mCount As Long, myInfo() As String Dim TempCount(1 To 4) As Long, NowObj As ListItem For X = 1 To 4 If Combo20(X - 1).List(Combo20(X - 1).ListIndex) = "奇数" Then TempCount(X) = 1 Else TempCount(X) = 0 End If Next X For X = 1 To ListView1.ListItems.Count mCount = 0 On Error Resume Next Set NowObj = ListView1.ListItems.Item(X) If Err.Number <> 0 Then Set NowObj = Nothing Err.Clear Exit For End If If NowObj Is Nothing <> True Then For Y = 1 To 4 myInfo = Split(NowObj.Text, ",") If (Int(myInfo(Y - 1)) + Int(myInfo(Y))) Mod 2 <> TempCount(Y) Then mCount = 1 Exit For End If Next Y If mCount = 1 Then ListView1.ListItems.Remove X: X = X - 1 End If Next X
fmBackup.Show
可是我看另外一个实例怎么没有类似的代码呢?
Private Sub cmdAddServer_Click()
Dim nServerHandle As Long
Dim sServerHandle As String
Dim TheListItem As ListItem
Dim sServerName As String
Dim sNetworkNode As String ' Display the Add Server Dialog
nServerHandle = TheServers.DialogAddServer(sServerName, sNetworkNode)
If nServerHandle > 0 Then
' Add the server to the Servers listview
sServerHandle = CStr(nServerHandle)
Set TheListItem = listviewServers.ListItems.Add(, , sServerName)
TheListItem.Tag = nServerHandle
TheListItem.EnsureVisible
TheListItem.Selected = True
ElseIf nServerHandle < 0 Then
MsgBox ("There was an error while adding the server: " & Hex(nServerHandle))
End IfEnd Sub
请问这段代码怎么创建的新窗体呢??
Public Function DialogAddServer(sServerName As String, sNetworkNode As String) As Long
Dim ServerObject As CServer DialogAddServer = 0 ' Check for maximum servers
If m_NextServerHandle > 15 Then
MsgBox ("The maximum number of servers has been reached.")
Exit Function
End If ' Call DialogCreateServer to display the Add Server dialog. It will return a
' CServer object which we do not need since the collection will create
' a CServer object when AddServer is called.
Set ServerObject = DialogCreateServer(sServerName, sNetworkNode)
If Not ServerObject Is Nothing Then
Set ServerObject = Nothing
DialogAddServer = AddServer(sServerName, sNetworkNode)
End IfEnd Function
没有创建窗体的代码啊
Load frmAddServer
frmAddServer.Show (1) If frmAddServer.m_bOK Then
' Fill in all of the output variables
sServerName = frmAddServer.m_sProgId
sNetworkNode = frmAddServer.m_sNetworkNode ' Create a server object to pass back
Dim ServerObject As CServer
Set ServerObject = New CServer
Set DialogCreateServer = ServerObject
End If Unload frmAddServerEnd Function
晕,原来在这里
这个是初级学员问得,解释这么复杂干吗?
load frm
frm.show
简直是自找麻烦。明明添加一个窗体就可以完的事,你要用代码实现创建窗体。
既然你习惯了C的概念,那你为什么不去用C来写程序,用VB这么做只有一个词形容,“多余”
我没有要用c的方法来写vb的意思,用vb当然用地道的vb
再问一下Load Form这一语句的作用,没有它会有什么区别?
我记得我玩VC的时候有人和我说,用VC就要有VC的概念,不要老想着用VB的概念来用VC,那是行不通的。
就好像VC里要用Com组件,就必须初始化COM,然后再创建Com组件,不然没法用,但VB要只用创建组建就可以了。
如果要在VB里用 HRESULT hr = S_OK;
if FAILED(CoInitialize(NULL))
{
CoUninitialize();
hr = E_UNEXPECTED;
}
return hr;来初始化COM不是多余吗?
Dim X As Long, Y As Long, mCount As Long, myInfo() As String
Dim TempCount(1 To 4) As Long, NowObj As ListItem
For X = 1 To 4
If Combo20(X - 1).List(Combo20(X - 1).ListIndex) = "奇数" Then
TempCount(X) = 1
Else
TempCount(X) = 0
End If
Next X
For X = 1 To ListView1.ListItems.Count
mCount = 0
On Error Resume Next
Set NowObj = ListView1.ListItems.Item(X)
If Err.Number <> 0 Then
Set NowObj = Nothing
Err.Clear
Exit For
End If
If NowObj Is Nothing <> True Then
For Y = 1 To 4
myInfo = Split(NowObj.Text, ",")
If (Int(myInfo(Y - 1)) + Int(myInfo(Y))) Mod 2 <> TempCount(Y) Then
mCount = 1
Exit For
End If
Next Y
If mCount = 1 Then ListView1.ListItems.Remove X: X = X - 1
End If
Next X