DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

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

Hybrid View

  1. #1
    Join Date
    Feb 2007

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

    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,


    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

    is this a wrong approach? or do i need to use the variables from form 1 in the code?? please help!

  2. #2
    Join Date
    Nov 2004
    I perfer to use global flags or variables, so that when form 1 is unfocused if textbox 1 contains x then the "x" global variable is set to true then when form 2 is unfocused if textbox 2 contains y then the "y" global variable is set to true, etc. etc. Then at the last just check the flags to see what form is your final destination.

  3. #3
    Join Date
    Feb 2007
    could you provide a simple example of how this is done (ie: using global falgs or variables)? im not quite sure as i am very new to vb

  4. #4
    Join Date
    Nov 2004
    Create a seperate module and title it "GlobalVariables"
    then add the following to the module:

    Public XTextBox as boolean 'this makes this variable a true or false type
    Public YTextBox as boolean
    Public ZTextBox as boolean
    'at this point you have created three variables that you will make either true or false
    ' by using the following code: XTextBox = True or xTextBox = False
    'you make them true or false in your program as you find our they are true or false.
    'For example after the user adds something to the text box on form 1 you will then want to see it is equal to your x value that you were looking for. This is then used later after all the text boxes are filled and you want to see if you should go to form A.
    'To see if you should go to form A just create an if statemen like this
    If XTextBox = True and YTextBox = True and ZTextBox = True then
    'now here is where you show your form A
    end if

  5. #5
    Join Date
    Feb 2007
    can this boolean be used for listboxes? for example:

    Public XListBox as boolean
    Public YListBox as boolean
    Public ZListBox as boolean

    i am not quite sure if you get what i mean. In form 1 I have a textbox to which the user adds names. Using the ADD button these names are added to the listbox on form 2. So these names that are added are stored in a variable on form1.

    Then on form 2, if the listbox 1 value = x (from the variable which stores the names from the previous forms, listbox 2 value = y (this is a random value) and listbox 3 value = z (again a random value)

    then form A is displayed.

    Therefore, it needs to look through the values from the variable which stores the names from the previous form.

    I hope this is more clearer

  6. #6
    Join Date
    Nov 2004
    I guess I do did not understand what you wanted, and I'm not sure that I understand now either. What is it you want to accomplish?

Similar Threads

  1. Display query result on Windows Form
    By megnin in forum .NET
    Replies: 2
    Last Post: 03-21-2007, 11:54 AM
  2. Replies: 1
    Last Post: 02-05-2007, 07:34 PM
  3. Replies: 0
    Last Post: 11-17-2005, 12:00 PM
  4. display data with listBox
    By shachar in forum VB Classic
    Replies: 0
    Last Post: 07-15-2001, 03:20 PM
  5. Replies: 2
    Last Post: 06-15-2001, 04:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center