simple vb.net questions | Newbie | | Join Date: Jun 2009
Posts: 4
| |
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: - 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!
|  | Moderator | | Join Date: Mar 2008 Location: Arizona, USA
Posts: 1,752
| | | 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
| | | re: simple vb.net questions
Well, the code simply doesnot work and I dont know why....
Thanks
|  | Moderator | | Join Date: Mar 2008 Location: Arizona, USA
Posts: 1,752
| | | 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
| | | 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.
|  | Moderator | | Join Date: Mar 2008 Location: Arizona, USA
Posts: 1,752
| | | re: simple vb.net questions Quote:
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. - 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. 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. - 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
| | Newbie | | Join Date: Jun 2009
Posts: 4
| | | 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
|  | Needs Regular Fix | | Join Date: Aug 2007
Posts: 493
| | | 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.
|  | Similar Visual Basic .NET bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,327 network members.
|