Solved

Picture Box graphing with 1 value

Posted on 2000-03-13
8
175 Views
Last Modified: 2010-05-02
Hi  All,
I need help with the code to chart with a picture box control,  i have an  app  that has a textbox that is updated in real time with the temperature...I now  want  a real time graph to enhance it.  I would  just  like  a single  line  plot  to  show   the trends  of  the  values  that  have  come through  the textbox. I think updating the line once per minute would be sufficient, and  Can it be coded  so the old  data  just  "drops off" as the new data is added? I am not worried  about saving the  data  at  this  point.   I would  like  to hear  all   comments,  and  would  really  like  some  code  snippets  to assist  me  with  this.   Also,   If  it  would be  easier,  I will save  the data  to a text  file or  db,  then  run a sort of "report"  to produce a graph.  I have looked  at  and  played  with the code  at  Mark2150's  website,  and  Im  sure  its  great  but  I dont  think  I wanted to do  that  much,...as  I only  have  one  value to plot.

DaveMon
0
Comment
Question by:DaveMon
  • 4
  • 4
8 Comments
 
LVL 3

Expert Comment

by:Lewy
ID: 2612722
It sounds like you want something like a strip chart recorder, with the plot drawn as the paper moves across.
First decide how large the Image will be. What is the range of the value? Let’s say your value is a temperature between 32 and 100 degrees F. That’s a difference of 68. If you use a graph with one degree equal to one pixel then the resolution of the graph will be one degree and the graph will need to show 69 pixels. I used pixels because the display is based on pixels and to use other scale modes requires additional computations to resolve. If the final objective were to print the graph then it would be necessary to use a different scale mode.
Now the time base should be decided. Will the one minute cause the graph to move one pixel? Then how wide should the graph be? 60 pixels would be one hour.
To plot the points (readings), you would use the draw line function. You wold use the last point and the current point to draw the line. This will fill in any jumps in the value.
    Line(OldValue,2)-(NewValue,1),C
    OldValue = NewValue
Use the BitBlt to move the graph (chart). Move the Y starting at 0 and a width of one less than the width of the time base to position 1. This will shift the chart one pixel to the right. The column for Y=0 is blank. Think of this as the supply of blank chart paper.
0
 
LVL 2

Author Comment

by:DaveMon
ID: 2612975
that sounds exactly like I want.....I was wondering,  wouldnt  it  be beneficial for me  if  I could just  start  a sample  type  project with a textbox,   add  my  graph code,  and  then  verify  it's  working  by  changing  the textbox values  manually ( within 32-100 of course )  then  I could enter a value in the textbox, wait 1 minute  then observe the plotting of the line, as well as the movment of the "graph paper". After that  is going  well  I can transport the code to my real project and use the real time value from the textbox there.....
One more thing,  I am kinda new at this, and Im not sure how to begin coding for this, could I convince you to give me a rough outline of the code that will need to be there? I wont be picky, but something to get me started would be great as  I am not at all familiar with the Bitblt method, or with how to manipulate last point to current point. In fact,  I only  understand the PictureBox1.Drawline  method  and  Im sketchy  on that.  

thanks  Already

DaveMon
0
 
LVL 3

Accepted Solution

by:
Lewy earned 100 total points
ID: 2614372
Yes. It's a good idea to test in a seperate project.

Add the following to a modual:
    'see http://www.vbapi.com/ref/b/bitblt.html for info on BitBlt
    Declare Function BitBlt Lib "gdi32.dll" (ByVal hdcDest As Long, ByVal nXDest As Long, ByVal nYDest As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hdcSrc As Long, ByVal nXSrc As Long, ByVal nYSrc As Long, ByVal dwRop As Long) As Long
    Public Const SRCCOPY = &HCC0020

Add the following to a Form:
Private Sub Timer1_Timer()
    Static OldValue As Double
    Dim NewValue As Double
    Dim retval As Long  ' return value
    NewValue = Picture1.Height - ((Val(Text1.Text) - 32) / (100 - 32) * Picture1.Height)  'proper scaling
    Picture1.Line (2, OldValue)-(1, NewValue), Picture1.ForeColor
    OldValue = NewValue
    retval = BitBlt(Picture1.hDC, 1, 0, Picture1.Width - 1, Picture1.Height, Picture1.hDC, 0, 0, SRCCOPY)
    Timer1.Enabled = True
End Sub

Let me know how it works.
0
 
LVL 2

Author Comment

by:DaveMon
ID: 2618065


Sorry  to be a pain,  but  this  code  appears  to  make  a  solid  sheet  of  color  move from  left  to right. of the Picture box control, regardless  of the value used  ( I called the function  with  the  change  text  event )  Is  that incorrect? ( for testing, of course )  are there  any  settings  for the timer control  that  I need to specify?  Can   you  tell me  how  this  graph  should be  started with code  ( the real app   already  has the textbox   being  updated in real time...( I borrowed the code in case youre  wondering..heheh )  But  I do  want   to say  thanks your  post  has  gotten me  to within sight  of the  finish  line.

DaveMon
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 3

Expert Comment

by:Lewy
ID: 2619743
Besure to set the following at design time or in the load event:

    Form1.ScaleMode = vbPixels '3 - smallest unit of monitor
    Picture1.ScaleMode = vbPixels
    Picture1.AutoRedraw = True 'Enables automatic repainting using the image stored in memory.
    Timer1.Interval = 60000
0
 
LVL 2

Author Comment

by:DaveMon
ID: 2624980
Just  one more thing  Lewy,   I put  all of  this  in my  "real "  application  and  it  does  begin,  but I tied the graph  to the text_changed event,  and  I noticed  that  when  the temp  doesnt  change...the  graph  just   sits  there...I was  really  hoping   it  would  continue moving one pixel width per second and rise  and  fall according to the textbox  value....I have  checked  and  rechecked  all of the values you told me to code ...they  all seem fine...  can you think of a way I can  have the graph   constantly  moving  from left  to right?    I will  wait  to hear from you on  this  then  I will award  the points.


Thanks  

Dave
0
 
LVL 3

Expert Comment

by:Lewy
ID: 2628162
You must use a timer to process the graph at the interval you want. That establishes the Time Base.
If the value doesn’t change it still needs to be drawn to create the “flat” line.
There is a problem using a text box to manually enter a value. If in editing the value you remove a digit to be replaced by another digit say 56 to 57, at one point you have a 5 in the text box. If the graph is drawn at this point in time, well it’s not what you want.
Let me know if you need more help.
0
 
LVL 2

Author Comment

by:DaveMon
ID: 2709718
Thanks  Lewy   sorry  I took  so  long  to  accept  your  answer
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now