List Info

Thread: Re: VB 'Tools' - Gauges and Instrumentation Questions




Re: VB 'Tools' - Gauges and Instrumentation Questions
country flaguser name
United States
2007-08-12 11:31:23

Hi Spoo. I have been very silly. I did not notice that the pbAA.ScaleWidth line was missing from my copy of your code. The result, which I cannot say I fully understand (but which I am quite willing to NOT understand for the moment) was that the Circle was drawn properly but the Dots which should have been positioned on the Circle were not, except on the X-axis. That is, the shape of the Dots was an ellipse, 'squished' in the Y-axis. Any other 'circular' object I drew within the original circle was also 'squished' in the Y-axis. Anyway it was just my stupidity.
I do not know what is the ettiquette for what I am about to do - if I am doing wrong someone can let me know and I wont do it again.
Here is your code that I have been taking some liberties with, if you know what I mean. In other words here is the gauge I have created from your code. It's not the finished, polished item, or course. There are many things that could be improved (only need 1 array to hold the scale values, for instance). Am using Copy and Paste so hope this works out OK.
'// Start Code
'// The form, Form1, is 3540 high and 5265 wide. There is a PictureBox called pbAA
'// positioned to the centre, left of the form. To the right are a Text Box, called
'// txtInput and two Option Button called optImp and optMetric.
Sub Gauges()
With pbAA
.Top = 100
.Left = 200
.Height = 3000
.Width = 3000
.ZOrder 0
.Visible = True
.ScaleHeight = 8000
.ScaleWidth = 8000
.ScaleMode = 0
.BorderStyle = 0
.BackColor = &H8000000B 'Set to the same colour as the form, Form1.
End With
Update
End Sub
Private Sub Form_Load()
optMetric = True
'// Clear the display
pbAA.Cls
Gauges
End Sub
Sub Update()
With pbAA
'1. Clear the screen (for each new needle position)
.Cls

'Regenerate the gauge each time
'2. Draw the Outer Gauge Circle
ccx = 4000 'x coord centre
ccy = 4000 'y coord centre
rGauge = 3000 'radius of outer Gauge circle
rScale = 2700 'radius of inner scale arc
rMinor = 2520 'radius of Minor scale marker
rMajor = 2340 'radius of Major scale marker
rDot = 50 'radius of Needle Center 'Dot'
rNeedle = 1500 'radius of the Pointer or Needle
cc = RGB(0, 0, 0) 'Black
.DrawWidth = 3
pbAA.Circle (ccx, ccy), rGauge, cc 'Draw the outer circle
'// Make the pbAA PictureBox BackColor Property the same color as the form (Form1)
'// Make the pbAA PictureBox BorderStyle Property 0-None
'// Now give the gauge a white 'face'
.FillStyle = 0
.FillColor = RGB(255, 255, 255)

'3a. Draw an inner 'scale' arc from 315 degrees to 255 degrees anticlockwise
.DrawWidth = 1
pbAA.Circle (ccx, ccy), rScale, cc, 5.4978, 3.927

'3b. Create scale markers
.DrawWidth = 1
Dim aCos(40), aSin(40) 'arrays to hold the results
'Create a scale - place a minor marker at each 9 degree
'poition. Place a major marker at each 45 degree position
For ii = 0 To 39
'Need to skip 6 to 14, the portion of the circle that is not in the arc
If (ii > 5) And (ii < 15) Then
GoTo Skip
End If

radn = (ii * 9) * (3.1416 / 180) 'Convert degrees to radians
aCos(ii) = Cos(radn)
aSin(ii) = Sin(radn)
'Locate the point on the scale arc
xx1 = aCos(ii) * rScale + ccx
yy1 = aSin(ii) * rScale + ccy
'Locate the required inner position point - 1st for the Minor scale position
MinorXX = aCos(ii) * rMinor + ccx
MinorYY = aSin(ii) * rMinor + ccy
'Then for the Major scale position
MajorXX = aCos(ii) * rMajor + ccx
MajorYY = aSin(ii) * rMajor + ccy

'Draw the scale markers
If ((ii * 9) Mod 45) = 0 Then
'Draw the major marker
.DrawWidth = 2
pbAA.Line (xx1, yy1)-(MajorXX, MajorYY), 0
Else
'Draw the minor marker
.DrawWidth = 1
pbAA.Line (xx1, yy1)-(MinorXX, MinorYY), 0
End If
Skip:
Next ii

'3c. Add a numeric scale, i.e. print numbers on the major scale markers
Dim arrScaleMetric(7) As String, arrScaleImp(7) As String
'Populate the arrays
ImpInc = 5
MetInc = 10

arrScaleImp(3) = 0
arrScaleImp(4) = 5
arrScaleImp(5) = 10
arrScaleImp(6) = 15
arrScaleImp(7) = 20
arrScaleImp(0) = 25
arrScaleImp(1) = 30
arrScaleImp(2) = "&quot;

