Why does this simple code not work? 
Author Message
 Why does this simple code not work?

I am trying to draw things on a form and I can't work out why the following
code doesn't produce a horisontal line in the middle of the form:

Private Sub Command1_Click()
Dim Xval As Integer
Dim StartPosX As Single
Dim StartPosY As Single
StartPosY = 0.5 * Form1.Height
For Xval = 0 To Form1.Width
    Line (StartPosX, StartPosY)-(Xval, Xval + (0.5 * Form1.Height)),
QBColor(4)
    StartPosX = Xval
    StartPosY = Xval
Next Xval
End Sub

I realise there is a simpler way of making a line across the form but I
specifically want it done in this way.

Thanks

Alex



Wed, 18 Jun 1902 08:00:00 GMT  
 Why does this simple code not work?
Replace height and width for the scaleheight and scalewidth
Your scalemode can be different from twips ....
height and width - outer dimensions using container scale units
Quote:

> I am trying to draw things on a form and I can't work out why the following
> code doesn't produce a horisontal line in the middle of the form:

> Private Sub Command1_Click()
> Dim Xval As Integer
> Dim StartPosX As Single
> Dim StartPosY As Single
> StartPosY = 0.5 * Form1.Height
> For Xval = 0 To Form1.Width
>     Line (StartPosX, StartPosY)-(Xval, Xval + (0.5 * Form1.Height)),
> QBColor(4)
>     StartPosX = Xval
>     StartPosY = Xval
> Next Xval
> End Sub

> I realise there is a simpler way of making a line across the form but I
> specifically want it done in this way.

> Thanks

> Alex



Wed, 18 Jun 1902 08:00:00 GMT  
 Why does this simple code not work?
Replace height and width for the scaleheight and scalewidth
Your scalemode can be different from twips ....
height and width - outer dimensions using container scale units
Quote:

> I am trying to draw things on a form and I can't work out why the following
> code doesn't produce a horisontal line in the middle of the form:

> Private Sub Command1_Click()
> Dim Xval As Integer
> Dim StartPosX As Single
> Dim StartPosY As Single
> StartPosY = 0.5 * Form1.Height
> For Xval = 0 To Form1.Width
>     Line (StartPosX, StartPosY)-(Xval, Xval + (0.5 * Form1.Height)),
> QBColor(4)
>     StartPosX = Xval
>     StartPosY = Xval
> Next Xval
> End Sub

> I realise there is a simpler way of making a line across the form but I
> specifically want it done in this way.

> Thanks

> Alex



Wed, 18 Jun 1902 08:00:00 GMT  
 Why does this simple code not work?
Replace height and width for the scaleheight and scalewidth
Your scalemode can be different from twips ....
height and width - outer dimensions using container scale units
Quote:

> I am trying to draw things on a form and I can't work out why the following
> code doesn't produce a horisontal line in the middle of the form:

> Private Sub Command1_Click()
> Dim Xval As Integer
> Dim StartPosX As Single
> Dim StartPosY As Single
> StartPosY = 0.5 * Form1.Height
> For Xval = 0 To Form1.Width
>     Line (StartPosX, StartPosY)-(Xval, Xval + (0.5 * Form1.Height)),
> QBColor(4)
>     StartPosX = Xval
>     StartPosY = Xval
> Next Xval
> End Sub

> I realise there is a simpler way of making a line across the form but I
> specifically want it done in this way.

> Thanks

> Alex



Wed, 18 Jun 1902 08:00:00 GMT  
 Why does this simple code not work?
That still doesn't work. It creates a diagonal bar across the bottom left
corner of the form.

Thanks

Alex

Quote:
> Replace height and width for the scaleheight and scalewidth
> Your scalemode can be different from twips ....
> height and width - outer dimensions using container scale units


> > I am trying to draw things on a form and I can't work out why the
following
> > code doesn't produce a horisontal line in the middle of the form:

> > Private Sub Command1_Click()
> > Dim Xval As Integer
> > Dim StartPosX As Single
> > Dim StartPosY As Single
> > StartPosY = 0.5 * Form1.Height
> > For Xval = 0 To Form1.Width
> >     Line (StartPosX, StartPosY)-(Xval, Xval + (0.5 * Form1.Height)),
> > QBColor(4)
> >     StartPosX = Xval
> >     StartPosY = Xval
> > Next Xval
> > End Sub

> > I realise there is a simpler way of making a line across the form but I
> > specifically want it done in this way.

> > Thanks

> > Alex



Wed, 18 Jun 1902 08:00:00 GMT  
 Why does this simple code not work?
Why not use pset to place a point on the screen instead of a minute line?

Private Sub Command1_Click()
Dim Xval As Integer
Dim StartPosX As Single
Dim StartPosY As Single
StartPosY = 0.5 * Form1.Height

For Xval = 0 To Form1.Width
    form1.pset(Xval, StartPosY),QBColor(4)
Next Xval

End Sub



Wed, 18 Jun 1902 08:00:00 GMT  
 Why does this simple code not work?
Alex

The following produces a horizontal line in the middle of the form:

=================================================
Private Sub Command1_Click()
Dim lineYposition As Single
Dim lineThickness As Single

    'Calculate the middle of the form
    lineYposition = ScaleTop + (ScaleHeight - ScaleTop) / 2

    'Set the line thickness
    lineThickness = lineYposition / 10

    'Draw the line using (actually a filled rectangular)
    Line (ScaleLeft, lineYposition - lineThickness / 2)- _
            Step(ScaleWidth, lineThickness), _
            QBColor(4), BF

'Or if you exists on using a For..Next:
'Dim Ypos As Single
'    For Ypos = -lineThickness / 2 To lineThickness / 2
'        Line (ScaleLeft, lineYposition + Ypos)-Step(ScaleWidth, 0),
QBColor(4)
'    Next
End Sub
=================================================

