473,396 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

I am trying to create a combination password-like system making pictures appear

Before starting please note I am a complete novice so most of my codes will probably be messy and overcomplicated. I am trying to create a program where when you enter the correct series of digits (In this case 4 digits ranging from 1-12) a picture would appear. The problem is that though it is working for when the correct combination of digits is used, there are also a few occasions when the pictures appear even though the combination is incorrect. This happens mostly when 2 or more numbers match. I think the main one of the issues that complicates this is the fact that the combination can be allowed in any order, and also the same picture needs to become visible for different codes. E.g. 11 11 11 2 gives the same picture as 11 11 11 5 and so I have tried to group them rather than write the code out numerous times.

Here is the code I am currently using:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.  
  3.         If Textbox1.Text = "11" And Textbox2.Text = "11" And Textbox3.Text = "11" And (Textbox4.Text = "1" Or "2" Or "3" Or "4" Or "5") Then PictureBox2.Visible = True Else PictureBox2.Visible = False
  4.         If Textbox1.Text = "11" And Textbox2.Text = "11" And (Textbox3.Text = "1" Or "2" Or "3" Or "4" Or "5") And Textbox4.Text = "11" Then PictureBox3.Visible = True Else PictureBox3.Visible = False
  5.         If Textbox1.Text = "11" And (Textbox2.Text = "1" Or "2" Or "3" Or "4" Or "5") And Textbox3.Text = "11" And Textbox4.Text = "11" Then PictureBox4.Visible = True Else PictureBox4.Visible = False
  6.         If (Textbox1.Text = "1" Or "2" Or "3" Or "4" Or "5") And Textbox2.Text = "11" And Textbox3.Text = "11" And Textbox4.Text = "11" Then PictureBox1.Visible = True Else PictureBox1.Visible = False
  7.         If (Textbox1.Text = "8" Or "9") And (Textbox2.Text = "8" Or "9") And (Textbox3.Text = "8" Or "9") And Textbox4.Text = "12" Then PictureBox5.Visible = True Else PictureBox5.Visible = False
  8.         If (Textbox1.Text = "8" Or "9") And (Textbox2.Text = "8" Or "9") And Textbox3.Text = "12" And (Textbox4.Text = "8" Or "9") Then PictureBox6.Visible = True Else PictureBox6.Visible = False
  9.         If (Textbox1.Text = "8" Or "9") And Textbox2.Text = "12" And (Textbox3.Text = "8" Or "9") And (Textbox4.Text = "8" Or "9") Then PictureBox7.Visible = True Else PictureBox7.Visible = False
  10.         If Textbox1.Text = "12" And (Textbox2.Text = "8" Or "9") And (Textbox3.Text = "8" Or "9") And (Textbox4.Text = "8" Or "9") Then PictureBox8.Visible = True Else PictureBox8.Visible = False
May 6 '14 #1

✓ answered by Luk3r

I'm not 100% certain with VB, but I believe you have to nest the Or statement with the And statement:

Expand|Select|Wrap|Line Numbers
  1. If Textbox1.Text = "11" And Textbox2.Text = "11" And Textbox3.Text = "11" Then
  2.     If Textbox4.Text = "1" Or Textbox4.Text = "2" Or Textbox4.Text = "3" Or Textbox4.Text = "4" Or Textbox4.Text = "5" Then
  3.         PictureBox2.Visible = True
  4.     Else
  5.         PictureBox2.Visible = False
  6.     End If
  7. End If
Edit**: You may also have to put PictureBox2.Visible = False as your Else in your first If...Else statement. I just tossed some code at you to show nesting.

9 1391
Rabbit
12,516 Expert Mod 8TB
Please use code tags when posting code or formatted data.

You haven't told us which scenarios result in incorrect results.
May 6 '14 #2
There seem to be endless incorrect results.
The Image I want to appear from the combinations only:
"11 11 11 1", "11 11 11 2", "11 11 11 3", "11 11 11 4" or "11 11 11 5" also appears when the combinations "11 11 11 6", "11 11 11 7", "11 11 11 8", "11 11 11 9" or "11 11 11 10" are typed.

Expand|Select|Wrap|Line Numbers
  1. If Textbox1.Text = "11" And Textbox2.Text = "11" And Textbox3.Text = "11" And (Textbox4.Text = "1" Or "2" Or "3" Or "4" Or "5") Then PictureBox2.Visible = True Else PictureBox2.Visible = False
