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

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
 

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)?
 

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.
 

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
 

Attachments

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:

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:

agraham

Expert
Licensed User
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 ?
I'm not sure what you mean but I meant
B4X:
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:

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 ()."
 

agraham

Expert
Licensed User
even without the RGB.
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.

"When you need to reference an entire array (not one item in the array) write the array's name followed by ()."
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).
 
Top