473,602 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

4 New Member
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.Con tains "X" and ME.listbox2.Con tains "Y"
AND ME.listbox3.con tains "Z" then
FinalDestinatio n.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 6526
cmrhema
375 Contributor
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
Work007
4 New Member
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.Listco utn 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 Contributor
[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
2401
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 writing a usercontrol which displays the typical two listboxes and the ability to move items from one to the other. The listboxes are populated with my custom objects (SwapItem), which simply
1
3572
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 listed. Is it possible to have the form show the list box (which is a combinination of the address and city/state/zip), along with the detail fields address and city/state/zip? I guess I was thinking of have the listbox display and then when the...
2
3475
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: Object.Variables.Customers.CusomerID = .... This works great and is similar in structure as for example the Docmd. or me. structure. Now I created a search form which can be opened from many forms, it consist of only a listbox. The listbox is filled at startup....
9
6990
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 it return the associated records to a listbox. Once the listbox has the records, I want to select a record, which will open a form associated with the selected record in the listbox.
2
10689
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 out is how to display an error, eg. "Please make a selection" if nothing is selected and the "Select" button is clicked. I'm trying an If Then Else statement worked into the button such as: If listbox value=null, then error message. Else, run...
4
2079
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 problem is that for the final user interface, I had planned to use a "frmDisplay" form which had a number of menu items and then depending on what the user selected, it would display the appropraite form in a subform beneath the menu items. I did this...
0
1345
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 and then takes the user to the next page: Public Class City Dim frm1 As ConfirmDestination 'Our instance of form2 Dim items As New List(Of String) 'Internal collection of items Dim streetitem As New List(Of String) ...
1
4271
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 another main and sub form. The requery on the sub form and refresh comands on the main form do not work when the form is first displayed and when the selection criteria is changed. Should I be doing a refresh and then repaint of the sub form. ...
1
4017
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 are not bound, I select from the bottom set and add to the top set which works fine, but now i decide to remove an item from the top set. when i tried to use a remove item code it worked fine, it did delete the item form the list but it added...
0
7993
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7920
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8404
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8054
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6730
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5867
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3944
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2418
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1510
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.