home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1999 January / pcwk_01_1999.iso / Wtestowe / Vistdstd / Install / Data.Z / Network.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-09-03  |  5.4 KB  |  136 lines

  1. VERSION 4.00
  2. Begin VB.Form Network 
  3.    Appearance      =   0  'Flat
  4.    BackColor       =   &H80000005&
  5.    Caption         =   "Network Diagram Example"
  6.    ClientHeight    =   2280
  7.    ClientLeft      =   1095
  8.    ClientTop       =   1485
  9.    ClientWidth     =   7365
  10.    BeginProperty Font 
  11.       name            =   "MS Sans Serif"
  12.       charset         =   0
  13.       weight          =   700
  14.       size            =   8.25
  15.       underline       =   0   'False
  16.       italic          =   0   'False
  17.       strikethrough   =   0   'False
  18.    EndProperty
  19.    ForeColor       =   &H80000008&
  20.    Height          =   2685
  21.    Left            =   1035
  22.    LinkTopic       =   "Form1"
  23.    ScaleHeight     =   2280
  24.    ScaleWidth      =   7365
  25.    Top             =   1140
  26.    Width           =   7485
  27.    Begin VB.Label Label1 
  28.       Appearance      =   0  'Flat
  29.       BackColor       =   &H80000005&
  30.       Caption         =   "The Form_Load procedure of this form creates a Visio network diagram from a database."
  31.       ForeColor       =   &H80000008&
  32.       Height          =   855
  33.       Left            =   1560
  34.       TabIndex        =   0
  35.       Top             =   480
  36.       Width           =   4215
  37.    End
  38. Attribute VB_Name = "Network"
  39. Attribute VB_Creatable = False
  40. Attribute VB_Exposed = False
  41. ' -----------------------------------------------------------------------------
  42. ' Copyright (C) 1996 Visio Corporation. All rights reserved.
  43. ' You have a royalty-free right to use, modify, reproduce and distribute
  44. ' the Sample Application Files (and/or any modified version) in any way
  45. ' you find useful, provided that you agree that Visio has no warranty,
  46. ' obligations or liability for any Sample Application Files.
  47. ' -----------------------------------------------------------------------------
  48. Option Explicit
  49. Private Sub Form_Load()
  50. ' This example demonstrates generating a Visio drawing from the data contained
  51. ' in a database.
  52. ' Declare database variables
  53. Dim NetBase As DAO.Database
  54. Dim NetInfo As DAO.Recordset
  55. ' Declare Visio variables
  56. Dim Visio As Visio.Application
  57. Dim NetDiagram As Visio.Page
  58. Dim NetStencil As Visio.Document
  59. Dim Master As Visio.Master
  60. Dim Shape As Visio.Shape
  61. Dim TextShape As Visio.Shape
  62. Dim Ethernet As Visio.Shape
  63. Dim ControlCell As Visio.Cell
  64. Dim ConnectCell As Visio.Cell
  65. Dim Chars As Visio.Characters
  66. ' Declare miscellaneous variables
  67. Dim Digit As Integer
  68. Dim NodeType As String
  69. Dim Label As String
  70. Dim Index As Integer
  71. Dim XPos As Double
  72.     ' Open the database and get the NetInfo table
  73.     Set NetBase = OpenDatabase(App.Path & "\network.mdb", True, True)
  74.     Set NetInfo = NetBase.OpenRecordset("NetInfo")
  75.     ' Get a Visio Object that is already running.
  76.     On Error Resume Next
  77.     Set Visio = GetObject(, "Visio.Application")
  78.     If Err Then
  79.         MsgBox "Launch Visio First"
  80.         End
  81.     End If
  82.     On Error GoTo 0
  83.     ' Open the NetDB template and retrieve the stencil
  84.     Set NetDiagram = Visio.Documents.Add("VB Solutions.vst").Pages(1)
  85.     Set NetStencil = Visio.Documents("VB Solutions.vss")
  86.     ' Set the size of the Page. We have to access cells in the special
  87.     ' shape "thePage" where page attributes are stored.
  88.     NetDiagram.Shapes("thePage").Cells("PageWidth").Formula = 8
  89.     NetDiagram.Shapes("thePage").Cells("PageHeight").Formula = 2.5
  90.     ' Drop the Ethernet master onto the page.
  91.     Set Master = NetStencil.Masters("EtherNet")
  92.     Set Ethernet = NetDiagram.Drop(Master, 1, 1)
  93.     ' Extend the Shape to fill up the whole page.
  94.     Ethernet.SetBegin 0.5, 2
  95.     Ethernet.SetEnd 7.5, 2
  96.     ' Loop over each record in the database.
  97.     NetInfo.MoveFirst
  98.     XPos = 1
  99.     Digit = Asc("1")
  100.     While Not NetInfo.EOF
  101.         Visio.ScreenUpdating = False
  102.         ' Drop a node symbol on the page for this database record.
  103.         NodeType = NetInfo.Fields("Node")
  104.         Set Master = NetStencil.Masters(NodeType)
  105.         Set Shape = NetDiagram.Drop(Master, XPos, 0.875)
  106.         XPos = XPos + 1.5
  107.         ' Add a label to each node symbol in the diagram.
  108.         Label = NetInfo.Fields("Name")
  109.         Label = Label & Chr$(13) & Chr$(10)
  110.         Label = Label & NetInfo.Fields("Dept")
  111.         Shape.Text = Label
  112.         ' Fill in the Data1 Field in each shape from the database spec field.
  113.         ' This information is available in the FormatSpecial dialog.
  114.         Shape.Data1 = NetInfo.Fields("Spec")
  115.         ' Connect the network lines to the computers. The EtherNet shape has
  116.         ' control handles that can be glued to the connection points on the
  117.         ' computer shapes. The top connection point on each node is
  118.         ' always the 5'th one.
  119.         Set ControlCell = Ethernet.Cells("Controls.X" & Chr$(Digit))
  120.         Digit = Digit + 1
  121.         Set ConnectCell = Shape.Cells("Connections.X5")
  122.         ControlCell.GlueTo ConnectCell
  123.         ' Embolden the first line of the text on each shape. Since this shape
  124.         ' is a group, dive down and get the shape that the text is really on.
  125.         Index = Shape.Shapes.Count
  126.         Set TextShape = Shape.Shapes(Index)
  127.         Set Chars = TextShape.Characters
  128.         Chars.End = InStr(TextShape.Text, Chr$(13)) - 1
  129.         Chars.CharProps(visCharacterStyle) = visBold
  130.         Visio.ScreenUpdating = True
  131.         NetInfo.MoveNext
  132.     Wend
  133.     NetInfo.Close
  134.     NetBase.Close
  135. End Sub
  136.