Click here to Skip to main content
15,039,149 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a code that can generate a number of straight lines on the form in VB 2010. It works in such a way that you write the number of lines in the textbox you want to create on the form. It will create half of the lines only. But then, there is another button which will increment one line at a time below the bunch of the lines create earlier and MOVES all the lines up. for example: I put 16 in the textbox: it will generate 8 lines only. Then I will click the second button to add rest of the 8 lines below the previously created lines ONE BY ONE with each click and it will move the lines up as well. Means that the starting point of the line will be same and it will move the lines up from that point one by one until it reaches 16.
So far the code I have is below. The problem is that i cant increment the lines with the click of the second button. You quick response will be appreciated...... Thanks and Best Regards VB_Learner

[Edit] added comment from OP
The problem is that i cant increment the lines one by one from the click of the second button.
[/Edit]

What I have tried:

VB
Public Class Form1
Private Xstart As Integer
Private Ystart As Integer
Private Xend As Integer
Private Yend As Integer

Dim graphicsfun As Graphics
Dim pencolor As New Pen(Color.Navy, 1)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    graphicsfun = Me.CreateGraphics

    graphicsfun.Clear(Color.White)

    Xstart = 50
    Ystart = 100
    Xend = 250
    Yend = 50

    Dim i As Integer



    For i = 0 To (Val(Me.TextBox1.Text) / 2) - 1

        graphicsfun.DrawLine(pencolor, Xstart + 150, i * (-Ystart) + 700, Xend + 150, i * (-Yend) + 700)

        Ystart = +8
        Yend = +8
    Next
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click


    Dim rollon As Integer
    Dim iter As Integer
    For iter = 0 To (Val(Me.TextBox1.Text) / 2) - 1
        For rollon = 1 To (Val(Me.TextBox1.Text) / 2) - 1

            graphicsfun.DrawLine(pencolor, Xstart + 150, rollon * (-Ystart) + 700 + (Ystart), Xend + 150, rollon * (-Yend) + 700 + (Yend))

            Ystart = +8
            Yend = +8

        Next

    Next




End Sub
Posted
Updated 27-May-17 1:25am
v4
Comments
[no name] 27-May-17 7:05am
   
And the Problem is?
VB_Learner 27-May-17 7:08am
   
The problem is that i cant increment the lines one by one from the click of the second button. Sorry for not mentioning the problem earlier.. thanks !!
[no name] 27-May-17 7:13am
   
No Problem. I suggest you to improve the question with this Information ;) I did it meanwhile for you. I hope you can agree with that. Otherwhise you have always the possibility to remove my changes.
[no name] 27-May-17 8:26am
   
First: I have _no_ expirience with VB Syntax...
Second: I think your Problem seems to be (on a very lazy view to your code) that you don't capture what allready has done. You allways reffer to TextBox1 value also in Button2_Click, but you should capture what you allready did in a member variable of the form.

BTW: Naming Buttons helps you and others. What I mean is "Button1" should be named something like "ButtonStartGraph" and "Button2" something like "ButtonStepGraph"...
[no name] 27-May-17 7:08am
   
And through all of that you didn't ask a question or describe an actual problem. Learn how to use the debugger and you would likely solve whatever your problem is yourself.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900