How do I use IF x.text="" OR y.text=""

Discussion in 'Questions (Windows Mobile)' started by sunnyboyj, Dec 19, 2007.

  1. sunnyboyj

    sunnyboyj Member

    I have a form with lets say 2 textboxes; textbox x and textbox y

    the thing is I want b4ppc to check if in one of them is text typed in (only ok when OR x OR y is typed in, not ok when x AND y are typed in or if nothing is typed in).
    I thought i could use:
    If x.text="" OR y.text="" Then
    Msgbox("Please fill in x or y")
    Return
    End If
    Thanks!
    Jorrit
     
  2. agraham

    agraham Expert Licensed User

    You probably want

    If x.text="" AND y.text="" Then
     
  3. sunnyboyj

    sunnyboyj Member

    I would think you are right. It works better. The problem is bigger:
    i have more then two lines which can be filled in:
    x.text, y.text and z.text
    If I use the AND argument
    IF x.text="" AND y.text="" AND z.text="" my program will accept only when one is filled in (and that's what I want!), but also if i fill in all three (and that's what I don't want). My problem is therfore: how do I make my program that it will accept only and filled (x or y or z)?
     
  4. sunnyboyj

    sunnyboyj Member

    Maybe I can do something like add the text from x+y+z and compare that with ""?
    I think that's they way, but I don't know how to compare them. I tried this but it's not working:

    Can I make a new variable and then

    compare=x.text+y.text+z.text
    if compare ="" then
    etc. etc.
     
  5. specci48

    specci48 Well-Known Member Licensed User

    Hi sunnyboyj,

    if the textboxes have similar names with different numbers like textbox1, textbox2, etc. you can cycle through the textboxes with the control statement.
    I add a small example for this. Maybe it's a possible solution for you.


    specci48
     

    Attached Files:

  6. Erel

    Erel Administrator Staff Member Licensed User

    You could also use:
    Code:
    compare=x.text & y.text & z.text
    if compare ="" then ...
    & - Concatenation character.
     
  7. derez

    derez Expert Licensed User

    groups

    It will be very efficient for at least one program of mine if there is a way to group together several controls (mainly textboxes) and perform operations on all of them using one command, for example - change the color of all the textboxes in the group, or like in this thread - check if the text is null.

    Of course, using the control method is possible but then I loose the textboxes specific names and programming becomes much more difficult then it is now...
     
    Last edited: Dec 20, 2007
  8. agraham

    agraham Expert Licensed User

    You could try putting the control names in an array and reference them as Control(Array(i)).Color
     
  9. sunnyboyj

    sunnyboyj Member

    thanks, great responses!
     
  10. derez

    derez Expert Licensed User

    Array

    thanks Agraham, I like your solution :)

    I implemented it on a group of 34 controls to change color and fontcolor - very efficient in saving code lines.

    I had to use for -next loop with index, I did not succeed in

    Control(boxes()).Color = 0,0,0 and got this error : "object does not contain a definition for ToLower "

    is it my fault or the compiler's ?
     
    Last edited: Dec 20, 2007
  11. agraham

    agraham Expert Licensed User

    I'm not sure what you mean but I meant
    Code:
    For i = 0 to x
      
    Control(boxes(i)).Color = RGB(0,0,0)
    Next
    Note the present of an array index and the RGB function compared to your line of code.

    EDIT:- I think I now see what you meant. You can't reference an entire array "in bulk", you need to iterate over it. If you look at my post suggesting this there is an index i for the array - I left out the For ... Next thinking it was obvious - Sorry!
     
    Last edited: Dec 20, 2007
  12. derez

    derez Expert Licensed User

    what I did and succeeded is the way you suggested, with the for-next loop, even without the RGB.

    what didn't work is the reference to the whole array, in contradiction to the documentation that says:

    "When you need to reference an entire array (not one item in the array) write the array's name followed by ()."
     
  13. agraham

    agraham Expert Licensed User

    Not using RGB is a syntax hangover from early versions and will not work with the next version of the compiler. Also if you use that synax in Globals it can mess up initialisation of other variables as we found out yesterday in another thread so I would advise using RGB.

    That is technically correct but rather obscure. To reference something means to make a pointer to it or take its' address. B4PPC cannot itself work directly with references but it can pass them to a library. So the syntax without an index would be used like this :-

    SomeLibraryFunction( somearray() )

    Would pass a reference to the array so within the library elements of the array could be accessed by array(somevariable).
     
  14. Erel

    Erel Administrator Staff Member Licensed User

    The old syntax will still be supported in the next version.
    However it is recommended to use RGB method instead.
     
  15. derez

    derez Expert Licensed User

    Thanks :)
     
Loading...