473,387 Members | 1,603 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,387 software developers and data experts.

Using a value in a listbox to display a form in an IF statement

i am using visual basic express edition and i am very new to it.

I have a form 1 which has a textbox. User adds something to this textbox and clicks on the ADD button. User is taken to form 2 and the value has been added to a listbox.

on this form 2 there is a listbox which stores values from the previous form. I also have a button on this form. I want to write code for this button so that when it is clicked...

if the 1st listbox contains x, and the 2nd listbox contains y, and the 3rd listbox contains z,

then

form A is displayed.

im not quite sure how this is done. i have done something like this:

If Me.ListBox1.Contains "X" and ME.listbox2.Contains "Y"
AND ME.listbox3.contains "Z" then
FinalDestination.Show()

is this a wrong approach? or do i need to use the variables from form 1 in the code?? please help!
Mar 19 '07 #1
3 6497
cmrhema
375 256MB
I may be sending you a huge code but you will get the result.
First I assume that the values which you entered in your form1's textbox has been updated in form2' s list box
Now declare three variables in second form and initialise it to 0.Its kind of flag

Expand|Select|Wrap|Line Numbers
  1. Dim A As Integer
  2. Dim B As Integer
  3. Dim C As Integer
  4. A = 0
  5. B = 0
  6. C = 0
  7.  
  8. 'Now loop all the items in your list box listcount will give you the total no. of items in your list
  9. For i = 0 To List1.ListCount - 1
  10. 'Compare your string with the items in the list
  11. 'list1.list(i). It will search all your items in the list box
  12. If List1.List(i) = "a" Then
  13. 'if found set the flag as 1
  14. A = 1
  15. End If
  16. Next i
  17. 'So if found the value of the flag is 1 else it is 0
  18. 'Repeat the same for the other two list boxes
  19. For i = 0 To List2.ListCount - 1
  20. If List2.List(i) = "b" Then
  21. B = 1
  22. End If
  23. Next i
  24. For i = 0 To List3.ListCount - 1
  25. If List3.List(i) = "c" Then
  26. C = 1
  27. End If
  28. Next i
  29.  
  30. If A = 1 And B = 1 And C = 1 Then
  31. 'write your code
  32. 'you want to go to another form or whatever
  33. End If
Let's hope this works. But I am sure there will be someone who will put you to much small code
Good Luck
Mar 20 '07 #2
i tried the code above. I think i am making some mistake somewhere. I replaced List1, List2, and List3 with Listbox1, Listbox2, Listbox3 as these are the names for my listbox.

secondly Listbox1.Listcoutn does not work as Listcount is not a valid method for Listbox

Thirdly i had specified that:
if the 1st listbox contains x, and the 2nd listbox contains y, and the 3rd listbox contains z,

it should be this:

if the 1st listbox contains x (from the list of values that are stored fro the previous form' and the 2nd listbox contains y (this should be a random value just specified in the if statement), and the 3rd listbox contains z, (this should be a random value just specified in the if statement)
Mar 20 '07 #3
cmrhema
375 256MB
[HTML]i am using visual basic express edition and i am very new to it. [/HTML]

Sorry I did not go through that properly. Unfortunately I have no experience in visual basic express edition
Sorry for the trouble I let you in
Mar 21 '07 #4

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

Similar topics

3
by: Alex Stevens | last post by:
I'd already posted this in microsoft.public.dotnet.framework.windowsforms and microsoft.public.dotnet.framework.windowsforms.controls to no avail so apologies for the cross-posting. Hi, I'm...
1
by: Annette Massie | last post by:
I would like to have a form that lists current addresses being used. On this form I would also like to have a command button that would allow the user to add an address if they do not see it...
2
by: Remco Groot Beumer | last post by:
Hello, I created a program in which I use modules and classmodules for setting my variables. For example when I need to set the customerID in a variable I use something like: ...
9
by: Megan | last post by:
Hi- I'm creating a database of music bands with their cds and songs. I'm trying to program an SQL statement so that I can enter a string of text in a textbox, press the 'Enter' key, and have...
2
by: jpalmerx | last post by:
Hi, I have a form in Access with a listbox containing some choices. There is a "Select" button underneath that runs a macro opening a form that acts on the selected value. What I can't figure...
4
by: Regnab | last post by:
I've got a form - "frmLookup" (with a subform) that works very happily on its own. The form has a list box, which when updated requeries the subform to display the appropriate results. The...
0
by: Work007 | last post by:
Hi. I really need help on how to use a value stored in a listbox. I have a form on which it has the following code. This form allows the user to add a value to the textbox which is on this page...
1
by: tomlebold | last post by:
Having problems displaying query results from combo boxes on a sub form, which is on the same form that is used to select criteria. This has always worked form me when displaying query results on...
1
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...

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.