arrScaleMetric(3) = 0
arrScaleMetric(4) = 10
arrScaleMetric(5) = 20
arrScaleMetric(6) = 30
arrScaleMetric(7) = 40
arrScaleMetric(0) = 50
arrScaleMetric(1) = 60
arrScaleMetric(2) = "&quot;
'The metric array now contains the scale values for the metric gauge
'The imperial array now contains the scale values for the imperial gauge
For Index = 0 To 7
If Index = 2 Then
Index = Index + 1
End If
rValues = 1800
If optImp = True Then
txtH = pbAA.TextHeight(arrScaleImp(Index))
txtW = pbAA.TextWidth(arrScaleImp(Index))
pbAA.CurrentX = aCos(Index * 5) * rValues + ccx - (0.5 * txtW)
pbAA.CurrentY = aSin(Index * 5) * rValues + ccy - (0.5 * txtH)
pbAA.Print (arrScaleImp(Index))
Else
txtH = pbAA.TextHeight(arrScaleMetric(Index))
txtW = pbAA.TextWidth(arrScaleMetric(Index))
pbAA.CurrentX = aCos(Index * 5) * rValues + ccx - (0.5 * txtW)
pbAA.CurrentY = aSin(Index * 5) * rValues + ccy - (0.5 * txtH)
pbAA.Print (arrScaleMetric(Index))
End If
Next Index

'4a. Draw the needle
.DrawWidth = 2
xxi = ccx
yyi = ccy
'The scale operates from 135 degrees to 45 degrees clockwise and displays from
'0 to 30 MPH or from 0 to 60 km/h
'Each MPH has an increment of 9 degrees. Each km/h has an increment of 4.5 degrees
'0 on the scales is at (clockwise) 135 degrees. Full scale (30MPH) is at (clockwise)
'45 degrees
If txtInput.Text = "&quot; Then
iValue = 0
Else
iValue = txtInput.Text
End If
If optMetric = True Then
'FullScale = 60
If iValue > 60 Then
iValue = 60
End If
rad = ((iValue * 4.5 + 135) Mod 360) * 3.1416 / 180
Else
'FullScale = 30
If iValue > 30 Then
iValue = 30
End If
rad = ((iValue * 9 + 135) Mod 360) * 3.1416 / 180
End If
xx2 = Cos(rad) * rNeedle + ccx
yy2 = Sin(rad) * rNeedle + ccy
pbAA.Line (xxi, yyi)-(xx2, yy2), 0

'4b. Draw the centre 'Dot'
.DrawWidth = 6
pbAA.Circle (ccx, ccy), rDot, cc

'5. Print the units of measurement (MPH || km/h) in the lower centre
'of the gauge
pbAA.CurrentX = ccx - 400
pbAA.CurrentY = ccy + 2100

If optMetric = True Then
pbAA.Print "km/h"
Else
pbAA.Print "MPH&quot;
End If

End With

End Sub
Private Sub optImp_Click()
If txtInput.Text = "&quot; Then
txtInput.Text = 0
Else
txtInput.Text = Round(txtInput.Text / 1.609, 1)
End If
Update
End Sub
Private Sub optMetric_Click()
If txtInput.Text = "&quot; Then
txtInput.Text = 0
Else
txtInput.Text = Round(txtInput.Text * 1.609, 1)
End If
Update
End Sub
Private Sub txtInput_Change()
Update
End Sub

'//End Code

Take Care.

Mike

spooboy54 < spooboy54%40yahoo.com">spooboy54yahoo.com> wrote:
Mike

LOL !! Wasn't sure if I'd hear back from you.
Glad you have fooled around with this.. and if
you copied my original code, by now you've noticed
that the needle sweeps counter-clockwise!!

Anyway, to your current question. I sort of get
your drift, but am not clear as to the issue.. is
it the circle that shows as an ellipse, or is it
the dots?

The reason I asked is that below, you seem to have
added the "7&quot; multiplier only to "yy1&quot;, and if I
read your snippet properly, this is only affecting
the placement of the dots, having nothing to do with
the circle. So perhaps you could include a little
more code fragment pertaining to your specific issue.

That said, some other things to consider:
1. Aspect ratio: The Circle Method has as one optional
parameter the aspect ratio. Default is 1 (makes it a circle),
changing it will turn it into an ellipse. I did not include
it in my statement, hence mine drew a circle.

2. ScaleHeight, ScaleWidth: These too can affect the
drawing appearance, turning a circle into an ellipse.
I intentionally set them to the same value to make it a
circle. Did you mess with these?

3. "Any other circle...&quot;: could you include a code snippet
that covers these? Something may pop out if I see it.

Spoo