Hope this helps
Johan.



| I am trying to draw things on a form and I can't work out why the
following
| code doesn't produce a horisontal line in the middle of the form:
|
| Private Sub Command1_Click()
| Dim Xval As Integer
| Dim StartPosX As Single
| Dim StartPosY As Single
| StartPosY = 0.5 * Form1.Height
| For Xval = 0 To Form1.Width
|     Line (StartPosX, StartPosY)-(Xval, Xval + (0.5 * Form1.Height)),
| QBColor(4)
|     StartPosX = Xval
|     StartPosY = Xval
| Next Xval
| End Sub
|
| I realise there is a simpler way of making a line across the form but I
| specifically want it done in this way.
|
| Thanks
|
| Alex
|
|



Wed, 18 Jun 1902 08:00:00 GMT  
 Why does this simple code not work?
Make a table and step through your code (say that Form1.Height=1000):

StartPosX      <> StartPosY          <> Xval     <> Line_from
StartPosX,StartPosY to Xval, Xval+(0,5*Form1.Height)
StartPosX=0 <> StartPosY=500 <> Xval=0 <> Line from 0 , 500 to 0 , 500
StartPosX=0 <> StartPosY=0      <> Xval=1 <> Line from 0 , 0     to 1 , 501
StartPosX=1 <> StartPosY=1      <> Xval=2 <> Line from 1 , 1     to 2 , 502
StartPosX=2 <> StartPosY=2      <> Xval=3 <> Line from 2 , 2     to 3 , 503
StartPosX=3 <> StartPosY=3      <> Xval=4 <> Line from 3 , 3     to 4 , 504

The first line is not a line and then the other lines are almost vertical
lines were:
the X of the Endpoint = the X of the Startpoint + 1 and
the Y of the Endpoint = the Y of the Startpoint + half Height of your Form

Try this:

Private Sub Command1_Click()
Dim Xval As Integer
Dim StartPosX As Single
Dim StartPosY As Single
StartPosY = 0.5 * Form1.Height
For Xval = 0 To Form1.Width
    StartPosX = Xval
    Line (StartPosX, StartPosY)-(StartPosX+1, StartPosY), QBColor(4)
Next Xval
End Sub

Or the easiest way:

Private Sub Command1_Click()
    Line (0, 0.5 * Form1.Height)-(Form1.Width, 0.5 * Form1.Height),
QBColor(4)
End Sub


message

Quote:
>I am trying to draw things on a form and I can't work out why the following
>code doesn't produce a horisontal line in the middle of the form:

>Private Sub Command1_Click()
>Dim Xval As Integer
>Dim StartPosX As Single
>Dim StartPosY As Single
>StartPosY = 0.5 * Form1.Height
>For Xval = 0 To Form1.Width
>    Line (StartPosX, StartPosY)-(Xval, Xval + (0.5 * Form1.Height)),
>QBColor(4)
>    StartPosX = Xval
>    StartPosY = Xval
>Next Xval
>End Sub

>I realise there is a simpler way of making a line across the form but I
>specifically want it done in this way.

>Thanks

>Alex



Wed, 18 Jun 1902 08:00:00 GMT  
 Why does this simple code not work?
Try and see if one of these samples help.
I put these in the Form_Resize event so you can see the effect better.

Private Sub Form_Resize()
Dim EndPosX As Single
Dim CentPosY As Single
EndPosX = Me.ScaleWidth
CentPosY = Me.ScaleHeight / 2
'----------------------------

'---Draws a line in the center of the form
Cls
Line (0, CentPosY)-(EndPosX, CentPosY), QBColor(4)
'---

'---Moves a line control in the center of the form
'Line1.X1 = 0
'Line1.X2 = EndPosX
'Line1.Y1 = CentPosY
'Line1.Y2 = CentPosY
'---

'---Draws the upper half of the form solid
'Cls
'Line (0, 0)-Step(EndPosX, CentPosY), QBColor(4), BF
'---

'---Draws the lower half of the form solid
'Cls
'Line (0, CentPosY)-Step(EndPosX, CentPosY * 2), QBColor(4), BF
'---

'---Draws a line in the center of the form from left to right
'Dim Xval As Integer
'Cls
'For Xval = 0 To EndPosX
'    Line (0, CentPosY)-(Xval, CentPosY), QBColor(4)
'Next Xval
'---
End Sub

Some free VB  addins and tools
http://members.nbci.com/marshall48/MiscVB/vbaddins.htm



Wed, 18 Jun 1902 08:00:00 GMT  
 Why does this simple code not work?
you don't want to change your Y value like you do with StartPosY = Xval
(that is what makes it go diagonally--you are changing your StartPosY with
the X value).  take that line out and it works fine.  for that matter, you
don't need to add Xval to the ending Y value. so your function should look
like this:

Private Sub Command1_Click()
Dim Xval As Integer
Dim StartPosX As Single
Dim StartPosY As Single
StartPosY = 0.5 * Form1.Height
For Xval = 0 To Form1.Width
    Line (StartPosX, StartPosY)-(Xval, StartPosY ), QBColor(4)
    StartPosX = Xval
Next Xval
End Sub



Sun, 30 Mar 2003 13:02:21 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. simple animations with code...not doing what they should

2. Simple animations with code...not doing what they should

3. Why is simple For/Next loop not working?

4. Why doesn't this simple code work!!!!

5. Why does the following code not work?

6. this code does not work, why?

7. (Simple) code not working

8. Help Please...Code does not work why?

9. Why code will not work?

10. Why does this piece of code work with Word 97 but not Word 2000

11. why will this code not work

12. Find/Replace code not working - why?

 

 
Powered by phpBB® Forum Software