This is only one example as this seems to happen for most of the others as well. I hope this makes more sense?
May 6 '14 #3
Rabbit
12,516 Expert Mod 8TB
This is wrong:
Expand|Select|Wrap|Line Numbers
  1. (Textbox4.Text = "1" Or "2" Or "3" Or "4" Or "5")
It has to be this:
Expand|Select|Wrap|Line Numbers
  1. (Textbox4.Text = "1" Or Textbox4.Text = "2" Or Textbox4.Text = "3" Or Textbox4.Text = "4" Or Textbox4.Text = "5")
May 7 '14 #4
Luk3r
300 256MB
In Addition to what Rabbit said, you could also use greater than or equal to, or less than or equal to. Example:
Expand|Select|Wrap|Line Numbers
  1. Textbox4.text <= 5
Which would cover the whole range of 1 through 5 instead of typing it all out. BUT, Rabbit is right that your syntax is definitely off when using 'Or'.
May 7 '14 #5
Thank you, this has resolved some problems except now the code:
Expand|Select|Wrap|Line Numbers
  1.  If Textbox1.Text = "12" And (Textbox2.Text = "8" Or Textbox2.Text = "9") And (Textbox3.Text = "8" Or Textbox3.Text = "9") And (Textbox4.Text = "8" Or Textbox4.Text = "9") Then PictureBox8.Visible = True Else PictureBox8.Visible = False
Does not accept combinations such as: "12 8 9 8", "12 9 9 9" etc. as valid when they should work. Thank you for your help, sorry for the lack of understanding of coding.
May 7 '14 #6
Luk3r
300 256MB
I'm not 100% certain with VB, but I believe you have to nest the Or statement with the And statement:

Expand|Select|Wrap|Line Numbers
  1. If Textbox1.Text = "11" And Textbox2.Text = "11" And Textbox3.Text = "11" Then
  2.     If Textbox4.Text = "1" Or Textbox4.Text = "2" Or Textbox4.Text = "3" Or Textbox4.Text = "4" Or Textbox4.Text = "5" Then
  3.         PictureBox2.Visible = True
  4.     Else
  5.         PictureBox2.Visible = False
  6.     End If
  7. End If
Edit**: You may also have to put PictureBox2.Visible = False as your Else in your first If...Else statement. I just tossed some code at you to show nesting.
May 7 '14 #7
Rabbit
12,516 Expert Mod 8TB
What you have as your expression should work fine. There's something else going on. Try nesting the ifs and stepping through the code to see what the actual values are and how far down into the nested ifs the code gets.
May 8 '14 #8
Thank you Luk3r and Rabbit my codes are working fine now. The nesting was a necessary step I had skipped.
May 8 '14 #9
Luk3r
300 256MB
Glad we could help and happy coding!
May 8 '14 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: LornaJane | last post by:
I've not done very much Java before and now I'm working on a j2me application, however I think the trouble I have is generic java. I can compile, preverify and jar everything fine, but the...
0
by: Dominic | last post by:
I got the following error when I built a project. vcdeploy : error VCD0035: Failed to create the file system directory for the virtual directory. Access is denied. The project / properties /...
0
by: Krishna | last post by:
Hi, I have used the Crystal report viewer in my asp.net application. while i run the application the images of the reportviewer are not displaying what properties i need to set. Plz help me in...
1
by: §iD` | last post by:
Hi, I would like to create a file system virtual directory which should be accessible by Explorer and by application from the standard path (ex. c:\virtual_directory). I would like to be able to...
0
by: lupina | last post by:
Hi I'm making web user control in ASP .NET 2.0 (TextBox + Button). It works allright, but I need to add property and event to it, that would be visible in VS Designer. With property I havn't...
1
by: richardgroen | last post by:
Hi all, I got one brainteaser (well...for me). I have a database with, lets say 100 images, these images are 'dynamic' e.g. it can be 100 but also 151 images. My question is: How can i...
0
by: kiranvn31 | last post by:
Hi 1) in my project i have two images on image which is draw by my designer suppose name of images is Col1.png and another is fabric image which is downloaded from net suppose name of image is...
4
by: AlteredRealitii | last post by:
I'm trying to create a clock that allows me to use a completely different set of images for the hours minutes and seconds for the iPhone. This is what I currently have which works correctly in Google...
2
by: nabil elraie | last post by:
Am trying to create a POS system for a restaurant using access... and am facing problem on how to : first you know how POS systems work... when i use touch screen and choose the items or food photo...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.