--- In visualbasic6programming%40yahoogroups.com">visualbasic6programmingyahoogroups.com, Michael Malone
<solarquark...> wrote:
&gt;
> Hi Spoo.
&gt; I've being playing with your PictureBox code below for the last few
days. Cool.
&gt; I have now created my first gauge, with your code as guidance. The
most important problem remains, however. What colour should it be?
>
> Actually I do have a little problem. This may be some sort of
scaling problem, but I have not been able to discover what it is that
I am doing wrong. The circle draws fine. But any other circle or
circular arrangement draws as an ellipse, 'squished' in the y-axis.
If I alter the code to, for example,
> '3. Put dots at each 45 degrees
> -
> -
> -yy1 = aSin(ii) * rr * 7 + ccy
> -
> -
> Note the '7' above.
&gt; Then the 'dots' draw on the original circle correctly. The same
happens if I try to draw any other circles inside the original (to
create a scale, for instance).
>
> I know I've done something stupid, but I cannot find what this is.
Any ideas?
&gt;
> Take care.
&gt;
> Mike
>;
>
>
>
>
> ----- Original Message ----
>; From: spooboy54 <spooboy54...>
> To: visualbasic6programming%40yahoogroups.com">visualbasic6programmingyahoogroups.com
&gt; Sent: Thursday, August 2, 2007 12:18:20 AM
> Subject: Re: [Visual Basic 6 programming] VB 'Tools' - Gauges and
Instrumentation Questions
>
> Mike
>;
> Haha! You took the bait !!
> OK, seeing as we both seem to be gluttons for
> punishment, I worked up this little ditty.
>
> It will draw a red circle, place 8 dots around
&gt; the perimeter, and then, using a timer, will
>; have a "needle" swing around the dial, one
> 45 degree angle sweep per second.
>
> The timer is merely to give you a sense of the
> effect. In real life, you will respond to
> a real-time data stream, say, from a weather vane.
&gt; And you'd want to modify the code to show more
>; resolution than simply 45 degrees.
>
> Note: Yahoo strips out leading blanks, so,
> to preserve the indents, I'll use "--&quot; .. you
> should disregard them. OK... here goes....
>
> On a form, add a PictureBox control (name it pbAA)
&gt; a Timer control (name it tmAA), and a command
> button (name it cmAA)
&gt;
> There are 3 subs, and 1 public variable.
> The sub cmAA is used to launch the demo
>; The sub Guages is used just to set up the PictureBox
> The sub tmAA_Timer will do the graphics animation.
>
> Declarations
> Public GGon ' just a counter
>
> Sub cmAA_Click()
> -- Guages
&gt; End Sub
>
> Sub Guages()
> -- With pbAA
>; ---- .Top = 500
> ---- .Left = 500
> ---- .Height = 5000
>; ---- .Width = 5000
>; ---- .ZOrder 0
> ---- .Visible = True
>; ---- .ScaleHeight = 15000
&gt; ---- .ScaleWidth = 15000
&gt; ---- .ScaleMode = 0
> -- End With
>; -- GGon = 0
> -- With tmAA
>; ---- .Interval = 1000 ' 1000 milliseconds = 1 second
&gt; ---- .Enabled = True ' will control the animation
> -- End With
>; End Sub
>
> Sub tmAA_Timer()
> -- With pbAA
>; ---- ' 1. clear the screen (for each new needle position)
> ---- .Cls
>; ---- ' 2. regenerate the "guage" each time
> ---- ccx = 7500 ' x-coord center
&gt; ---- ccy = 7500 ' y-coord center
&gt; ---- rr = 5000 ' radius of circle
&gt; ---- cc = RGB(255, 0, 0) ' color = red
> ---- .DrawWidth = 5
> ---- pbAA.Circle (ccx, ccy), rr, cc ' draws the circle
&gt; ---- ' 3. put dots at each 45 degrees
> ---- Dim aCos(7), aSin(7) ' create arrays to hold the results
> ---- For ii = 0 to 7
> ------ radn = (ii * 45) * (3.1416 / 180) ' convert deg to radians
> ------ aCos(ii) = Cos(radn)
> ------ aSin(ii) = Sin(radn)
> ------ xx1 = aCos(ii) * rr + ccx
> ------ yy1 = aSin(ii) * rr + ccy
> ------ pbAA.PSet (xx1, yy1), 0 ' draws the dot, 0 = black color
&gt; ---- Next ii
> ---- ' 4. draw the "needle" (sweep it 45 degrees each interval)
> ---- GGon = GGon + 1 ' just a counter
> ---- resu = GGon Mod 8 ' returns the modulus, so, from 0 to 7
> ---- xx1 = ccx
> ---- yy1 = ccy
> ---- xx2 = aSin(resu) * rr + ccx
> ---- yy2 = aCos(resu) * rr + ccy
> ---- pbAA.Line (xx1, yy1)-(xx2, yy2), 0 ' draws line, color = black
&gt; ---- ' 5. turn off the timer after 20 seconds
> ---- If GGon = 20 Then
>; ------ tmAA.Enabled = False
&gt; ---- End If
> -- End With
>; End Sub
>
> Click the button, and off she goes !!
> Hope this gives you a flavor.
> Spoo
>;
> --- In visualbasic6program mingyahoogroups .com, Michael Malone
> <solarquark ...> wrote:
&gt; >
>; > Aah! Someone with my own inclinations. I have been trying to
> curtail these (assembler-like? || C-like?) inclinations since I
> decided to learn VB. VB is a little like a Lego set. The components
> are, hopefully, already there - it's just a matter of selecting the
> correct (most suitable) building block and dropping this into the
> App. But you are right. If you can't find what you need reasonable
> easily then perhaps building it should be considered. I'll have to
> have a look at that PictureBox control - mind you, it can take me
> years to finish a project
> >
> > Thank you, Spoo.
&gt; >
> > Mike
>; >
> >
> > ----- Original Message ----
>; > From: spooboy54 <spooboy54 ..>
&gt; > To: visualbasic6program mingyahoogroups .com
>; > Sent: Sunday, July 29, 2007 4:18:30 PM
> > Subject: Re: [Visual Basic 6 programming] VB 'Tools' - Gauges and
> Instrumentation Questions
> >
> > Mike
>; >
> > If your search does not yield any guages that suit your
>; > needs, there's always the brute force method -- create your own!
>; >
> > You seem industrious and methodical, so this may be an
> > interesting challenge.
> >
> > I'd suggest the following to study:
&gt; >
> > PictureBox control
> > -- Line method
&gt; > -- Circle method
&gt; >
> > For example, you could create a speedometer- like guage
&gt; > that would react to a datastream you send to it in
> > a loop.
&gt; >
> > Or, you could create a custom chart.. horiz and vert
>; > gridlines, with the data curve(s) to show results over
>; > a particular time period, in different colors, with
>; > annotations as needed.
> >
> > The sky is the limit.
&gt; >
> > There is a cost .. time to get familiar with them and
> > time to code them to get them to do what you want. However,
> > you will retain ultimate control over how they look and work.
&gt; >
> > But there is also a cost in using someone else's -- finding
> > one you like, learning how to use it, maybe then finding
> > it doesn't meet your needs after all, and thus ending
&gt; > up spinning your wheels.
> >
> > There is no right answer, but I'm in the build-it-yourself
&gt; > camp.
&gt; >
> > Spoo
>; >
> > --- In visualbasic6program mingyahoogroups .com, Michael Malone
> > <solarquark ...> wrote:
&gt; > >
>; > > Thanks Rick.
&gt; > >
> > > vbaccelerator. com doesn't seem to have what I need but you
have
> > shown me that there are VB sites out there that may have - so
I'll
> > start looking.
> > >
> > > Components: This seems to me to be extraordinarily frustrating.
> > The 'vsFlexLib' for instance is included with the standard
install
> of
> > VB6. Is it therefore a Microsoft component? But there is no
mention
> > of this in the VB documentation. Nor does there seem to me any MS
> > Knowledge Base article on this component. On adding the component
> to
> > the project I can, as you suggest, see the functions, etc, of
that
> > component. But this still doesn't tell me what the component is
> > actually for. In addition, with the many hundreds of components
in
> > the standard install it would be practically impossible to use
this
> > method just to see this information for each component. Surely
> there
> > is a simple mechanism to determine the purpose of each component?
> Or
> > am I just expecting too much?
&gt; > >
> > > Thanks for your help, Rick.
&gt; > >
> > > Mike
>; > >
> > >
> >
> >
> >
> >
> >
> >
> >
> ____________ _________ _________ _________ _________ _________ _
> ____________ __
> > Boardwalk for $500? In 2007? Ha! Play Monopoly Here and Now (it's
> updated for today's economy) at Yahoo! Games.
&gt; > http://get.games. yahoo.com/ proddesc? gamekey=monopoly herenow
> >
> > [Non-text portions of this message have been removed]
> >
>;
>
>
>
>
>
>
__________________________________________________________
______________
> Building a website is a piece of cake. Yahoo! Small Business gives
you all the tools to get online.
> http://smallbusiness.yahoo.com/webhosting
>
> [Non-text portions of this message have been removed]
>

---------------------------------
Need a vacation? Get great deals to amazing places on Yahoo! Travel.

[Non-text portions of this message have been removed]

__._,_.___
.

__,_._,___
Re: VB 'Tools' - Gauges and Instrumentation Questions
country flaguser name
United States
2007-08-18 07:38:29

Mike

Let me first apologize for the delay in my reply.. I've been
kinda swamped of late. For that reason, too, I have not
tried to run your code. Nonetheless, I have read it, and
I must say ... very nice job .. very nicely annotated with
comments. You seem to have taken the very basic components
that I initially provided and run with it. That was exactly
my hope. It has blossomed quite nicely. Congrats.

Now, as to your initial stumble regarding the pbAA.ScaleWidth
statement.... this property (along with ScaleHeight) govern
the visual effect of 2-D graphics, such as circles and
rectangles. My approach to deal with this was to actually
use code to set the values. In the alternative, you could
have gone to the Properties window on the VB Editor and
set the values there. Either way is fine; I did it by code
mainly to highlight them as "properties of interest&quot; for
your purposes.

As to why your omission of the ScaleWidth produced to squished
dot positions why not affecting the Circle statement, here
is my hunch:

The circle statement is "self contained&quot; (ie, it has its own
aspect ratio parameter, discussed in my last post). Hence,
it doesn't care about ScaleWidth and ScaleHeight.

