|
str is filled with an unknown value. 145.35 is an example only.
|
|
|
|
|
I was using "145.35" as an example as well. BTW, what is your locale? This does play a part into how the conversion routines try to to parse things. Is "." the decimal delimiter or the thousand delimiter for you?
ps. This does bring up an quirky point: Is Convert.ToSingle meant to be the IEEE supported float conversion while Single.Parse is the locale specific one?
|
|
|
|
|
It's the decimal one.
Single bring the same problem.
|
|
|
|
|
I've written a lot of code converting string values that are clearly "float like" and never had a problem. I guess the problem is deeper. I would investigate exactly what is the string you are feeding into it because I simply can't reproduce your problem. The only other thing I can think you are running into is some bad percision mojo but your example isn't sufficient to show it.
example code:
using System;
namespace tlarsen
{
public class test
{
public static int Main()
{
string s = " 145.35 ";
float f = Convert.ToSingle(s);
Console.WriteLine("s = " + s);
Console.WriteLine("f = " + f.ToString());
Console.WriteLine("1 + f = (should be 146.35) : " + (f + 1));
return 0;
}
}
}
|
|
|
|
|
Due to the local settings, application demands "," as delimeter not the "."
Now it works.
|
|
|
|
|
float.Parse(str) method should also work. Perhaps you might have committed some small mistake here and there. For testing it, create a new Windows Form project and place a button1 on that. In the click event-handler, put the following code:
private void button1_Click(object sender, System.EventArgs e)
{
string str = "145.35";
float x = float.Parse(str);
MessageBox.Show(x.ToString());
}
It works properly and the MessageBox shows the correct value of float variable as "145.35". If you use x in some expression such as x = x*2, again it will use the correct value. In the debug mode, when you check the value of x, again it shows the correct value. So please ensure that you use the proper coding, otherwise there is nothing wrong in the method.
|
|
|
|
|
Hi!
Is there a way of making a string html compliant (i.e. replacing german umlauts with the appropriate hex code), without hardcoding each character's translation.
|
|
|
|
|
Check out System.Web.HttpServerUtility.HtmlEncode(string)
Hope this helps
|
|
|
|
|
Thanks a lot! That was exactly what I meant. Although I must say that HttpServerUtility is only usable from within an ASP.NET application, for normal Windows apps HttpUtility has to be used.
|
|
|
|
|
Thank you for spending time here
You know in Visual Studio, when you move an object around such as a textbox, the cursor is changed to an arrow with a rectangle (the rectangle's size is equal to the size of the textbox) to indicate the new location of the textbox when you release the button..
I can change the cursor shape and all, but how do i draw that custom rectangle?
please help me out.
Elapid For The Win
|
|
|
|
|
anyone?
Elapid For The Win
|
|
|
|
|
What do you mean "custom rectangle"? You mean around a control? The designer is responsible for drawing that feedback mechanism (the border + handles). As for how they do it, there is a bunch of stuff inside System.Drawing that helps.
|
|
|
|
|
Thank you Tom for your reply.
I mean when you move a control (i.e Textbox) the Cursor is changed to an arrow with a rectangle which would show users that if they release the mouse, then the textbox will be moved in the place of the rectangle.
What I don't know is how to draw a rectangle with the cursor
please help me out
Elapid For The Win
|
|
|
|
|
Actually, the cursor doesn't change at all. What happens is the MouseMove event, the mouse buttons are polled to see if one is held down. If so, then a box representing the size of the control is drawn on the form, under the cursor.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thank you Dave.
I got that done
Elapid For The Win
|
|
|
|
|
Hi
I have a custom property updating another custom properety the code is as follows
<br />
public enum CodePageType { None, Swift, ASCII, Trade };<br />
public string RegularExpP<br />
{<br />
get { return regularEx; }<br />
set { regularEx = value; }<br />
}<br />
[Category("Custom Properties")]<br />
[DefaultValue(false)]<br />
public CodePageType Validate<br />
{<br />
get <br />
{<br />
if (type == CodePageType.ASCII)<br />
{<br />
RegularExpP = "Exp1";<br />
}<br />
if (type == CodePageType.None)<br />
{<br />
RegularExpP = "Exp2";<br />
}<br />
return type;<br />
}<br />
set {type = value;}<br />
}<br />
Now when i select the validate property the RegExpP property is set in the UI but its not getting updated in the Form1.Designer.cs Page.But its getting updated only the second time, and this time it sets the previous value i selected hat could be the problem
Regards
Deepak.s
|
|
|
|
|
I am working on a windows app and having some trouble getting type information by just the name. I have to load a file that will have several different type names (Type.FullName). When I call Type.GetType(fullname), it is always returning null, even for types that I would assume it wouldn't like System.Windows.Forms.TextBox. The only way that I can get it to return a type is if it is a local assembly, put it in format of 'Fullname,AssemblyName'. If it is not a local assembly, then I have to put it in the format of 'AssemblyQualifiedName'. This is ok, but it kinda screws some of the useability of the app. Does any one know a way around this? I know that I can use just the full name of the type if I am doing straight from the assembly reference (Assembly.GetType(fullname)), but I would prefer it if I didn't have to have a reference to the assembly to get the type (even though the assembly will be loaded at this point anyways). Any ideas would be greatly appreciated?
|
|
|
|
|
Can I ask what you are attempting to do? Type information is somewhat non-human friendly just because it is designed to be that way. Why are you asking the user for a type which may or may not be in any loaded assembly? Maybe you should instead offer a list of loaded types with a filter?
|
|
|
|
|
nevermind, i just altered the file format to allow the assembly name as well.
|
|
|
|
|
Hi
I have created web application to upload files. When the client uploades the files, the files should be put on to my server in a specific folder. Can this be done only through FTP or is there any other way to do it? The client could be in different place(one country) and the server could be in different place(another country). Can you send me the code for this?
|
|
|
|
|
Hi
I want to save pdf/tiff/bmp/jpg file formats in database and retrieve the same from database. i am using SQL Server 2000. I have a Windows form where i need to view these files. Right now i am using picturebox control. Files are saved to database and retrieved from database on to picturebox. But with picture box i can view the tiff files and not the pdf. Is there any way to view both tiff files and pdf files? Can you send the coding for this?
|
|
|
|
|
Did you ever get any information on this. I am having the same issue.
|
|
|
|
|
Hey!
I am building a program that recives data från a serail port and then puts it on streams to other units in the program.
Its inportant that this happens with no delay!
I have thougt of using regular stream, but i saw someone usning MemoryStream? maby MemoryStream is a better choce?
I need to be abled to write to this streams to.
What ar the diffrence between MemoryStream and regular stream?
BestRegards
Jimmy
|
|
|
|
|
Hey!
I have a incoming stream on a Serail port, i want to show this in a RichTextBox.
I have seen that i can load RichTextBox with a stream but it only loads whats in the stream at that moment?
Is there an easy way to let teh stream update the RichTextBox? or do i need to take the data out of the stream and then append to RichTextBox manualy?
And one other thing! i have tested to append data to my RichTextBox from another thread, but this is not posible? do i realy have to use the thread that created the RichTextBox? I am using delegates it another class to add data to the RichTextBox in the main form, this means that it will be another thread that adds data to the RichTextBox.
Best Regards
Jimmy
|
|
|
|
|
Hi,
I'm trying to send files (*.bmp;*.doc;*.gif;*.htm;*.html;*.jpg;*.pdf;*.tif;*.xls;*.txt) directly to a printer which should convert it to .tif with GhostScript.
I tried it with GhostScript, the PrintDocument Class, with the Image Class and through the console, but nothing works or just works for some files. I have a solution for converting the picture files, the txt files and the pdf files with the above mentioned methods, but it's a bit slow and not fully to my satisfaction or 100% right.
Isn't there a solution with which I can send every file type directly to the printer, or convert them direcly in the programm?
I hope you can help me.
Sorry when my english is bad
|
|
|
|