473,385 Members | 1,317 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

nested If statments!!

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
Jul 21 '05 #1
5 1711
Cor
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
///


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

Jul 21 '05 #2
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
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
-----Original Message-----
Hi Angelina,

Looking at the code I think I would do it in the way I have typed in directbeneath (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) asboolean
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
///


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

.

Jul 21 '05 #3
Cor
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
Jul 21 '05 #4
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
-----Original Message-----
Hi Angelina,

I did not understand that the textboxes where from a datagrid, but I dontthink 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 ifthere was an error and true if not
(understand it think it does, I did not test it, I have written it direct inthis mail, you have to test it yourself, but it is very standard, but therecan 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 twotextboxes, but not always and therefore the second can be nothing)(And do not be afraid, only the place(reference) of the textbox istransported 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 thetext 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
.

Jul 21 '05 #5
Cor
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


Jul 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ozzy | last post by:
Hi, Just a quick question. If i am writing a nested IF statment what is the order of the execution. i.e are the inner if statments evaluated first before the outer If statments? If the inner IF...
4
by: Jesper | last post by:
Hi, I would like to issue three statements to the database (mysql v4.1) each time the server starts up. Is there any built in way to do this? Like a init file to put them in? At the moment I...
3
by: Vinny Vinn | last post by:
I have used simple batch statments with C#.for example: string select = "select model from cars where id = ?;select * from trucks where model = ?"; where ? is a parameter whose value i have...
5
by: orencs | last post by:
Hello, I am using Microsoft.Practices.EnterpriseLibrary.Data. I am running the following sqlCommand = "SELECT var1 FROM table1 WHERE var2 IN (4,5,6) ; SELECT var3 FROM table2 WHERE var2 IN...
5
by: Angelina | last post by:
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...
25
by: GY2 | last post by:
I writing some documentation and I want to describe a common code structure which is used to step through all the items in a collection (e.g. each file in a subdirectory) while applying more and...
1
by: Syl | last post by:
Hello! Can someone verify this for me please. Should these 2 statments return the same result ? The 2nd one is the original, the first one is my re-write. Thanks : SELECT orders_status,...
2
by: lee | last post by:
Newbie question: I'm looking for the easiest way to run SQL statments in Access. I'm getting confused by th GUIs - I'm just looking forhow to run SQL on a table- thanks
2
by: ramdil | last post by:
Hi All Please help me .Hope i have described my problem clearly below. I have a condition where i need to update some data in table from the value taken from another table.So basically i need to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.