simple vb.net questions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nastaran4
    New Member
    • Jun 2009
    • 4

    simple vb.net questions

    Hi all,
    I am fairly new to vb.net so this question will certainly sound stupid, but I've been stock with it for the last week so any help is much appreciated.
    the form includes 3 picture boxes in red which you can click and change their color to green, also each picture box have three text box asscoiate with it and they are by default color dark gray. I want the system to check whether the picture boxes are clicked and if yes set the associated text box colours to white. here is the code I wrote:
    Code:
    Public Class Screen
        Inherits Windows.Forms.Form
        Dim T(1, 2) As TextBox
        Dim S(2) As PictureBox
        Dim x, i, j As Integer
        
        Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles S1.Click
            S1.BackColor = Color.Green
    
        End Sub
    
        Private Sub S2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles S2.Click
            S2.BackColor = Color.Green
        End Sub
    
        Private Sub S3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles S3.Click
            S3.BackColor = Color.Green
        End Sub
    
        
        Public Function checkedS() As Boolean
            If S1.BackColor = Color.Green Then
                Return True
            ElseIf S2.BackColor = Color.Green Then
                Return True
            ElseIf S3.BackColor = Color.Green Then
                Return True
            ElseIf S1.BackColor = Color.Red Then
                Return False
            End If
    
        End Function
        Public Function findS() As Integer
            If checkedS() = True Then
                If S1.BackColor = Color.Green Then
                    x = 0
                ElseIf S2.BackColor = Color.Green Then
                    x = 1
                ElseIf S3.BackColor = Color.Green Then
                    x = 2
                End If
                Return x
            End If
    
        End Function
        Public Sub setroute()
    
            t(0, 0) = TextBox1
            t(0, 1) = TextBox2
            t(0, 2) = TextBox3
            t(1, 0) = TextBox4
            t(1, 1) = TextBox5
            t(1, 2) = TextBox6
    
            x = findS()
            Do Until i = 3
                t(x, i).BackColor = Color.White
                i = i + 1
            Loop
        End Sub
        Public Sub Screen_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            If checkedS() = True Then
    
                setroute()
            End If
    
    
    
        End Sub
    End Class

    Thanks in advance!
    Last edited by tlhintoq; Jun 5 '09, 02:37 PM. Reason: [CODE] ... your code here ... [/CODE] tags added
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    You haven't actually asked a question or stated what is going wrong? Only what you want to happen. What is problem you are having?

    Comment

    • nastaran4
      New Member
      • Jun 2009
      • 4

      #3
      Well, the code simply doesnot work and I dont know why....

      Thanks

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        Don't work... where? Doesn't change the picture boxes when you click on them... Doesn't change the text boxes when you click on them... Doesn't change the text to white...

        Have you stepped through the code line by line to confirm values are what you are expecting at each point?

        Have you read the debugging guide article?

        Comment

        • nastaran4
          New Member
          • Jun 2009
          • 4

          #5
          well when I run the program it shows the pictures boxes and everything , when I click on the picture box it turns into green as I wanted it to, but then the three text boxes associated with that picture box do not turn into white.
          I assume that there is something wrong with calling events in my program, I call the event of picture box which is if it gets a green back color or not but for some reason it does not process it.

          Thanks for the link , I will look into it.

          Comment

          • tlhintoq
            Recognized Expert Specialist
            • Mar 2008
            • 3532

            #6
            Originally posted by nastaran4
            well when I run the program it shows the pictures boxes and everything , when I click on the picture box it turns into green as I wanted it to.
            Code:
                Private Sub S2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles S2.Click
                    S2.BackColor = Color.Green
                End Sub
            Makes sense. You click on s2 and and s2 backcolor is told to go green. And nothing else.

            but then the three text boxes associated with that picture box do not turn into white.
            Besides when the screen first loads, where are you calling your subroutines to check the condition of the pictureboxes? You change the background color then don't recheck anything.

            Code:
                Private Sub S2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles S2.Click
                    S2.BackColor = Color.Green
                    If checkedS() = True Then setroute()
                End Sub

            Comment

            • nastaran4
              New Member
              • Jun 2009
              • 4

              #7
              Thanks

              Thanks that made it work, but I am afraid I am stock with something else now, I had a moving red block cross over the white text boxes one by one with some delay... now I need the system to enable multiple enterings of these red boxes.
              To give more explanation I say what is this program about, it is to simulate the signalling of trains, the white boxes are representative of routes in which the train can go in and the red box is the train . I know want to enter more than one train at one time.

              Thanks

              Comment

              • daniel aristidou
                Contributor
                • Aug 2007
                • 494

                #8
                use "select case" and alot of if statements.
                making sure you comment all of your code at the top of each select statement, this should make the task easier.

                Comment

                Working...