vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
SEPA-Dateien erstellen inkl. IBAN-, BLZ-/Kontonummernprüfung  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2025
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

Fortgeschrittene Programmierung
Trendbeispiel 
Autor: Wöllmi
Datum: 05.11.02 07:34

Hi,

nach langer Suche habe ich im Web folgendes Bsp. gefunden und
für meine Belange sehr gut nutzen können.

Anbei das Bsp. im Urzustand.

Bitte lege Dir mit einem Texteditor folgende Dateien an und kopiere den
Inhalt in diese. Dann kann das PRJ getestet werden.

Das Ergebnis ist eine Form, auf der sich 4 Pictureboxen befinden in denen
Diagramme als Trend gezeichnet werden. Ein Timer sorgt für die Updateraten.
Jedes der Diagramme stellt eine neue Variante dar. (Linie, Punkte, mit Gitter oder ohne)

In diesem Bsp. werden feste Funktionen verwendet und auch nur ein Graph je Trend
dargestellt. Wie gesagt es läßt sich gut ausbauen, wenn man sich mit dem Prinzip
vertraut gemacht hat. (z.B. Freie Farbgestaltung, mehrere Graphen je Trend, freie
Updateraten uvm. der Fantasie sind keine grenzen gesetzt

Viel Glück:
Hier der Code:
Datei 1: "Module_main.bas"
Attribute VB_Name = "Module_main"
Public linediagram As New Cls_linediagram
Datei 2: "Cls_linediagram.cls"
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "Cls_diagram"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Public HorzSplits As Long
Public VertSplits As Long
Public Max As Single 'Max value
 
Private ValueArray() As Single 'Array to hold values
Private mem_LineColor As Long
Private mem_GridColor As Long
Private mem_ShowGrid As Boolean
Private mem_pBox As PictureBox
Private mem_pBoxHeight As Long
Private mem_pBoxWidth As Long
Private mem_movingGrid As Boolean
Private StartPosition As Long 'Needed to not to display first zero values when 
' starting a new diagram
Private GridPosition As Long
 
Public Enum ENUM_DIAGRAMTYPE
    TYPE_LINE = 0
    TYPE_POINT = 1
End Enum
Public DiagramType As ENUM_DIAGRAMTYPE 'Type of diagram (line or point)
 
Const const_tolerance = 0.0001 'Used to fix last line tolerance problem in some 
' cases
 
Public Function InitDiagram(pBox As PictureBox, LineColor As Long, ShowGrid As _
  Boolean, Optional GridColor As Variant, Optional MovingGrid As Variant)
 
    pBox.ScaleMode = vbPixels 'Set pixel scale mode
 
    mem_LineColor = LineColor
    mem_ShowGrid = ShowGrid
 
    mem_pBoxHeight = pBox.ScaleHeight
    mem_pBoxWidth = pBox.ScaleWidth
 
    'If user didn't give a grid color, we are using default (dark green) color
    If IsMissing(GridColor) Then
        mem_GridColor = RGB(0, 130, 0) 'Dark green
    Else:
        mem_GridColor = GridColor
    End If
 
    'If user didn't give a movingGrid parameter, we are using default (off)
    If IsMissing(MovingGrid) Then
        mem_movingGrid = False
    Else:
        mem_movingGrid = MovingGrid
    End If
 
    Set mem_pBox = pBox 'Save picturebox, so we dont need to ask it again
 
    'Allocate array to hold all diagram values (value per pixel)
    ReDim ValueArray(mem_pBoxWidth - 1)
 
    StartPosition = mem_pBoxWidth - 1
 
    GridPosition = 0
 
End Function
Public Sub AddValue(value As Single)
 
    Dim l As Long
 
    'Check if InitDiagram has not been executed yet
    If mem_pBox Is Nothing Then
        'Failed! (exit function)
        Exit Sub
    End If
 
    'Move all values from array one position lower
    For l = 1 To mem_pBoxWidth - 1
        ValueArray(l - 1) = ValueArray(l)
    Next
 
    'Max can't be 0 or smaller
    If Max <= 0 Then Max = 1
 
    'Add new value to the last element of array
    ValueArray(l - 1) = mem_pBoxHeight - ((value / Max) * mem_pBoxHeight)
 
    If StartPosition >= 1 Then StartPosition = StartPosition - 1
 
    GridPosition = GridPosition - 1
End Sub
Public Sub RePaint()
 
    Dim x As Single
    Dim y As Single
    Dim l As Long
 
    'Check if InitDiagram has not been executed yet
    If mem_pBox Is Nothing Then
        'Failed! (exit sub)
        Exit Sub
    End If
 
    'Create background image
    'First clear hole picture box, then draw grid if set, then draw diagram
 
    mem_pBox.Cls 'Clear picturebox
 
    'Draw grid if set
    If (mem_ShowGrid) Then
        mem_pBox.ForeColor = mem_GridColor
 
        'Draw vertical lines with or without using gridposition
        If (mem_movingGrid) Then
            For x = GridPosition To mem_pBoxWidth - 1 Step ((mem_pBoxWidth - 1) _
              / (VertSplits + 1)) - const_tolerance
                mem_pBox.Line (x, 0)-(x, mem_pBoxHeight)
            Next
        Else:
            For x = 0 To mem_pBoxWidth - 1 Step ((mem_pBoxWidth - 1) / ( _
              VertSplits + 1)) - const_tolerance
                mem_pBox.Line (x, 0)-(x, mem_pBoxHeight)
            Next
        End If
 
        For y = 0 To mem_pBoxHeight - 1 Step ((mem_pBoxHeight - 1) / ( _
          HorzSplits + 1)) - const_tolerance
            mem_pBox.Line (0, y)-(mem_pBoxWidth, y)
        Next
        'Reset gridposition, when first line is not visible anymore
        If GridPosition <= -Int((mem_pBoxWidth - 1 / (HorzSplits + 1))) Then
            GridPosition = 0
        End If
    End If
 
    'Draw line diagram only if theres 2 or more values defined
    If StartPosition <= mem_pBoxWidth - 1 Then
        mem_pBox.ForeColor = mem_LineColor
 
        Select Case DiagramType
 
            Case TYPE_LINE
            For l = StartPosition + 1 To mem_pBoxWidth - 2
                mem_pBox.Line (l, ValueArray(l))-(l + 1, ValueArray(l + 1))
            Next
 
            Case TYPE_POINT
            For l = StartPosition + 1 To mem_pBoxWidth - 2
                mem_pBox.PSet (l + 1, ValueArray(l + 1))
            Next
        End Select
 
    End If
 
End Sub
Datei 3: "Form_main.frm"
VERSION 5.00
Begin VB.Form Form_main 
   Caption         =   "Pure VB diagram monitors"
   ClientHeight    =   5175
   ClientLeft      =   1800
   ClientTop       =   1965
   ClientWidth     =   6090
   LinkTopic       =   "Form1"
   ScaleHeight     =   5175
   ScaleWidth      =   6090
   Begin VB.Frame Frame2 
      Caption         =   "Point"
      Height          =   2235
      Left            =   120
      TabIndex        =   3
      Top             =   2400
      Width           =   5835
      Begin VB.PictureBox Picture_point2 
         BackColor       =   &H00000000&
         BorderStyle     =   0  'None
         CausesValidation=   0   'False
         ClipControls    =   0   'False
         Height          =   1695
         Left            =   2940
         ScaleHeight     =   113
         ScaleMode       =   3  'Pixel
         ScaleWidth      =   181
         TabIndex        =   6
         Top             =   300
         Width           =   2715
      End
      Begin VB.PictureBox Picture_point 
         BackColor       =   &H00000000&
         BorderStyle     =   0  'None
         CausesValidation=   0   'False
         ClipControls    =   0   'False
         Height          =   1695
         Left            =   180
         ScaleHeight     =   113
         ScaleMode       =   3  'Pixel
         ScaleWidth      =   181
         TabIndex        =   4
         Top             =   300
         Width           =   2715
      End
   End
   Begin VB.Timer Timer1 
      Interval        =   500
      Left            =   3720
      Top             =   4680
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Start"
      Height          =   315
      Left            =   4380
      TabIndex        =   2
      Top             =   4740
      Width           =   1575
   End
   Begin VB.Frame Frame1 
      Caption         =   "Line"
      Height          =   2235
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   5835
      Begin VB.PictureBox Picture_line2 
         BackColor       =   &H00000000&
         BorderStyle     =   0  'None
         CausesValidation=   0   'False
         ClipControls    =   0   'False
         Height          =   1695
         Left            =   2940
         ScaleHeight     =   113
         ScaleMode       =   3  'Pixel
         ScaleWidth      =   181
         TabIndex        =   5
         Top             =   300
         Width           =   2715
      End
      Begin VB.PictureBox Picture_line 
         BackColor       =   &H00000000&
         BorderStyle     =   0  'None
         CausesValidation=   0   'False
         ClipControls    =   0   'False
         Height          =   1695
         Left            =   180
         ScaleHeight     =   113
         ScaleMode       =   3  'Pixel
         ScaleWidth      =   181
         TabIndex        =   1
         Top             =   300
         Width           =   2715
      End
   End
End
Attribute VB_Name = "Form_main"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
''''''''''''''''''''''''''''''''''''
'Simple diagrams
'Just add new reference to cls_diagram!
'By Sami Riihilahti
'Free to use at any case!
''''''''''''''''''''''''''''''''''''
 
Public linediagram As New Cls_diagram
Public linediagram2 As New Cls_diagram
Public pointdiagram As New Cls_diagram
Public pointdiagram2 As New Cls_diagram
Public tancounter As Single 'We are using this just to create tan diagrams
 
Private Sub Command1_Click()
 
    'Create all 4 diagrams. See what options we have when calling .InitDiagram()
 
    '.InitDiagram picturebox, linecolor, showgrid, gridcolor, movinggrid
    'picturebox = the picturebox in which to add the diagram
    'linecolor = line color
    'showgrid = grid ON/OFF
    'gridcolor = [optional] grid color (default=dark green)
    'movinggrid = [optional] boolean true/false of moving grid (default=false)
 
    With linediagram
        .InitDiagram Picture_line, RGB(0, 255, 0), True
        .Max = 10
        .HorzSplits = 9
        .VertSplits = 9
        .DiagramType = TYPE_LINE
        .RePaint
    End With
    With pointdiagram
        .InitDiagram Picture_point, RGB(0, 255, 0), True
        .Max = 20
        .HorzSplits = 9
        .VertSplits = 9
        .DiagramType = TYPE_POINT
        .RePaint
    End With
    With linediagram2
        .InitDiagram Picture_line2, RGB(255, 255, 0), True, , True
        .Max = 100
        .HorzSplits = 9
        .VertSplits = 9
        .DiagramType = TYPE_LINE
        .RePaint
    End With
    With pointdiagram2
        .InitDiagram Picture_point2, RGB(0, 255, 255), True, RGB(100, 0, 0), _
          True
        .Max = 10
        .HorzSplits = 9
        .VertSplits = 9
        .DiagramType = TYPE_POINT
        .RePaint
    End With
 
End Sub
 
Private Sub Picture_line_Paint()
    linediagram.RePaint
End Sub
 
Private Sub Picture_line2_Click()
    linediagram2.RePaint
End Sub
 
Private Sub Picture_point_Paint()
    pointdiagram.RePaint
End Sub
 
Private Sub Picture_point2_Click()
    pointdiagram.RePaint
End Sub
 
Private Sub Timer1_Timer()
 
    'Just randomize a new value in this sample
    Dim value As Single
    tancounter = tancounter + 0.1
    value = Tan(tancounter) + 2
 
    linediagram.AddValue value
    linediagram2.AddValue value
    pointdiagram.AddValue value
    pointdiagram2.AddValue value
    linediagram.RePaint
    linediagram2.RePaint
    pointdiagram.RePaint
    pointdiagram2.RePaint
End Sub
Datei 4: "Diagrams.vbp"
Type=Exe
Form=Form_main.frm
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\WINNT\System32\STD_
  OLE2.TLB#OLE Automation
Class=Cls_diagram; Cls_linediagram.cls
Object={831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0; MSCOMCTL.OCX
IconForm="Form_main"
Startup="Form_main"
HelpFile=""
Title="Diagrams"
ExeName32="Diagrams.exe"
Command32=""
Name="VBDiagrams"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="HomeCenter"
VersionFileDescription="Pure VB diagrams"
VersionProductName="Pure VB diagrams"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1
DebugStartupOption=0
 
[MS Transaction Server]
AutoRefresh=1
Datei 5: "Diagrams.vbw"
Form_main = 129, 103, 633, 679, , 0, 0, 0, 0, C
Cls_diagram = 129, 103, 776, 679,
Das wars.
Sollte es nicht klappen, so kann ich Dir dieses kleine Projekt auch mailen.
Wie gesagt ich habe dies als Anregung verwendet und unter VB4/16, VB6
erfolgreich genutzt.

MfG

Tschaui
Woellmi

alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
Graph erstellen95aga04.11.02 17:50
Re: Graph erstellen493IsoLizer05.11.02 00:38
Trendbeispiel541Wöllmi05.11.02 07:34

Sie sind nicht angemeldet!
Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.

Einloggen  |  Neu registrieren

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2025 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel