|
how do you turn a 'Text' into a number variable since I wanted to get some input through textboxes and do mathamatical operations on them, and what is the namespace for mathamatical operations by the ways?
|
|
|
|
|
Sry I forgot to mention Im using VS.NET 2005 beta 1 with the .net framework v2.0 so if anyone has this problem email me..
|
|
|
|
|
Sry again, I figured it out but now I have another (?) how would you convert a string into an integer or double or whatever??
|
|
|
|
|
By using the Convert[^] class.
Paul Lyons, CCPL Certified Code Project Lurker
|
|
|
|
|
Thx but now I don't have any errors exept
Error 3 Cannot implicitly convert type 'uint' to 'string'
|
|
|
|
|
This is something like what I have.
UInt32 A = 0;<br />
UInt32 O = 0;<br />
A = Convert.ToUInt32(tbA.Text);<br />
O = Convert.ToUInt32(tbO.Text);<br />
tbResults.Text = A/O;<br />
tbResults.Text = Math.Pow(A, 2)/Math.Sqrt(O);
Error 3 Cannot implicitly convert type 'uint' to 'string'
|
|
|
|
|
just use a cast...
UInt32 A = 0;<br />
UInt32 O = 0;<br />
A = Convert.ToUInt32(tbA.Text);<br />
O = Convert.ToUInt32(tbO.Text);<br />
tbResults.Text = (string)(A/O);<br />
tbResults.Text = (string)(Math.Pow(A, 2)/Math.Sqrt(O));
if these inputs are coming from a textbox, which it looks like they are, you should consider putting a try/catch block around those Convert statements to make sure the input is valid:
UInt32 A = 0;<br />
UInt32 O = 0;<br />
try<br />
{<br />
A = Convert.ToUInt32(tbA.Text);<br />
}<br />
catch<br />
{<br />
tbA.Text = "0";<br />
A = 0;<br />
}<br />
try<br />
{<br />
O = Convert.ToUInt32(tbO.Text);<br />
}<br />
catch<br />
{<br />
tbO.Text = "0";<br />
O = 0;<br />
}<br />
tbResults.Text = A/O;<br />
tbResults.Text = Math.Pow(A, 2)/Math.Sqrt(O);
I have always used Parse, such as UInt32.Parse(string); instead of Convert, so I'm not sure if it will handle incorrect strings or not, but this is good just to make sure. Obviously you don't have to use 0 to assign to A and O in the try/catch blocks, you can make them whatever you want. Good luck!
|
|
|
|
|
DougW48 wrote:
have always used Parse, such as UInt32.Parse(string); instead of Convert,
Convert is safer than parse IIRC, in the sense that it wont throw an exception. Could be wrong
top secret xacc-ide 0.0.1
|
|
|
|
|
You're probably right, I've never used Convert. Thanks!
|
|
|
|
|
Error 1 Cannot implicitly convert type 'uint' to 'string'
It still says that even if I had it like DougW48's example... I don't know can this be a bug since I'm testing out Visual Studio 8 2005 beta 1
|
|
|
|
|
NVM I got it, anyways Thx for the quick help I got at codeproject, will be visiting this site more often;P
|
|
|
|
|
Hello,
i am developing a web service in c# and i have the following problem. The requests and the responses are signed with CAPICOM.SignedData, when the server receives the request and verify the signature, he builds a response which is serialized and signed before going to the client. When the client receives the response, the signature is correctly verified, but when the data are going to be deserialized comes the exception InvalidaCastException (when i try to cast the object returned bu the formatter to the data type defined in a separated class).
Thank you in advance for your help!
|
|
|
|
|
Just an idea. You probably checked this already.
Make sure that both your webservice and your client reference the same library (data type that is serialized). Make sure that you have identical version of the libary on both the client and webservice.
|
|
|
|
|
Could we see some code? probably the entire function that includes the part where InvalidCastException occurs?
|
|
|
|
|
Hi
How can I replace the Task Managar with another Task Manager.
I mean, when I press Ctrl+Alt+Delete my Task Manager opens.
Thanks
Mohammad-Reza Taikandi(HM)
|
|
|
|
|
Ctrl+Alt+Delete is a special key combination that cannot be intercepted (at least on NT). On windows 9x branch it might be possible but i haven't checked.
I strongly recomend against replacing anything that is considered standard windows UI, unless you are trying to do something that is specifically designed to modify the entire user experience.
|
|
|
|
|
Hi
I try to execute an *.exe file that i renamed it to *.sec unfortunately
Process.start() method can't execute it.
Is there any other way to do this?
Thanks
Mohammad-Reza Taikandi(HM)
|
|
|
|
|
Of course *.sec is not going to execute. Its not a executable extension.
Another way to do this would be to rename the filename part instead of the extension. ie Myprogram.exe to abcdef.exe or myprogram.sec.exe
|
|
|
|
|
Hi I have a text file with the following layout:
[PROFILE1]
SYSTEM=home
DEBUG=true
[PROFILE2]
SYSTEM=laptop
DEBUG=true
What I want to do is insert a new line after the FIRST DEBUG LINE in PROFILE1 so the whole of PROFILE2 then moves down a line. My problem is that I keep overwriting the start of PROFILE2 e.g
[PROFILE1]
SYSTEM=home
DEBUG=true
testline
2]
SYSTEM=laptop
DEBUG=true
Can you take a look at my code and see what I am doing wrong!!
if( File.Exists( "d:\\networld.ini" ) )
{
long lFilePos = 0;
string sLine = null;
FileStream fs = new FileStream("d:\\networld.ini",
FileMode.Open, FileAccess.ReadWrite);
// Create a new streams to read and write to the file
StreamReader sr = new StreamReader( fs );
StreamWriter sw = new StreamWriter( fs );
while( sr.Peek() > -1 )
{
sLine = sr.ReadLine();
if( sLine.CompareTo( "[" + "PROFILE1" + "]" ) == 0 )
{
lFilePos = sLine.Length;
while( sr.Peek() > -1 )
{
sLine = sr.ReadLine();
lFilePos += sLine.Length + 2;
if( sLine.CompareTo( "" ) == 0 )
{
fs.Seek( lFilePos,SeekOrigin.Begin );
sw.Write( "testline\r\n" );
sw.Flush();
break;
}
}
}
}
sr.Close();
fs.Close();
MessageBox.Show( "Finished Writing To File." );
}
Thanks a million.
|
|
|
|
|
Why would not you consider the old fashion way read the old file and create
simultaneously a new file -> copy each line while they are identical, then insert the change and so on. When you finish you can delete the old file and rename the new file to the old name. You can use File class. I think it will save you much trouble
DavidR
|
|
|
|
|
IrishSonic wrote:
Can you take a look at my code and see what I am doing wrong!!
You are doing nothing, you are just using it wrong. Best would be to read the file into a stringbuilder instance and just insert the text, then just rewrite the file. There is no point in doing it directly in the file, because your data cannot be "shifted" forward. Imagine trying this (what u wanna do) on a 1Gbyte file....
top secret xacc-ide 0.0.1
|
|
|
|
|
Ok guys, comments definitely taken on board!!
But can't believe that if you want to insert a new line at a specific point, it means rewriting the file to a new file and deleting the old one.
Is this the industry standard way its always done??
So what if I wanted to just update a line?? Would I still have to write to a new file and delete old??
Also could I trouble you for maybe a quick example of placing everything into a StringBuilder with the new line.
Thanks.
|
|
|
|
|
Did you ever figure this out? I need to edit a line in a text file and I do NOT want to write everything to a new file to do this.
Any help would be appreciated!
Sue
|
|
|
|
|
Hi
I am developing an invoicing application, and I need to know how to
do simple multiplication and addition on a datagrid with values
from different columns ie Qty * Price = SubTotal
Any help would be appreciated
Thanks
chris-s@54.co.za
|
|
|
|
|
If u r having any associated DataSource for that grid like Data Table or Data Set u can set particular column value in particular row...That will automaticalle be updated in the grid.
If u want to update All the Rows ata time u can even use loops like as follows
int i;
for(i=0;i< dt.Rows.Count;i++)
{
dt.Rows[i][2]=Convert.ToInt32(dt.Rows[i][0]) * Convert.ToInt32(dt.Rows[i][1]);
}
Here in ur case the
first column is QTY
Second Column is Price and
third column may be SubTotal
|
|
|
|