|
Umm, I'm not sure how much more specific I can be, but I'll try
Ok, I have a variable of type double, let's call it dNumber.
I want to create a string that represents that number. Let's call the string strFormatted.
The string must be formatted as follows:
the 1st character is a space
the next 7 characters represent the number
the string must always be 8 characters in length
here's some examples of correctly formatted strings.
12345678 <- characters in string
--------
1.34567
1234.67
0.23456
I figured the following function would do the trick:
string FormatToFortran( double dNumber )
{
return String.Format( " {0,7:g}", dNumber );
}
but unfortunately it doesn't. Format() seems to be ignoring the alignment section of the format string (the 7), and strings returned by FormatToFortran() are similar to the following:
130.312393712128
136.399493519436
121.295216530426
obviously, these aren't 8 characters in length.
So, I'm wondering what is wrong with my format string.
Hope that clarifies things. If not, feel free to ask away!
Cheers,
Pete
|
|
|
|
|
hi,
What i thought is correct. I got correct result.For me it's working properly.
i don't know why it is showing like that in your machine.
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
Argh! Really?
I'm using the VS 2005 beta. Maybe this is a bug in the .NET 2.0 runtime. Boo.
Just to double check, when you call FormatToFortran(), it /always/ returns a string of length 8, no matter what you put in?
Thanks for the help, by the way
|
|
|
|
|
OK, well I guess I managed to fix the problem by using the following format string:
String.Format(" {0,7:G6}", dNumber );
strange that the previous format string performed differently on different machines though.
|
|
|
|
|
I'm getting to grips with C#, but one thing still escapes me
If I have a number, 0x12345678, and I need to reorder it for some reason to 0x56781234, I could do this in C/C++
<br />
int i = 0x12345678;<br />
short *ps = (short*)&i;<br />
short s;<br />
<br />
s = ps [0];<br />
ps [0] = ps [1];<br />
ps [1] = s;<br />
i is then 0x56781234.
This sort of problem also pops up when a file has some binary data encoded in such a way that 3 bytes are used to represent a 4 byte int (PowerPoint does this if I remember correctly)
All attempts I've tried at this so far have resulted in unsafe code. I'd prefer a safe way, if this is possible.
Cheers
|
|
|
|
|
the only way i can recall now is to put your data in a string then manipulated it the way you want. after that cast it back.
i don't think there could be another way becuase you are accessing the memory directly here.
good luck!
|
|
|
|
|
How 'bout using the shift operators?
int i = 0x12345678;
i = (i << 16) + (i >> 16);
|
|
|
|
|
hi there,
i wonder if there´s a way to manipulate a window that i can only be dragged horizontal with mouse (i.e. vertical mouse movements are ignored).
any ideas? thanks, best regards
jkersch
|
|
|
|
|
|
well, i created a Bitmap as hwnd (a transparent images that resides on top of the screen (win32.getDC via native function in user32.dll) and i wonder how i can access window x and y position values and how i can get x and y of the mouse position.
is there something like a mousemove event with native win32 windows?
i have to bitmap hWnd to remain at the same x-position all the time.
and ideas?
thanks
jkersch
|
|
|
|
|
Has anyone used this? I have a very simple app that takes a xml file that I'd like to validate against a schema.
XmlValidatingReader(doc.InnerXml, XmlNodeType.Element, null);<br />
reader.ValidationType = ValidationType.Auto;<br />
reader.Schemas.Add(null, Server.MapPath(schema));<br />
reader.ValidationEventHandler += new ValidationEventHandler(ValidationHandler);<br />
while( reader.Read() );
It doesn't seem to matter what the xml is like, it never throws an exception. I've removed nodes in the xml and even passed in a xml file with a completely different structure and it passes right through.
|
|
|
|
|
try this
While objValidator.Read() And m_ValidationSuccess
End While
m_ValidationSuccess comes from validating call back
Bhaskara
|
|
|
|
|
Thanks for the VB
By implementing the ValidationHandler I can get any errors received during the validation. The problem is NO ERRORS are being generated.
|
|
|
|
|
I think I have discovered that the string function PadLeft in the 1.1 framework is broken. I experienced padding problems in my production app, so I built this simple program to test it. Form1 just contains a listbox name=listbox1 and the Items collection contains a string with 10 spaces in front of it.
private string[] texts = new string[5] {"Line One", "Line Two", "Line Three", "Line Four", "Line Five"};
private void Form1_Load(object sender, System.EventArgs e)
{
string item = this.listBox1.Items[0].ToString();
int len = 0;
for (int i=0; i<item.Length; i++)
{
if (item[i] != ' ')
{
len = i;
break;
}
}
for (int i=0; i<5; i++)
{
this.listBox1.Items.Add(String.Concat(texts[i], " unpadded"));
}
for (int i=0; i<5; i++)
{
this.listBox1.Items.Add(texts[i].PadLeft(len));
}
}
When executed, the padding eratically addes only one space and the third line is padded with nothing. All strings should have had 10 spaces padded in the left as per the framework documentation!!!
This signature left intentionally blank
|
|
|
|
|
theRealCondor wrote:
this.listBox1.Items.Add(texts[i].PadLeft(len));
This is your problem, PadLeft wants the total length, this would include what is already in the string which is why your results vary, each string length is different. The following works for me:
private void button_Click(object sender, EventArgs e)
{
string[] text = new string[]{"Line One", "Line Two", "Line Three", "Line Four", "Line Five"};
int len = 10;
char c = '.';
for(int i = 0; i < 5; i++)
box.Items.Add(text[i].PadLeft(len + text[i].Length, c));
}
- Nick Parker My Blog | My Articles
|
|
|
|
|
Re-reading the SDK I can see that they think they are stating this. Total length of string. Anyway --> this one gets inserted into the memory bank.
It is not the bugs that kill a programmer, it is the subtle errors that appear to be coded correctly.
Thanks Nick.
This signature left intentionally blank
|
|
|
|
|
Hi all!
Can anybody tell me where from to embed the Timeline control like one used in MS-Producer.I am studying DirectX 9.0 SDK documentation but havent found any clue yet.Any kind of help will be appreciated.
Thanks
|
|
|
|
|
I have a very typical problem. I am trying to create a user in activedirectory running in windows 2003 server. i am able to create user but when coming to setting password its not working.
the code :
String strPath = "LDAP://192.168.0.101:389/OU=100001,DC=Tserver,DC=local";
try
{
DirectoryEntry user = new DirectoryEntry(strPath, @"Tserver.local\administrator", "password", AuthenticationTypes.Secure | AuthenticationTypes.Sealing |AuthenticationTypes.ServerBind );
//create user
DirectoryEntry user = entry.Children.Add("cn=Test User", "user");
user.Properties["sAMAccountName"].Add("testuser");
user.Properties["sn"].Add("User");
user.Properties["givenName"].Add("Test");
user.Properties["description"].Add("Test account added with code.");
user.CommitChanges();
// User has to be saved prior to this step
user.Invoke("SetPassword", new string[] {"password1"} );
user.CommitChanges();
user.Close();
user.Dispose();
}
catch (Exception exx)
{
Response.Write("Exception: "+ exx.ToString() + " \n");
return;
}
Response.Write("Success: Password set.");
Error Description:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.FileNotFoundException: The network path was not found.
Source Error:
Line 127:
Line 128: // User has to be saved prior to this step
Line 129: user.Invoke("SetPassword", new string[] {"princeton"} );
Line 130: user.Properties["userAccountControl"].Value = 0x200;
Line 131: user.CommitChanges();
Source File: c:\inetpub\wwwroot\adminlogin\pages\information.aspx.cs Line: 129
Stack Trace:
[FileNotFoundException: The network path was not found.]
[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters) +0
System.RuntimeType.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters) +473
System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args) +29
System.DirectoryServices.DirectoryEntry.Invoke(String methodName, Object[] args)
AdminLogin.Information.btnSave_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\adminlogin\pages\information.aspx.cs:129
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()
I am looking for some help to solve this problem
I think this explains the problem well? Thank you in advance.
shambho Mahadeva
hap
|
|
|
|
|
99% of the time....when you get a System.Exception.FileNotFound it is due to the fact that you are trying to get an assembly and that assembly either does not exist on the target machine ... or it does exist but the assembly identifiers do not match.
For example: if you built your application and used System.Security.dll which had an assembly identifier of version 1.1.4322 but a service pack that your machine did not receive had version System.Security.dll at version 1.1.4325 then you would get that exception.
This signature left intentionally blank
|
|
|
|
|
But my dear friend i am able to create user add all other properties why not password. Is this System.Security.dll has some thing to do with setpassword native method alone. I dont know thats why i am posting this reply.
Kindly reply me
thanks in advance
anand
|
|
|
|
|
shambho wrote:
// User has to be saved prior to this step
user.Invoke("SetPassword", new string[] {"password1"} );
Your should be passing an Object[] instead:
Object[] pswd = new Object[]{"password1"};
However by default all code that executes from the local intranet or Internet zones is partially trusted and full trust is required. You might check into placing the AllowPartiallyTrustedCallers attribute on your code.
- Nick Parker My Blog | My Articles
|
|
|
|
|
hi friend,
actually i am not using
user.Invoke("SetPassword", new string[] {"password1"} );
but
user.Invoke("SetPassword", new object[] {"password1"} );
By mistake while i was trying different alternative you got this piece of code. even with object its giving the same error
|
|
|
|
|
Hello,
I'm working on a Mapi Agent using C#.
Everything works fine despite the fact I've to commit the nice Outlook Message
which is shown after Installing the Security Update for Microsoft if you try to send mails from other interfaces.
See the Knowledge Base Articel :
http://support.microsoft.com/default.aspx?scid=kb;en-us;263073
WD2000: Warning Message: "A Program Is Trying to Access ..." When You Send Mail Merge to E-mail After You Apply Outlook Security Update
and Information for Developers :
OL98: Developer Information About the Outlook E-mail Security Update
http://support.microsoft.com/default.aspx?scid=kb;EN-US;262700
The Problem is that I've to commit this windows automatically - because this agent should run by itself.
I already find out that I've to use the user32.dll with their functions FindWindow and SendMessage,
and that you have to use Spy++ to find out the WindowClass and the wParam and lParam in hex formate.
Indeed I'm right now at the point that I can find the window, and can send messages - WM_Command.
But the wNotifyCode is wrong, I've to send a BN_Clicked WM_Command but with my routine I send a Code 0 (send from a menue) to the Window
although I got the right hex codes.
So now my question : how can I send a BN_Clicked Message to the window?
Is there any other opportunity to commit the windows with "Yes"?
I'm grateful for any advice.
Here are some code snippets :
----------------------------------------------------------------------------------
The class for the user32.dll Import and their functions :
----------------------------------------------------------------------------------
public class Win32
{
public const int WM_COMMAND = 0x111;
[DllImport("User32.dll")]
public static extern int FindWindow(string strClassName, string strWindowName);
[DllImport("User32.dll")]
public static extern int FindWindowEx(int hwndParent, int hwndChildAfter, string strClassName, string strWindowName);
[DllImport("User32.dll")]
public static extern Int32 SendMessage(
int hWnd, // handle to destination window
int Msg, // message
int wParam, // first message parameter
[MarshalAs(UnmanagedType.LPStr)] string lParam); // second message parameter
[DllImport("User32.dll")]
public static extern Int32 SendMessage(
int hWnd, // handle to destination window
int Msg, // message
int wParam, // first message parameter
int lParam); // second message parameter
}
----------------------------------------------------------------------------------
----------------------------------------------------------------------------------
The Main Routine with the calling routines :
----------------------------------------------------------------------------------
System.Int32 iHandle
// Finding the window :
iHandle = Win32.FindWindow("#32770", "Microsoft Office Outlook");
// Send a Message
Win32.SendMessage(iHandle, Win32.WM_COMMAND, 0x000012A6, 0)
----------------------------------------------------------------------------------
********************
There are only ten types of people in the world.
Those who understandy binary and those who do not
|
|
|
|
|
I use A data grid which has a datasource and a datamember is connected
to an access database.
I make update to the datagrid by using:
oledbdataAdapter1.update(dataset11.tables[0]) ;
where user make all he wants then press a button to execute the previous
line of code.
the problem is the an exception may ocuur:
"Concurrency Violation: the update command affected 0 rtecords"
I don't know what is the reason of this exception as it appears rarelly.
|
|
|
|
|
check if there are any foreign key relations existing.
Bhaskara
|
|
|
|
|