|
Why are you asking this here?? It's a question specific to Teleriks controls. Ask them about it, here[^].
|
|
|
|
|
need to do a console application that shows arabic numerals next to their roman counter part. I'm lost on the conversion part getting it into another method and how that works? Just need to know where to start.
|
|
|
|
|
That is best broken into two parts:
0) Parsing the arabic numerals into a variable -- for which you may want to use System.Int32.TryParse .
1) Converting the value to Roman numerals.
The following will convert the value 42 into Roman numerals:
new System.String ( 'I' , 42 )
Compressing the value is left as an exercise.
|
|
|
|
|
thanks for the help but i guess now the problems is looping it so that they show counting down this is what i have.
namespace ConsoleApplication1
{
class Program
{
public static string ToRoman(int i)
{
if (i <= 0) return "";
int[] Nums = { 1 , 4 , 5 , 9 , 10 , 40 ,
50, 90 , 100, 400, 500, 900, 1000};
string[] RomanNums = {"I", "IV", "V", "IX", "X", "Xl",
"l", "XC", "C", "CD", "D", "CM", "M"};
string sRtn = ""; int k = i;
for (int j = Nums.Length - 1; j >= 0; --j)
{
while (k >= Nums[j])
{
k -= Nums[j];
sRtn += RomanNums[k];
}
}
return sRtn;
}
static void Main(string[] args)
{
for( int Nums = 1; Nums <= 4000; Nums++)
{
Console.WriteLine(Nums + RomanNums[]);
}
|
|
|
|
|
Salomon Velazquez wrote: sRtn += RomanNums[k];
May I suggest a System.Text.StringBuilder instead?
You don't need k .
How about using an array of Tuple<int,string> rather than two arrays? And make it a static readonly field.
The for loop ought to stop when the value reaches zero, then you can eliminate the first if statement.
Your code won't produce MIM for 1999.
|
|
|
|
|
Private Sub UpdateSecurityStatus(ByRef device As deviceStruct, ByVal w128 As Int16)
device.ATAdeviceInfo.MasterPasswordCapabilty = (w128 >> 8) And 1
device.ATAdeviceInfo.EnhancedSecurityErase = (w128 >> 5) And 1
device.ATAdeviceInfo.SecurityCountExpired = (w128 >> 4) And 1
device.ATAdeviceInfo.SecurityFrozen = (w128 >> 3) And 1
device.ATAdeviceInfo.SecuirtyLocked = (w128 >> 2) And 1
device.ATAdeviceInfo.SecurityEnabled = (w128 >> 1) And 1
device.ATAdeviceInfo.SecuritySupported = w128 And 1
End Sub
w128 = 41 when this is called.
What it the '>>' and what does the 'And 1' mean. How do I write this in C#?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
The VB.NET expression:
(w128 >> 8) And 1
means, shift the value of variable w128 right 8 bits and then AND the resulting value with 1. Thus if w128 contains the binary value 0101100100 the result would be 1. In C# you would write this as:
(w128 >> 8) & 1
So these expressions are just matching certain bits in the w128 variable and using them to set flags in device.ATAdeviceInfo .
[edit]
See here[^] for information on VB.NET operators.
[/edit]
|
|
|
|
|
Ahh ok. Thanks
If it's not broken, fix it until it is
|
|
|
|
|
The full conversion is:
private void UpdateSecurityStatus(ref deviceStruct device, Int16 w128)
{
device.ATAdeviceInfo.MasterPasswordCapabilty = (w128 >> 8) & 1;
device.ATAdeviceInfo.EnhancedSecurityErase = (w128 >> 5) & 1;
device.ATAdeviceInfo.SecurityCountExpired = (w128 >> 4) & 1;
device.ATAdeviceInfo.SecurityFrozen = (w128 >> 3) & 1;
device.ATAdeviceInfo.SecuirtyLocked = (w128 >> 2) & 1;
device.ATAdeviceInfo.SecurityEnabled = (w128 >> 1) & 1;
device.ATAdeviceInfo.SecuritySupported = w128 & 1;
}
If you have conversions to do just go here: http://www.developerfusion.com/tools/convert/vb-to-csharp/[^] - it's a free online Vb to C# and vice versa converter. I used it for teh above, and use it for answering VB questions in QA. It's not perfect, but it gets a good percentage of it done. If it compiles in VS, it will probably convert automatically.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Thank you
If it's not broken, fix it until it is
|
|
|
|
|
|
How to set default textbox value in C#.net
|
|
|
|
|
What do you mean by the default textbox value? If it's just a value when the form displays, simply set the Text property as in userName.Text = "No user"; . Is it something more complicated that you are after?
|
|
|
|
|
sir, i'm using textbox in my project having calculating some value.
Noe if user hv'nt entered any value, then I wish to set default value as "0".
plz suggest me something.
|
|
|
|
|
Check if the user entered a value when the textbox looses focus. If not, set aforementioned property to '0'.
If this sounds "complex", then you probably want to spend some time at the library with a good book on the subject.
Bastard Programmer from Hell
|
|
|
|
|
Use the Properties window to set the 'Text' property to 0. This could be set as default when your form initializes. When the textbox loses focus add a validation. This should suffice. Alternatively I suppose you can set the text box to accept numbers only.
Sunil
|
|
|
|
|
Hi am using one dll in my application.
it is used to show popup for login.
In this popup there is a link for Change Password and Reset Password, but a method for this link is declared in internal class in that dll file.
This is the internal class in that dll.
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
namespace Satis.Client
{
internal class AuthenticationForm : Form
{
private string _resetPasswordUrl;
private string _changePasswordUrl;
private string _application;
public string ResetPasswordUrl
{
set
{
this._resetPasswordUrl = value;
}
}
public string ChangePasswordUrl
{
set
{
this._changePasswordUrl = value;
}
}
public string Application
{
set
{
this._application = value;
}
}
private void _changePasswordLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
if (!string.IsNullOrEmpty(this._changePasswordUrl))
{
Process.Start(this._changePasswordUrl);
}
}
private void _resetPasswordLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
if (!string.IsNullOrEmpty(this._resetPasswordUrl))
{
Process.Start(this._resetPasswordUrl);
}
}
}
Here i can able to pass the value to this properties in AuthenticationForm class, but when i click on those link, it is not firing the event and this links are not opening,
Please find my code below.
public class RTFEauthentication
{
IAuthentication wrapper;
string ChangePwd = "http://gmail.com";
string ResetPwd = "http://microsoft.com";
string appName = "LRM";
public RTFEauthentication()
{
wrapper = new Authentication("*****************", "LRM", "UAT", "AUTH", "1.7.3", null);
Authentication.ChangePasswordUrl = ChangePwd;
Authentication.ResetPasswordUrl = ResetPwd;
}
public string ChangePasswordURL
{
get
{
return ChangePwd;
}
}
public string ResetPasswordURL
{
get
{
return ResetPwd;
}
}
public string Application
{
get
{
return appName;
}
}
public bool ValidateRTFE()
{
object formInstance = PrivateMethodAccessHelper.GetInstanceOfClass("Satis.Client",
"Satis.Client.AuthenticationForm", new object[] { });
PrivateMethodAccessHelper.SetInstancePropertyValue(formInstance.GetType(),
"ChangePasswordUrl", formInstance, ChangePasswordURL);
PrivateMethodAccessHelper.SetInstancePropertyValue(formInstance.GetType(),
"ResetPasswordUrl", formInstance, ResetPasswordURL);
PrivateMethodAccessHelper.SetInstancePropertyValue(formInstance.GetType(),
"Application", formInstance, Application);
PrivateMethodAccessHelper.SetInstanceFieldValue(wrapper.GetType(),
"_form", wrapper, formInstance);
IAuthenticationResult result = wrapper.AuthenticatePopup();
if (result == null)
return false;
else
return result.Succeeded;
}
}
public sealed class PrivateMethodAccessHelper
{
public static object GetInstanceOfClass(string assembly,
string fullyQualifiedName, params object[] contructorParams)
{
return Activator.CreateInstance(Type.GetType(fullyQualifiedName + "," + assembly), contructorParams);
}
/// <summary>
/// Set value of the object member.
/// </summary>
public static void SetInstancePropertyValue(Type typ, string propName, object objInstance, object objValue)
{
PropertyInfo propInfo = typ.GetProperty(propName, BindingFlags.Default | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
if (propInfo != null)
{
propInfo.SetValue(objInstance, objValue, null);
}
}
/// <summary>
/// Set value of the object member.
/// </summary>
public static void SetInstanceFieldValue(Type typ, string fieldName, object objInstance, object objValue)
{
FieldInfo fieldInfo = typ.GetField(fieldName, BindingFlags.Default | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
if (fieldInfo != null)
{
fieldInfo.SetValue(objInstance, objValue);
}
}
}
Could any one pls tell me what is the problem here and how to fix it.?
|
|
|
|
|
If you own this class (and the fact that you have the source strongly implies that you do), make the class you want to use outside the assembly public! Internal means internal and using reflection hackery to get around that shows that you have a serious design problem.
Nothing happens because you haven't actually done anything with the form you create. If you hadn't obfuscated everything with the reflection crap then you'd have been able to spot that.
|
|
|
|
|
Hi Bob,
No, i dont own this class, this class available only that assembly and i have to display an webpage when that linkbutton in this internal class is clicked.
But if i directly invoke that method, i can able to display the url i want(see the code below), but if i pass the value into those 2 public properties, this url is not invoked when i click on those links in the popup.
formInstance.GetType().InvokeMember("_changePasswordLinkLabel_LinkClicked", BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.NonPublic, null, formInstance, new object[] { null, null });
So could you tell me how to fix this.
|
|
|
|
|
I hate quote myself but really:
"Nothing happens because you haven't actually done anything with the form you create. If you hadn't obfuscated everything with the reflection crap then you'd have been able to spot that."
... I already pointed out the problem. Assigning properties does nothing, you have to actually use the form in some way (adding it as a control? not sure how ASP.net works exactly and this is definitely a bit of an abuse).
|
|
|
|
|
this popup form is used to check the user credentials, it is linked to some internal assembly and check the username and password which i eneter in this popup with the some internal assembly.
All the control in this form is working properly apart from those 2 link button.
|
|
|
|
|
Then there's something you aren't showing us, because nowhere in what you posted do you actually call a method on an instance of that class.
|
|
|
|
|
Could you explain a bit more in detail what you're trying to achieve? As it looks, you're trying to hook into some internal class to get at a username/password.
How would you need that to redirect a button? And who is "Satis"?
Bastard Programmer from Hell
|
|
|
|
|
Hi Eddy,
thanks for the respnse.
here, am passing the value into ChangePasswordUrl and ResetPasswordUrl property where it assign the value into _changePasswordUrl and _resetPasswordUrl this fields.
You can see that when this method
_changePasswordLinkLabel_LinkClicked is invoked it reads the data from _changePasswordUrl and open the link which i pass into this field.
Satis.Client is assembly/dll name which am consuming in my application.
|
|
|
|
|
Rocky23 wrote: here, am passing the value into ChangePasswordUrl and ResetPasswordUrl property where it assign the value into _changePasswordUrl and _resetPasswordUrl this fields.
I've seen the write-only properties in the first post - but no events that "should" get fired. I've also seen that you're trying to assign a value to a read-only property.
Rocky23 wrote: Satis.Client is assembly/dll name which am consuming in my application.
That much I figured. I also know it's a forms-application, and that you're trying to use one of their classes - and apparently, they're not documented. So, you found a way to create their form, and now you want it to point "elsewhere".
Now, from my point of view, you're trying to hook into someones authentication-mechanism.
Bastard Programmer from Hell
|
|
|
|
|