Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Changing the Colour of an Auto Shape (Line)


Could anyone help me with this query. I simply want to create a line
that changes colour, which I can do in part. But why when I run the
code, when BLUE or GREEN is entered into Test Sub, it just runs as
RED?


Code:
--------------------
Sub TestShoot()
Call DrawShooting(171#, 115.5, 255.75, 167.25, 2, "BLUE")
End Sub

Sub DrawShooting(StartX As Single, StartY As Single, EndX As Single, EndY As Single, _
Shots As Integer, Optional Color As String)
Dim Shot As Shape
Dim i As Integer
Dim j As Integer

'AddLine(BeginX As Single, BeginY As Single, EndX As Single, EndY As Single) As Shape - Member of Excel.Shapes
If IsMissing(Color) Then
Color = "RED"
ElseIf Color < "GREEN" Or Color < "BLUE" Then
Color = "RED"
End If


Select Case Color
Case "RED"
For i = 1 To Shots
Set Shot = ActiveSheet.Shapes.AddLine(StartX, StartY, EndX, EndY)
For j = 1 To 255
Shot.Line.ForeColor.RGB = RGB(255, 0 + j, 0 + j)
Application.Wait Now() + 0.0000007
Next
Shot.delete
Next
Case "GREEN"
For i = 1 To Shots
Set Shot = ActiveSheet.Shapes.AddLine(StartX, StartY, EndX, EndY)
For j = 1 To 255
Shot.Line.ForeColor.RGB = RGB(0 + j, 255, 0 + j)
Application.Wait Now() + 0.0000007
Next
Shot.delete
Next
Case "BLUE"
For i = 1 To Shots
Set Shot = ActiveSheet.Shapes.AddLine(StartX, StartY, EndX, EndY)
For j = 1 To 255
Shot.Line.ForeColor.RGB = RGB(0 + j, 0 + j, 255)
Application.Wait Now() + 0.0000007
Next
Shot.delete
Next
End Select
End Sub
--------------------


It is obviously something to do with my "
Code:
--------------------
If Color < "GREEN" Or Color < "BLUE" Then
--------------------
" statement, but I'm not sure what. Also, is there a more intuitive way
of selecting the colours than repeating similar code for RED GREEN AND
BLUE. Any help is appreciated.


--
d.i.barr
------------------------------------------------------------------------
d.i.barr's Profile: http://www.excelforum.com/member.php...o&userid=15521
View this thread: http://www.excelforum.com/showthread...hreadid=381268

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Changing the Colour of an Auto Shape (Line)

Your code fails right he
ElseIf Color < "GREEN" Or Color < "BLUE" Then
because one of these must always be False , so Not Green or Not Blue
together is, of course, False
Make it And instead of Or and I think it will work

"d.i.barr" wrote:


Could anyone help me with this query. I simply want to create a line
that changes colour, which I can do in part. But why when I run the
code, when BLUE or GREEN is entered into Test Sub, it just runs as
RED?


Code:
--------------------
Sub TestShoot()
Call DrawShooting(171#, 115.5, 255.75, 167.25, 2, "BLUE")
End Sub

Sub DrawShooting(StartX As Single, StartY As Single, EndX As Single, EndY As Single, _
Shots As Integer, Optional Color As String)
Dim Shot As Shape
Dim i As Integer
Dim j As Integer

'AddLine(BeginX As Single, BeginY As Single, EndX As Single, EndY As Single) As Shape - Member of Excel.Shapes
If IsMissing(Color) Then
Color = "RED"
ElseIf Color < "GREEN" Or Color < "BLUE" Then
Color = "RED"
End If


Select Case Color
Case "RED"
For i = 1 To Shots
Set Shot = ActiveSheet.Shapes.AddLine(StartX, StartY, EndX, EndY)
For j = 1 To 255
Shot.Line.ForeColor.RGB = RGB(255, 0 + j, 0 + j)
Application.Wait Now() + 0.0000007
Next
Shot.delete
Next
Case "GREEN"
For i = 1 To Shots
Set Shot = ActiveSheet.Shapes.AddLine(StartX, StartY, EndX, EndY)
For j = 1 To 255
Shot.Line.ForeColor.RGB = RGB(0 + j, 255, 0 + j)
Application.Wait Now() + 0.0000007
Next
Shot.delete
Next
Case "BLUE"
For i = 1 To Shots
Set Shot = ActiveSheet.Shapes.AddLine(StartX, StartY, EndX, EndY)
For j = 1 To 255
Shot.Line.ForeColor.RGB = RGB(0 + j, 0 + j, 255)
Application.Wait Now() + 0.0000007
Next
Shot.delete
Next
End Select
End Sub
--------------------


It is obviously something to do with my "
Code:
--------------------
If Color < "GREEN" Or Color < "BLUE" Then
--------------------
" statement, but I'm not sure what. Also, is there a more intuitive way
of selecting the colours than repeating similar code for RED GREEN AND
BLUE. Any help is appreciated.


--
d.i.barr
------------------------------------------------------------------------
d.i.barr's Profile: http://www.excelforum.com/member.php...o&userid=15521
View this thread: http://www.excelforum.com/showthread...hreadid=381268


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Changing the Colour of an Auto Shape (Line)


Change your else if from Or to And

ElseIf Color < "GREEN" Or Color < "BLUE" Then

to

ElseIf Color < "GREEN" And Color < "BLUE" Then

HTH


--
bhofsetz
------------------------------------------------------------------------
bhofsetz's Profile: http://www.excelforum.com/member.php...o&userid=18807
View this thread: http://www.excelforum.com/showthread...hreadid=381268

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Changing the Colour of an Auto Shape (Line)


You can actually avoid that IF statement altogether and take bette
advantage of your Select Case statement.

see modified code below:


Code
-------------------
Sub TestShoot()
Call DrawShooting(171#, 115.5, 255.75, 167.25, 20, "BLUE")
End Sub

Sub DrawShooting(StartX As Single, StartY As Single, EndX As Single, EndY As Single, _
Shots As Integer, Optional Color As String)
Dim Shot As Shape
Dim i As Integer
Dim j As Integer

Select Case Color
Case "GREEN"
For i = 1 To Shots
Set Shot = ActiveSheet.Shapes.AddLine(StartX, StartY, EndX, EndY)
For j = 1 To 255
Shot.Line.ForeColor.RGB = RGB(0 + j, 255, 0 + j)
Application.Wait Now() + 0.0000007
Next
Shot.Delete
Next
Case "BLUE"
For i = 1 To Shots
Set Shot = ActiveSheet.Shapes.AddLine(StartX, StartY, EndX, EndY)
For j = 1 To 255
Shot.Line.ForeColor.RGB = RGB(0 + j, 0 + j, 255)
Application.Wait Now() + 0.0000007
Next
Shot.Delete
Next
Case Else
For i = 1 To Shots
Set Shot = ActiveSheet.Shapes.AddLine(StartX, StartY, EndX, EndY)
For j = 1 To 255
Shot.Line.ForeColor.RGB = RGB(255, 0 + j, 0 + j)
Application.Wait Now() + 0.0000007
Next
Shot.Delete
Next

End Select
End Su
-------------------


HT

--
bhofset
-----------------------------------------------------------------------
bhofsetz's Profile: http://www.excelforum.com/member.php...fo&userid=1880
View this thread: http://www.excelforum.com/showthread.php?threadid=38126

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Changing the Colour of an Auto Shape (Line)


Thanks bhofsetz and K Dales for the response, that works a treat.
Bhofsetz, the Case statement does make a lot more sense. Have you an
idea how I would make the values of "Color" non-case sensitive? Tha
is, to work with BLUE or Blue or blue or bLue etc without listing the
all seperately in the Case statement? Thanks in advance

--
d.i.bar
-----------------------------------------------------------------------
d.i.barr's Profile: http://www.excelforum.com/member.php...fo&userid=1552
View this thread: http://www.excelforum.com/showthread.php?threadid=38126



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Changing the Colour of an Auto Shape (Line)


Sorry, I got it ten minutes after posting. Just placing

Code
-------------------
Color = UCase(Color
-------------------

at the start will work

--
d.i.bar
-----------------------------------------------------------------------
d.i.barr's Profile: http://www.excelforum.com/member.php...fo&userid=1552
View this thread: http://www.excelforum.com/showthread.php?threadid=38126

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
If I draw a shape in Excel (say a triangle), can I colour it? David Burne Jones Excel Worksheet Functions 4 August 4th 08 08:44 PM
Shape colour set according to text value tonywig Excel Discussion (Misc queries) 1 April 19th 06 07:18 PM
Legends - Changing the Shape of Paul Charts and Charting in Excel 2 January 4th 06 12:22 PM
Auto Date 4 changing fields in a line nastech Excel Discussion (Misc queries) 3 October 12th 05 11:49 PM
Why oh why are my comment boxes changing shape? Marc New Users to Excel 1 April 1st 05 03:54 AM


All times are GMT +1. The time now is 05:05 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"