943,722 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 1769
  • VB.NET RSS
Mar 22nd, 2008
0

If Statements!....for a newbie :)

Expand Post »
Hey guys, I am having trouble with this If satement. heres the code that i have so far:

vb Syntax (Toggle Plain Text)
  1. If Val(TextBox1.Text) = Val(TextBox3.Text) And Val(TextBox2.Text) = Val(TextBox4.Text) Then
  2. Label6.Text = "Students share 2 Subjects"
  3. End If
  4.  
  5. If Val(TextBox1.Text) = Val(TextBox4.Text) And Val(TextBox2.Text) = Val(TextBox3.Text) Then
  6. Label6.Text = "Students share 2 Subjects"
  7. End If
  8.  
  9. If Val(TextBox1.Text) = Val(TextBox3.Text) Or Val(TextBox2.Text) = Val(TextBox4.Text) Then
  10. Label6.Text = "Students share 1 Subject"
  11. If Val(TextBox2.Text) = Val(TextBox3.Text) Or Val(TextBox1.Text) = Val(TextBox4.Text) Then
  12. Label6.Text = "Students share 1 Subject"
  13. End If
  14. End If
  15.  
  16. If Val(TextBox1.Text) <> Val(TextBox3.Text) And Val(TextBox2.Text) <> Val(TextBox4.Text) Then
  17. Label6.Text = "Students share 0 subjects"
  18. End If
  19. If Val(TextBox1.Text) <> Val(TextBox4.Text) And Val(TextBox2.Text) <> Val(TextBox3.Text) Then
  20. Label6.Text = "Students share 0 subjects"
  21. End If



And here's what im trying to achieve (DL pic file attatchment). So If the two subject codes are the same the label is meant to read "students share 2 subjects" and if only one subject code matches then the label is meant to read "students share 1 subject" and if no subjects match then "students share 0 subjects".

I haven't named the textboxes or labels yet, so TextBox1 and TextBox2 are the subjects of Student 1 and TextBox3 and TextBox4 are the subjects of Student 2. Label6 is wehre the "students share x subject(s)"!!

Thank you very much for any help....I'm new to vb.net and appreciate any help given, Thank you very much!!!!
Attached Thumbnails
Click image for larger version

Name:	untitled.JPG
Views:	26
Size:	19.8 KB
ID:	5554  
Last edited by WolfPack; Mar 22nd, 2008 at 9:49 am. Reason: Added code tags. Use them when you post code. Also corrected indenting.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ferrier18 is offline Offline
5 posts
since Mar 2008
Mar 22nd, 2008
0

Re: If Statements!....for a newbie :)

Hey there ferrier, couldn't you just shorten that whole piece of code down to just 3 statements? I've done it here (without using Val, you can add it if you want and such):

VBNET Syntax (Toggle Plain Text)
  1. If TextBox1.Text = TextBox3.Text And TextBox2.Text = TextBox4.Text Or TextBox1.Text = TextBox4.Text And TextBox2.Text = TextBox3.Text Then
  2. Label6.Text = "Students share 2 subjects"
  3. ElseIf TextBox1.Text = TextBox3.Text And TextBox2.Text <> TextBox4.Text Or TextBox1.Text = TextBox4.Text And TextBox2.Text <> TextBox3.Text Or TextBox2.Text = TextBox4.Text And TextBox1.Text <> TextBox3.Text Or TextBox2.Text = TextBox3.Text And TextBox1.Text <> TextBox4.Text Then
  4. Label6.Text = "Students share 1 subject"
  5. Else
  6. Label6.Text = "Students share 0 subjects"
  7. End If

I think it works with every option if it doesn't then I'd have to sit down and work through it some more. Aye the middle elseif is just one huge statement lol.

Hope it works.

mhmm, looks like the VB.net highlighting syntax is incomplete
Reputation Points: 10
Solved Threads: 0
Light Poster
BluePaper is offline Offline
31 posts
since Mar 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Indent the C text in vb.net
Next Thread in VB.NET Forum Timeline: check box problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC