The codes below is part of my project in C# Compact Framework. I want to parse the values of textbox txtIP and txtPort to another form where my socket connection occurs. However, im unable to parse the IP & Port values as it appears empty and produce an error. How can i avoid the error and allow the form to parse values to another?
Form1 Codes:
private void LoadSettings()
{
string strIp;
string strPort;
string path = @"\My Documents\Config.txt";
if (File.Exists(path))
{
using (StreamReader sr = File.OpenText(path))
{
strIp = sr.ReadLine();
strPort = sr.ReadLine();
txtIP.Text = strIp;
txtPort.Text = strPort;
sr.Close();
}
}
}
Jan MontanoPosted May 30, 2007, 5:53 AM
Or if that's not what I'm talking about. Just check first if the string is not null before assigning the value to the textbox.
if (strIp != Null) {txtIP.Text = strIp;} if (strPort != Null) {txtPort.Text = strPort;}
OR you could use the conditional operator
txtIP.txt = strIp == Null ? "" : strIP; txtPort.txt = strPort == Null ? "" : strPort;