However, the PSet statement (for the dots) is not "self contained&quot;.
You are feeding it the xx1 and yy1 coordinates, which are based
on the coordinate system of the PictureBox pbAA. Said
coordinate system IS governed by ScaleWidth and ScaleHeight.
So, why did you get squished dots? --> The "default" values.

By "default" values, I mean the ones that appear in the
Properties window on the VB Editor when you created pbAA in
the first place. There were (and still should be) values
there. By only setting ScaleHeight in your code, the app
reverted to the default value for ScaleWidth (in the Properties
window) -- unless they are equal, you'll get a squished effect.

Hope this explains what you initially experienced.

You seem to be, as I mentioned above, progressing very nicely,
and at present don't seem to have any new issues. Let us
know if you do.

In closing, I couldn't help but notice the funny way you
spelled "color" and "center" (hehe)... you are obviously
a speaker of the Queen's English .. Brit or Aussie? I lived
in Newcastle on Tyne for a year when I was 11, many moons
ago, and in my current work, chat with Brits and Aussies
on a daily basis. We are constantly kidding each other
about spelling and other language quirks.

May the force be with you !

Spoo

--- In visualbasic6programming%40yahoogroups.com">visualbasic6programmingyahoogroups.com, Michael Malone
<solarquark...> wrote:
&gt;
> Hi Spoo. I have been very silly. I did not notice that the
pbAA.ScaleWidth line was missing from my copy of your code. The
result, which I cannot say I fully understand (but which I am quite
willing to NOT understand for the moment) was that the Circle was
drawn properly but the Dots which should have been positioned on the
Circle were not, except on the X-axis. That is, the shape of the Dots
was an ellipse, 'squished' in the Y-axis. Any other 'circular' object
I drew within the original circle was also 'squished' in the Y-axis.
Anyway it was just my stupidity.
> I do not know what is the ettiquette for what I am about to do -
if I am doing wrong someone can let me know and I wont do it again.
&gt; Here is your code that I have been taking some liberties with, if
you know what I mean. In other words here is the gauge I have created
from your code. It's not the finished, polished item, or course.
There are many things that could be improved (only need 1 array to
hold the scale values, for instance). Am using Copy and Paste so hope
this works out OK.
> '// Start Code
>; '// The form, Form1, is 3540 high and 5265 wide. There is a
PictureBox called pbAA
>; '// positioned to the centre, left of the form. To the right are a
Text Box, called
&gt; '// txtInput and two Option Button called optImp and optMetric.
> Sub Gauges()
> With pbAA
>; .Top = 100
> .Left = 200
> .Height = 3000
>; .Width = 3000
>; .ZOrder 0
> .Visible = True
>; .ScaleHeight = 8000
>; .ScaleWidth = 8000
>; .ScaleMode = 0
> .BorderStyle = 0
> .BackColor = &H8000000B 'Set to the same colour as the
form, Form1.
&gt; End With
>; Update
&gt; End Sub
> Private Sub Form_Load()
> optMetric = True
>; '// Clear the display
> pbAA.Cls
> Gauges
&gt; End Sub
> Sub Update()
> With pbAA
>; '1. Clear the screen (for each new needle position)
> .Cls
>;
> 'Regenerate the gauge each time
>; '2. Draw the Outer Gauge Circle
&gt; ccx = 4000 'x coord centre
&gt; ccy = 4000 'y coord centre
&gt; rGauge = 3000 'radius of outer Gauge circle
&gt; rScale = 2700 'radius of inner scale arc
> rMinor = 2520 'radius of Minor scale marker
&gt; rMajor = 2340 'radius of Major scale marker
&gt; rDot = 50 'radius of Needle Center 'Dot'
&gt; rNeedle = 1500 'radius of the Pointer or Needle
&gt; cc = RGB(0, 0, 0) 'Black
&gt; .DrawWidth = 3
> pbAA.Circle (ccx, ccy), rGauge, cc 'Draw the outer circle
&gt; '// Make the pbAA PictureBox BackColor Property the same
color as the form (Form1)
> '// Make the pbAA PictureBox BorderStyle Property 0-None
&gt; '// Now give the gauge a white 'face'
&gt; .FillStyle = 0
> .FillColor = RGB(255, 255, 255)
>;
> '3a. Draw an inner 'scale' arc from 315 degrees to 255
degrees anticlockwise
> .DrawWidth = 1
> pbAA.Circle (ccx, ccy), rScale, cc, 5.4978, 3.927
&gt;
> '3b. Create scale markers
> .DrawWidth = 1
> Dim aCos(40), aSin(40) 'arrays to hold the results
> 'Create a scale - place a minor marker at each 9 degree
&gt; 'poition. Place a major marker at each 45 degree position
> For ii = 0 To 39
> 'Need to skip 6 to 14, the portion of the circle that
is not in the arc
> If (ii > 5) And (ii < 15) Then
>; GoTo Skip
>; End If
>
> radn = (ii * 9) * (3.1416 / 180) 'Convert degrees to
radians
> aCos(ii) = Cos(radn)
> aSin(ii) = Sin(radn)
> 'Locate the point on the scale arc
> xx1 = aCos(ii) * rScale + ccx
> yy1 = aSin(ii) * rScale + ccy
> 'Locate the required inner position point - 1st for the
Minor scale position
> MinorXX = aCos(ii) * rMinor + ccx
> MinorYY = aSin(ii) * rMinor + ccy
> 'Then for the Major scale position
> MajorXX = aCos(ii) * rMajor + ccx
> MajorYY = aSin(ii) * rMajor + ccy
>
> 'Draw the scale markers
> If ((ii * 9) Mod 45) = 0 Then
>; 'Draw the major marker
&gt; .DrawWidth = 2
> pbAA.Line (xx1, yy1)-(MajorXX, MajorYY), 0
> Else
>; 'Draw the minor marker
&gt; .DrawWidth = 1
> pbAA.Line (xx1, yy1)-(MinorXX, MinorYY), 0
> End If
> Skip:
&gt; Next ii
>
> '3c. Add a numeric scale, i.e. print numbers on the major
scale markers
> Dim arrScaleMetric(7) As String, arrScaleImp(7) As String
&gt; 'Populate the arrays
&gt; ImpInc = 5
> MetInc = 10
>
> arrScaleImp(3) = 0
> arrScaleImp(4) = 5
> arrScaleImp(5) = 10
> arrScaleImp(6) = 15
> arrScaleImp(7) = 20
> arrScaleImp(0) = 25
> arrScaleImp(1) = 30
> arrScaleImp(2) = "&quot;
>
> arrScaleMetric(3) = 0
> arrScaleMetric(4) = 10
> arrScaleMetric(5) = 20
> arrScaleMetric(6) = 30
> arrScaleMetric(7) = 40
> arrScaleMetric(0) = 50
> arrScaleMetric(1) = 60
> arrScaleMetric(2) = "&quot;
> 'The metric array now contains the scale values for the
metric gauge
&gt; 'The imperial array now contains the scale values for the
imperial gauge
&gt; For Index = 0 To 7
> If Index = 2 Then
>; Index = Index + 1
> End If
> rValues = 1800
>; If optImp = True Then
>; txtH = pbAA.TextHeight(arrScaleImp(Index))
>; txtW = pbAA.TextWidth(arrScaleImp(Index))
> pbAA.CurrentX = aCos(Index * 5) * rValues + ccx -
(0.5 * txtW)
&gt; pbAA.CurrentY = aSin(Index * 5) * rValues + ccy -
(0.5 * txtH)
&gt; pbAA.Print (arrScaleImp(Index))
> Else
>; txtH = pbAA.TextHeight(arrScaleMetric(Index))
> txtW = pbAA.TextWidth(arrScaleMetric(Index))
&gt; pbAA.CurrentX = aCos(Index * 5) * rValues + ccx -
(0.5 * txtW)
&gt; pbAA.CurrentY = aSin(Index * 5) * rValues + ccy -
(0.5 * txtH)
&gt; pbAA.Print (arrScaleMetric(Index))
> End If
> Next Index
&gt;
> '4a. Draw the needle
&gt; .DrawWidth = 2
> xxi = ccx
> yyi = ccy
> 'The scale operates from 135 degrees to 45 degrees
clockwise and displays from
>; '0 to 30 MPH or from 0 to 60 km/h
>; 'Each MPH has an increment of 9 degrees. Each km/h has an
increment of 4.5 degrees
> '0 on the scales is at (clockwise) 135 degrees. Full scale
(30MPH) is at (clockwise)
> '45 degrees
> If txtInput.Text = "&quot; Then
>; iValue = 0
> Else
>; iValue = txtInput.Text
> End If
> If optMetric = True Then
>; 'FullScale = 60
> If iValue > 60 Then
>; iValue = 60
> End If
> rad = ((iValue * 4.5 + 135) Mod 360) * 3.1416 / 180
> Else
>; 'FullScale = 30
> If iValue > 30 Then
>; iValue = 30
> End If
> rad = ((iValue * 9 + 135) Mod 360) * 3.1416 / 180
> End If
> xx2 = Cos(rad) * rNeedle + ccx
> yy2 = Sin(rad) * rNeedle + ccy
> pbAA.Line (xxi, yyi)-(xx2, yy2), 0
>
> '4b. Draw the centre 'Dot'
&gt; .DrawWidth = 6
> pbAA.Circle (ccx, ccy), rDot, cc
>
> '5. Print the units of measurement (MPH || km/h) in the
lower centre
&gt; 'of the gauge
&gt; pbAA.CurrentX = ccx - 400
> pbAA.CurrentY = ccy + 2100
>;
> If optMetric = True Then
>; pbAA.Print "km/h"
&gt; Else
>; pbAA.Print "MPH&quot;
>; End If
>
> End With
>;
> End Sub
> Private Sub optImp_Click()
>; If txtInput.Text = "&quot; Then
>; txtInput.Text = 0
> Else
>; txtInput.Text = Round(txtInput.Text / 1.609, 1)
> End If
> Update
&gt; End Sub
> Private Sub optMetric_Click()
> If txtInput.Text = "&quot; Then
>; txtInput.Text = 0
> Else
>; txtInput.Text = Round(txtInput.Text * 1.609, 1)
> End If
> Update
&gt; End Sub
> Private Sub txtInput_Change()
> Update
&gt; End Sub
>
> '//End Code
>;
> Take Care.
&gt;
> Mike
>;
>
> spooboy54 <spooboy54...> wrote:
&gt; Mike
>;
> LOL !! Wasn't sure if I'd hear back from you.
>; Glad you have fooled around with this.. and if
> you copied my original code, by now you've noticed
> that the needle sweeps counter-clockwise!!
>
> Anyway, to your current question. I sort of get
> your drift, but am not clear as to the issue.. is
> it the circle that shows as an ellipse, or is it
> the dots?
&gt;
> The reason I asked is that below, you seem to have
>; added the "7&quot; multiplier only to "yy1&quot;, and if I
> read your snippet properly, this is only affecting
> the placement of the dots, having nothing to do with
>; the circle. So perhaps you could include a little
&gt; more code fragment pertaining to your specific issue.
&gt;
> That said, some other things to consider:
> 1. Aspect ratio: The Circle Method has as one optional
> parameter the aspect ratio. Default is 1 (makes it a circle),
> changing it will turn it into an ellipse. I did not include
> it in my statement, hence mine drew a circle.
>
> 2. ScaleHeight, ScaleWidth: These too can affect the
> drawing appearance, turning a circle into an ellipse.
> I intentionally set them to the same value to make it a
> circle. Did you mess with these?
&gt;
> 3. "Any other circle...&quot;: could you include a code snippet
> that covers these? Something may pop out if I see it.
>
> Spoo
>;
> --- In visualbasic6programming%40yahoogroups.com">visualbasic6programmingyahoogroups.com, Michael Malone
> <solarquark> wrote:
&gt; >
>; > Hi Spoo.
&gt; > I've being playing with your PictureBox code below for the last
few
> days. Cool.
&gt; > I have now created my first gauge, with your code as guidance.
The
> most important problem remains, however. What colour should it
be?
> >
> > Actually I do have a little problem. This may be some sort of
> scaling problem, but I have not been able to discover what it is
that
> I am doing wrong. The circle draws fine. But any other circle or
> circular arrangement draws as an ellipse, 'squished' in the y-axis.
> If I alter the code to, for example,
> > '3. Put dots at each 45 degrees
> > -
> > -
> > -yy1 = aSin(ii) * rr * 7 + ccy
> > -
> > -
> > Note the '7' above.
&gt; > Then the 'dots' draw on the original circle correctly. The same
> happens if I try to draw any other circles inside the original (to
> create a scale, for instance).
> >
> > I know I've done something stupid, but I cannot find what this
is.
> Any ideas?
&gt; >
> > Take care.
&gt; >
> > Mike
>; >
> >
> >
> >
> >
> > ----- Original Message ----
>; > From: spooboy54 <spooboy54>
>; > To: visualbasic6programming%40yahoogroups.com">visualbasic6programmingyahoogroups.com
&gt; > Sent: Thursday, August 2, 2007 12:18:20 AM
> > Subject: Re: [Visual Basic 6 programming] VB 'Tools' - Gauges and
> Instrumentation Questions
> >
> > Mike
>; >
> > Haha! You took the bait !!
> > OK, seeing as we both seem to be gluttons for
> > punishment, I worked up this little ditty.
> >
> > It will draw a red circle, place 8 dots around
&gt; > the perimeter, and then, using a timer, will
>; > have a "needle" swing around the dial, one
> > 45 degree angle sweep per second.
> >
> > The timer is merely to give you a sense of the
> > effect. In real life, you will respond to
> > a real-time data stream, say, from a weather vane.
&gt; > And you'd want to modify the code to show more
>; > resolution than simply 45 degrees.
> >
> > Note: Yahoo strips out leading blanks, so,
> > to preserve the indents, I'll use "--&quot; .. you
> > should disregard them. OK... here goes....
> >
> > On a form, add a PictureBox control (name it pbAA)
&gt; > a Timer control (name it tmAA), and a command
> > button (name it cmAA)
&gt; >
> > There are 3 subs, and 1 public variable.
> > The sub cmAA is used to launch the demo
>; > The sub Guages is used just to set up the PictureBox
> > The sub tmAA_Timer will do the graphics animation.
> >
> > Declarations
> > Public GGon ' just a counter
> >
> > Sub cmAA_Click()
> > -- Guages
&gt; > End Sub
> >
> > Sub Guages()
> > -- With pbAA
>; > ---- .Top = 500
> > ---- .Left = 500
> > ---- .Height = 5000
>; > ---- .Width = 5000
>; > ---- .ZOrder 0
> > ---- .Visible = True
>; > ---- .ScaleHeight = 15000
&gt; > ---- .ScaleWidth = 15000
&gt; > ---- .ScaleMode = 0
> > -- End With
>; > -- GGon = 0
> > -- With tmAA
>; > ---- .Interval = 1000 ' 1000 milliseconds = 1 second
&gt; > ---- .Enabled = True ' will control the animation
> > -- End With
>; > End Sub
> >
> > Sub tmAA_Timer()
> > -- With pbAA
>; > ---- ' 1. clear the screen (for each new needle position)
> > ---- .Cls
>; > ---- ' 2. regenerate the "guage" each time
> > ---- ccx = 7500 ' x-coord center
&gt; > ---- ccy = 7500 ' y-coord center
&gt; > ---- rr = 5000 ' radius of circle
&gt; > ---- cc = RGB(255, 0, 0) ' color = red
> > ---- .DrawWidth = 5
> > ---- pbAA.Circle (ccx, ccy), rr, cc ' draws the circle
&gt; > ---- ' 3. put dots at each 45 degrees
> > ---- Dim aCos(7), aSin(7) ' create arrays to hold the results
> > ---- For ii = 0 to 7
> > ------ radn = (ii * 45) * (3.1416 / 180) ' convert deg to radians
> > ------ aCos(ii) = Cos(radn)
> > ------ aSin(ii) = Sin(radn)
> > ------ xx1 = aCos(ii) * rr + ccx
> > ------ yy1 = aSin(ii) * rr + ccy
> > ------ pbAA.PSet (xx1, yy1), 0 ' draws the dot, 0 = black color
&gt; > ---- Next ii
> > ---- ' 4. draw the "needle" (sweep it 45 degrees each interval)
> > ---- GGon = GGon + 1 ' just a counter
> > ---- resu = GGon Mod 8 ' returns the modulus, so, from 0 to 7
> > ---- xx1 = ccx
> > ---- yy1 = ccy
> > ---- xx2 = aSin(resu) * rr + ccx
> > ---- yy2 = aCos(resu) * rr + ccy
> > ---- pbAA.Line (xx1, yy1)-(xx2, yy2), 0 ' draws line, color =
black
> > ---- ' 5. turn off the timer after 20 seconds
> > ---- If GGon = 20 Then
>; > ------ tmAA.Enabled = False
&gt; > ---- End If
> > -- End With
>; > End Sub
> >
> > Click the button, and off she goes !!
> > Hope this gives you a flavor.
> > Spoo
>; >
> > --- In visualbasic6program mingyahoogroups .com, Michael Malone
> > <solarquark ...> wrote:
&gt; > >
>; > > Aah! Someone with my own inclinations. I have been trying to
> > curtail these (assembler-like? || C-like?) inclinations since I
> > decided to learn VB. VB is a little like a Lego set. The
components
> > are, hopefully, already there - it's just a matter of selecting
the
> > correct (most suitable) building block and dropping this into the
> > App. But you are right. If you can't find what you need
reasonable
> > easily then perhaps building it should be considered. I'll have
to
> > have a look at that PictureBox control - mind you, it can take me
> > years to finish a project
> > >
> > > Thank you, Spoo.
&gt; > >
> > > Mike
>; > >
> > >
> > > ----- Original Message ----
>; > > From: spooboy54 <spooboy54 ..>
&gt; > > To: visualbasic6program mingyahoogroups .com
>; > > Sent: Sunday, July 29, 2007 4:18:30 PM
> > > Subject: Re: [Visual Basic 6 programming] VB 'Tools' - Gauges
and
> > Instrumentation Questions
> > >
> > > Mike
>; > >
> > > If your search does not yield any guages that suit your
>; > > needs, there's always the brute force method -- create your own!
>; > >
> > > You seem industrious and methodical, so this may be an
> > > interesting challenge.
> > >
> > > I'd suggest the following to study:
&gt; > >
> > > PictureBox control
> > > -- Line method
&gt; > > -- Circle method
&gt; > >
> > > For example, you could create a speedometer- like guage
&gt; > > that would react to a datastream you send to it in
> > > a loop.
&gt; > >
> > > Or, you could create a custom chart.. horiz and vert
>; > > gridlines, with the data curve(s) to show results over
>; > > a particular time period, in different colors, with
>; > > annotations as needed.
> > >
> > > The sky is the limit.
&gt; > >
> > > There is a cost .. time to get familiar with them and
> > > time to code them to get them to do what you want. However,
> > > you will retain ultimate control over how they look and work.
&gt; > >
> > > But there is also a cost in using someone else's -- finding
> > > one you like, learning how to use it, maybe then finding
> > > it doesn't meet your needs after all, and thus ending
&gt; > > up spinning your wheels.
> > >
> > > There is no right answer, but I'm in the build-it-yourself
&gt; > > camp.
&gt; > >
> > > Spoo
>; > >
> > > --- In visualbasic6program mingyahoogroups .com, Michael
Malone
> > > <solarquark ...> wrote:
&gt; > > >
>; > > > Thanks Rick.
&gt; > > >
> > > > vbaccelerator. com doesn't seem to have what I need but you
> have
> > > shown me that there are VB sites out there that may have - so
> I'll
> > > start looking.
> > > >
> > > > Components: This seems to me to be extraordinarily
frustrating.
> > > The 'vsFlexLib' for instance is included with the standard
> install
> > of
> > > VB6. Is it therefore a Microsoft component? But there is no
> mention
> > > of this in the VB documentation. Nor does there seem to me any
MS
> > > Knowledge Base article on this component. On adding the
component
> > to
> > > the project I can, as you suggest, see the functions, etc, of
> that
> > > component. But this still doesn't tell me what the component is
> > > actually for. In addition, with the many hundreds of components
> in
> > > the standard install it would be practically impossible to use
> this
> > > method just to see this information for each component. Surely
> > there
> > > is a simple mechanism to determine the purpose of each
component?
> > Or
> > > am I just expecting too much?
&gt; > > >
> > > > Thanks for your help, Rick.
&gt; > > >
> > > > Mike
>; > > >
> > > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > ____________ _________ _________ _________ _________ _________ _
> > ____________ __
> > > Boardwalk for $500? In 2007? Ha! Play Monopoly Here and Now
(it's
> > updated for today's economy) at Yahoo! Games.
&gt; > > http://get.games. yahoo.com/ proddesc? gamekey=monopoly herenow
> > >
> > > [Non-text portions of this message have been removed]
> > >
>; >
> >
> >
> >
> >
> >
> >
> __________________________________________________________
> ______________
>; > Building a website is a piece of cake. Yahoo! Small Business
gives
> you all the tools to get online.
> > http://smallbusiness.yahoo.com/webhosting
> >
> > [Non-text portions of this message have been removed]
> >
>;
>
>
>
>
>
> ---------------------------------
> Need a vacation? Get great deals to amazing places on Yahoo!
Travel.
>
> [Non-text portions of this message have been removed]
>

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )