|
Subtracting an int from a float that's believed to be a int always returns an int, because ascii values are ints.
|
|
|
|
|
I guess it'd be better if you used Console.ReadLine() and then use float.TryParse() on the resulting string.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
float.TryParse() needs 2 arguments: at first the string that is wanted to be converted, and the second I think is the variable I want to give the resault to.
string s;<br />
double x;<br />
s = Console.ReadLine();<br />
float.TryParse(s,x);<br />
Console.Write(x);
The compiler reacts with two errors:
2-argument: can't be converted from "double" into "float"
method has illegal arguments
Thanks.
|
|
|
|
|
Hello,
For the first error the compiler says it all.
you have to use float instead of double or use double.TryParse.
Second error is, that the second parameter is an out parameter and has to be marked like that.
string s = "";
float x = 0;
s = Console.ReadLine();
if(float.TryParse(s, out x))
Console.Write(x.ToString());
Hope it helps!
All the best,
Noch einen schönen Tag,
Martin
-- modified at 11:48 Wednesday 4th July, 2007
|
|
|
|
|
The question is, why use Float.TryParse() is you're dealing with Ascii values?
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
i use usb-rs232 cable.and i have already install its driver.what must i do for using serialport in Windows Vista?i use visual studio 2005.must i download servispack?cause i have used XP,and same codes on C# was working.now what must i do?
|
|
|
|
|
I am a newbie, and I am starting to use the C# language, and I need a little help.
Here goes:
Main Form:
I put a textbox where card number should be inputted. When the user presses the Enter key it should look into the database (table) the value of the textbox.
Condition is:
If only one (1) item found, the information will be displayed on the Main Form other textboxes.
Otherwise if two or more items found, it will pass the card number to Form 2.
Form 2: will be shown if Main Form calls
Receive the card number passed by Main Form and search again the database (table) and display the items found on the datagridview. Then the user should select one (1) item, and pass back the single item with the complete (full) card number selected on the Main Form.
My questions:
How will I get the value of the current cell that I selected?
How will I pass back the value I selected to the Main Form?
How will Main Form receive the data being passed by Form 2?
Many thanks!
Form 1:
public partial class MRRMainForm : Form
{ // start partial class MRRMainForm
public String myConString = @"Provider=VFPOLEDB.1;" +
@"Data Source=" + D:\\MyMaintable.DBF";
public String cardNumber;
OleDbConnection con;
OleDbDataAdapter da;
OleDbCommand cmd = new OleDbCommand();
DataSet ds = new DataSet();
String commandSearch;
public MRRMainForm()
{
InitializeComponent();
}
private void txtCardNumber_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
// will trap other keys later..
//case Keys.
// break;
case Keys.Enter:
findCardNumber();
txtDescription.Focus();
break;
} // end switch
}
private void findCardNumber()
{
commandSearch = "Select * from MyMaintable where substr(prod_code,6,7)=\"" + txtCardNumber.Text + "\"";
con = new OleDbConnection(myConString);
cmd.CommandText = commandSearch;
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
da = new OleDbDataAdapter(cmd);
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows.Count > 1)
{
cardNumber = txtCardNumber.Text;
MultiplesFound myMF = new MultiplesFound(cardNumber);
myMF.myCardNumber = cardNumber;
myMF.ShowDialog();
}
else
{
txtProductCode.DataBindings.Add("text", ds.Tables[0], "prod_code");
txtDescription.DataBindings.Add("text", ds.Tables[0], "prod_desc");
txtModelNumber.DataBindings.Add("text", ds.Tables[0], "model_no");
}
}
else
{
MessageBox.Show("Not exist", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
} // end partial class MRRMainForm : Form
Form 2:
public partial class MultiplesFound : Form
{
public MultiplesFound(String myCard)
{
InitializeComponent();
}
public String myCardNumber;
private void MultiplesFound_Load(object sender, EventArgs e)
{
OleDbConnection con;
OleDbDataAdapter da;
OleDbCommand cmd = new OleDbCommand();
DataSet ds = new DataSet();
String commandSearch;
String myConString = @"Provider=VFPOLEDB.1;" +
@"Data Source=" + "D:\\ MyMaintable.DBF";
textBox1.Text = myCardNumber;
commandSearch = "Select * from MyMaintable where substr(prod_code,6,7)=\"" + myCardNumber + "\"";
con = new OleDbConnection(myConString);
cmd.CommandText = commandSearch;
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
da = new OleDbDataAdapter(cmd);
da.Fill(ds);
dataGridView1.AutoGenerateColumns = false;
int newColIndex = dataGridView1.Columns.Add("prod_code","Code");
dataGridView1.Columns[newColIndex].DataPropertyName ="prod_code";
newColIndex = dataGridView1.Columns.Add("prod_desc","Description");
dataGridView1.Columns[newColIndex].DataPropertyName = "prod_desc";
newColIndex = dataGridView1.Columns.Add("model_no", "Model Number");
dataGridView1.Columns[newColIndex].DataPropertyName = "model_no";
dataGridView1.Columns["prod_code"].Frozen = true;
dataGridView1.DataSource = ds.Tables[0];
}
private void btnOK_Click(object sender, EventArgs e)
{
// I’m lost here!
}
private void dataGridView1_DoubleClick(object sender, EventArgs e)
{
// I’m lost here, either!
}
} //end class
BM
|
|
|
|
|
Maybe look at a public method on form2 as your entry point from form1, in that public method you use as the entry point use a ref variable that will enable you to use the variable in form2 and what ever you changed it to in form2 it will return that value back to form1.
He who laughs last is a bit on the slow side
|
|
|
|
|
1. For the first task, you can capture any suitable event of the
DataGridView in which you can get the content of the selected cell like
CellClick etc
2. To pass back the data to MainForm
There are many ways to do it. I choose the simplest one.
Create public properties in Second form and while closing this form, set the values of those properties with the selected values.
3. To get the data passed from form2
When the form2 closes, read the public properties created in step2
|
|
|
|
|
Just have the MultiplesFound form expose a public property indicating the row that was selected by the user.
<br />
if (ds.Tables[0].Rows.Count > 0)<br />
{<br />
int SelectedRow = 0;<br />
if (ds.Tables[0].Rows.Count > 1)<br />
{<br />
cardNumber = txtCardNumber.Text;<br />
MultiplesFound myMF = new MultiplesFound(cardNumber);<br />
myMF.myCardNumber = cardNumber;<br />
myMF.ShowDialog();<br />
SelectedRow = myMF.SelectedRow;<br />
}<br />
txtProductCode.DataBindings.Add("text", ds.Tables[SelectedRow], "prod_code");<br />
txtDescription.DataBindings.Add("text", ds.Tables[SelectedRow], "prod_desc");<br />
txtModelNumber.DataBindings.Add("text", ds.Tables[SelectedRow], "model_no");<br />
<br />
}<br />
Jeff Clark
Systems Architect
JP Clark, INC.
Columbus, Ohio
|
|
|
|
|
i getting this error message in my project
Control 'ctl00_cphContent_ctl00_grdReport' of type 'GridView' must be placed inside a form tag with runat=server.
Pls help me
kankeyan
|
|
|
|
|
What part of that don't you understand? Also, if you don't post your code, how are we supposed to tell you how to correct it?
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
protected void Page_PreRender(Object o, EventArgs e)
{
if (IsPostBack.Equals(false))
{
calFrom.SelectedDate = System.DateTime.Today;
calTo.SelectedDate = System.DateTime.Today;
}
}
protected void calFrom_SelectionChanged(object sender, EventArgs e)
{
blnCallFrom = true;
}
protected void calTo_SelectionChanged(object sender, EventArgs e)
{
blnCallTo = true;
}
protected void btnExcel_Click(object sender, EventArgs e)
{
// Set the content type to Excel
Response.ContentType = "application/vnd.ms-excel";
//Turn off the view state
this.EnableViewState = false;
//Remove the charset from the Content-Type header
Response.Charset = String.Empty;
Response.AddHeader("content-disposition", "attachment; filename=" + calFrom.SelectedDate.ToString("YYYYMMdd") + ".xls");
value is not posted in the calfrom date too
System.IO.StringWriter myTextWriter =new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter myHtmlTextWriter = new System.Web.UI.HtmlTextWriter(myTextWriter);
grdReport.RenderControl(myHtmlTextWriter);
error is coming here
//grdReport.RenderControl(myHtmlTextWriter);
//Write the HTML to the browser
Response.Write(myTextWriter.ToString());
//End the response
Response.End();
}
}
kankeyan
|
|
|
|
|
The problem is with the ASPX, not the CS file. Do what the compiler suggests, and if you stil face problems, post the relevant ASPX code. In the right forum.
Cheers,
Vıkram.
After all is said and done, much is said and little is done.
|
|
|
|
|
First This is an asp.net question so you should have posted it in the correct forum.
And regarding the error it states that the gridview control has to be inside the form control which should have runat=server attributes.
Apurva Kaushal
|
|
|
|
|
how to delete a string from a string array.
|
|
|
|
|
Have a look at String.Replace method but remember that it will delete all occurrences from the string
|
|
|
|
|
you want to diminsish the size of the array or put a null or "" instead?
|
|
|
|
|
Hello,
I would suggest to use the System.Collections.Specialized.StringCollection class instead.
All the best,
Martin
|
|
|
|
|
You can also use StringBuilder. It depends how many times you will use it
|
|
|
|
|
Hello,
I wouldn't prevere the StringBuilder as an alternative to a string[].
I would miss methods like Contains.
Allt he best,
Martin
|
|
|
|
|
hello,
Thanks my problem solved
|
|
|
|
|
|
You can't easily. You'd have to copy the array to a second array leaving out the string you don't want.
Just use List<string> instead.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Hi,
I am trying to learn C# for a few months. I have managed writing my own classes and developped a few little .NET applications. My Pc has .NET FrameWork of ver: 2.0 .
Recently I have a need to create a new project (In Visual Studio - 2005) for some kind of small devices that runs Windows CE and have Compact FrameWork. In Visual Studio 2005 I do this steps "File\New\Project" and choose "Visual C# \ Smart Device" and <pocket pc="" 2006=""> Or <widnows ce="" 5.0=""> as project type, and choose <device application=""> .. Just to new a project for mobile devices.
Unfortunately creating fails with this message ("This Project requires .NET Compact FrameWork v2.0, whics is not installed on this machine"). And also I tried Device Application(1.0) but the result is an error. Althoug I use C#, just to test I tried this in Vb.net but I failed creating a new Device App. project.
What does it mean ? Should I install Compact FW 2.0 on my PC, which seems strange to me ?
And I also should mention that while I was intalling Visual Studio-2005 with a Custom Instalation in which I only not choosen the J# components. I am sure that I selected all other compnents (Vb.net, C#, Web programming Tools, Device porgramming Capabilities.. things like that )
Thanks for all in advance.
|
|
|
|