nested If statments!!

  • Thread starter Thread starter Angelina
  • Start date Start date
A

Angelina

Hi,

I need some help in writing a 'if-then-else' statement.
I currently have wrote one that looks something like this..

If Combobox1 = xxx and textbox1 <> "" then
'run stored procedure 1 to obtain the relevant
records and place them in a datagrid.
elseif combox1 = yyy and textbox2 <> "" or textbox3 <> ""
then
'run stored procedure 2 to obtain the relevant
records and place them in a datagrid.
elseif combox1 = zzz and textbox4 <> "" then
'run stored procedure 3 to obtain the relevant
records and place them in a datagrid.


what i want to do is to also include some nested if
statments to ensure that a message box is displayed if any
of the textboxes (Where the parameter is obtained for the
stored procedure) is empty.

I also wanted to know how to diplay a message if the
result of the sproc is empty.

any advise and help is appreciated.

thx in advance
 
Hi Angelina,

Looking at the code I think I would do it in the way I have typed in direct
beneath (so not tested or something)

This procedure you can make endless therefore.

I hope this solves your problem?

Cor
\\\
if Combobox1.text = xxx then
if myproc(textbox1, nothing) = true then
'run stored procedure 1
end if
elseif
if Combobox1.text = yyy then
if myproc(textbox2, textbox3) = true then
'run procedure 2
etc etc
////
\\\
Private Function MyProc (byval text1 as textbox, byval text2 as textbox) as
boolean
if Not text2 Is Nothing then
if text2.text ="" then
messagebox.show(error)
return false
end if
end if
if text1.text = "" then
messagebox.show(error)
return false
end if
return true
end function
///
 
Hi Cor,

thx for the code,
Im a liitle confused on how MyProc works though!!.
How do i ensure that for the second part of my if
stataments a message box is displayed if either one of my
textboxes are empty (Or both)?? (i.e i am using 2
textboxes in this case so that the user can search by
their first and last name)
Does the code u showed me below only meant for a single
textbox? if so how can it be modifed?

also y do have a NOT for the first textbox (text2) and not
for text1?? .....

if Not text2 Is Nothing then
if text2.text ="" then
messagebox.show(error)
return false
end if
end if
if text1.text = "" then
messagebox.show(error)
return false
end if
return true
end function


One final question.....
How do i integrate an if statment into your code that
displays that the results of the query are empty? At the
moment the datagrid just shows up empty with just the
column headings? Im not to sure on how to code this?
Can the if statment u provided me be extended to include
any number of if staments e.g...

if Combobox1.text = xxx then
 
Hi Angelina,

I did not understand that the textboxes where from a datagrid, but I dont
think that does make a difference.

I take some rows from my code

if myproc(textbox1, nothing) = true then
test if the result from the action done in myproc is true, it is false if
there was an error and true if not
(understand it think it does, I did not test it, I have written it direct in
this mail, you have to test it yourself, but it is very standard, but there
can be some thinking or typing errors)

You can give to myprocedure two parameters, in the first test it was
"textbox1" and "nothing" (because in your example there were one or two
textboxes, but not always and therefore the second can be nothing)
(And do not be afraid, only the place(reference) of the textbox is
transported not the textbox itself)

In the procedure is
Private Function MyProc (byval text1 as textbox, byval text2 as textbox)
"text1" a reference to the first by you supplied textbox
"text2" a reference to the second supplied textbox (can also be nothing)

if Not text2 Is Nothing then
because you can give "nothing" as textbox (no reference adres)
In other words "If there is a textbox supplied then"
(I wish there was something in the syntax as
"If text2 Is Something" but it is not.)

You give always a first textbox so that has not to be tested, althought the
text can be empty.

if text2.text =""
This is an supplied textbox withouth text

return false
is the only thing you want to know before you start the SP

return true
There where in both(or one) textbox texts so you can go on.

I hope this explains it?

Cor
 
Hi Cor,

thx for taking your time to explain your code. U have been
a great help :o)
As u can tell im a beginner on vb.net

Can i just ask u if u know how i can check if a datatable
is empty.

i.e i want to include a statment in my if statment that
checks if the results of the query is empty. If the result
is empty i want a label displayed to the user that
states 'no records were found' rather than just displaying
an empty datagrid.

thx in advance
 
Hi angelina,

if ds.tables(0).count = 0
then there is no table
if ds.tables(0).rows.count=0
then there are no rows,

I do not know what it is in your case.

If you get an error message, because i do not know how you load the
datatable in your dataset.
But I think it is one of these.

Just try.

I hope this works?

Cor
 
Back
Top