Connecting Tech Pros Worldwide Help | Site Map

simple vb.net questions

Newbie
 
Join Date: Jun 2009
Posts: 4
#1: Jun 5 '09
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:
Expand|Select|Wrap|Line Numbers
  1. Public Class Screen
  2.     Inherits Windows.Forms.Form
  3.     Dim T(1, 2) As TextBox
  4.     Dim S(2) As PictureBox
  5.     Dim x, i, j As Integer
  6.  
  7.     Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles S1.Click
  8.         S1.BackColor = Color.Green
  9.  
  10.     End Sub
  11.  
  12.     Private Sub S2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles S2.Click
  13.         S2.BackColor = Color.Green
  14.     End Sub
  15.  
  16.     Private Sub S3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles S3.Click
  17.         S3.BackColor = Color.Green
  18.     End Sub
  19.  
  20.  
  21.     Public Function checkedS() As Boolean
  22.         If S1.BackColor = Color.Green Then
  23.             Return True
  24.         ElseIf S2.BackColor = Color.Green Then
  25.             Return True
  26.         ElseIf S3.BackColor = Color.Green Then
  27.             Return True
  28.         ElseIf S1.BackColor = Color.Red Then
  29.             Return False
  30.         End If
  31.  
  32.     End Function
  33.     Public Function findS() As Integer
  34.         If checkedS() = True Then
  35.             If S1.BackColor = Color.Green Then
  36.                 x = 0
  37.             ElseIf S2.BackColor = Color.Green Then
  38.                 x = 1
  39.             ElseIf S3.BackColor = Color.Green Then
  40.                 x = 2
  41.             End If
  42.             Return x
  43.         End If
  44.  
  45.     End Function
  46.     Public Sub setroute()
  47.  
  48.         t(0, 0) = TextBox1
  49.         t(0, 1) = TextBox2
  50.         t(0, 2) = TextBox3
  51.         t(1, 0) = TextBox4
  52.         t(1, 1) = TextBox5
  53.         t(1, 2) = TextBox6
  54.  
  55.         x = findS()
  56.         Do Until i = 3
  57.             t(x, i).BackColor = Color.White
  58.             i = i + 1
  59.         Loop
  60.     End Sub
  61.     Public Sub Screen_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  62.         If checkedS() = True Then
  63.  
  64.             setroute()
  65.         End If
  66.  
  67.  
  68.  
  69.     End Sub
  70. End Class

Thanks in advance!
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,752
#2: Jun 5 '09

re: simple vb.net questions


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?
Newbie
 
Join Date: Jun 2009
Posts: 4
#3: Jun 5 '09

re: simple vb.net questions


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

Thanks
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,752
#4: Jun 5 '09

re: simple vb.net questions


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?
Newbie
 
Join Date: Jun 2009
Posts: 4
#5: Jun 5 '09

re: simple vb.net questions


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.
tlhintoq's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,752
#6: Jun 5 '09

re: simple vb.net questions


Quote:

Originally Posted by nastaran4 View Post

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.

Expand|Select|Wrap|Line Numbers
  1.     Private Sub S2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles S2.Click
  2.         S2.BackColor = Color.Green
  3.     End Sub
Makes sense. You click on s2 and and s2 backcolor is told to go green. And nothing else.

Quote:
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.

Expand|Select|Wrap|Line Numbers
  1.     Private Sub S2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles S2.Click
  2.         S2.BackColor = Color.Green
  3.         If checkedS() = True Then setroute()
  4.     End Sub
Newbie
 
Join Date: Jun 2009
Posts: 4
#7: Jun 9 '09

re: simple vb.net questions


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
daniel aristidou's Avatar
Needs Regular Fix
 
Join Date: Aug 2007
Posts: 493
#8: Jun 14 '09

re: simple vb.net questions


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.
Reply