hey

Has the name entered in the name TextBox at least one
char?.
If yes, return true. The out parameter will have a valid
value returning to the caller.
If no
show a message box with a friendly error message
Set the focus to the textbox
return false

this is what im going to do. i know im going to do a if and else but dont know how im going to type it so it okej if its only one char. I look around and i find that string.IsNullOrEmpty can help here but i dont know really how to type the code so i hope anyone can help me

Take a look at this link and give it a go. Bare in mind that you can get the length of the text box value by using:

myTextbox.Text.Length

(use this in your if statement).

okej so you meen if if (txtname.Text.Length >0) but how do i do the rest if its true The out parameter will have a valid
value returning to the caller. the celler i fink it what the meen is my listbox

The caller can be anyone. You can't assume it's your listbox, or a form, or a polka-dotted pink elephant.

So you may have a method called "ValidateTextbox". It can accept an argument of type TextBox and has an out parameter of type String. I have to guess here because you haven't specified what a valid value is.

So from what I've said, and what Chris said, you should be able to construct a valid method that:

A) Accepts a TextBox to validate as an argument
B) Has an out paramter of type String to send back to the caller
C) Checks the textbox according to your specification
D) Sets the out parameter to some valid value
E) Returns your Boolean

In this case D & E generally happen at the same time as a consequence of step C

Yes you if statement should look like:

if (txtName.Text.Length > 0)
{
 // this is where you should write the code that you want to execute if the text box has more than 1 charactor in it
}
else
{
// this is where you should write the code that you want to execute if the text box has 0 charactors in it
}

I'm sorry i can't understand anything after "how do i do the rest if its true". Can try to be a little clearer and post the code you have for this so far in code brackets please so i can get a better idea of what your asking.

Thanks

okej this code is going to be in a textbox where you enter your name and the name of it going to be printend on a listbox after you click on a butten and when you press the butten and have nothing in it the error going to com up. the code is going under
private bool ReadAndValitateName(out string name). so i need to do so if its true its going to return it and false under else and return it

Judging by the fact that i have pretty much given the code to go into the method and haven't shown us your code yet i'm guessing you haven't attempted this yourself and you want us to give you the code rather than doing some research on the likes of the MSDN website and attempting it yourself.

Take what Ketsuekiame and I have said so far into account and give it a go yourself first.

commented: Helpfull! +15
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.