|
Hey folks!
I need help getting something done. I need a function to do this but can not seem to figure out the structure to make it happen.
This is a plain text explanation of what I am doing, how should it be in C#??
public static void tiers()<br />
{<br />
string tier_temp = "124.5";
if tier_temp has "."<br />
string tier_fr = extract number to left of ".";<br />
string tier = extract numbers to right of ".";<br />
else<br />
string tier_fr = "0";<br />
string tier = tier_temp;<br />
}
I have seen this done using Mid and Left in VB6 but can not see how it should be done in C#
HELP!!!
Thanks Everyone!
David
You are only as good as your last project.
|
|
|
|
|
hi,
use
<br />
<a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemstringclasssplittopic.asp">String.Split()</a>[<a target=_blank title='New Window' href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemstringclasssplittopic.asp">^</a>] . This looks like you want to use "124.5" as number... If yes, look at Parse()[^] method of standard number types.
hope it helps.
David
Never forget: "Stay kul and happy" (I.A.)
David's thoughts / dnhsoftware.org / MyHTMLTidy
|
|
|
|
|
that part I think I understand, but how do I step the parsed info to the if so that it can populate my other var's?
I am very new to C# and trying to learn durring project development so please be patient with me!
Thanks;
David
You are only as good as your last project.
|
|
|
|
|
I see. If you really want both parts of a input as strings, String.Split returns array of strings (delimitered by chars in argument you passed to this method). So
public static void tiers()
{
string tier_temp = "124.5";
if(tier_temp.indexOf('.')>=0)
{
string [] parts = tier_temp.Split(new char[]{'.'});
string tier_fr = parts[0];
string tier = parts[1];
}
else
{
string tier_fr = "0";
string tier = tier_temp;
}
}
is almost direct translation of your example. I don't say this code is optimal or secure! Just an example...
DEWright_CA wrote:
I am very new to C# and trying to learn durring project development so please be patient with me!
That's ok.
David
Never forget: "Stay kul and happy" (I.A.)
David's thoughts / dnhsoftware.org / MyHTMLTidy
|
|
|
|
|
That is incredible, now I just need to see if I can make the next part of it work.
Will be able to test the entire thing after I get the validation piece added!
Thanks for the help, seeing your I now realize my main problem is the brackets; for some reason I have not gotten use to all of those!
Thanks again!
David
You are only as good as your last project.
|
|
|
|
|
Hello Friends,
I need to add some event funtions about Window Forms, for example I want to add sentence to the "Form_Closing" Event and customize it, but I know I don't write the function declaration.
How can I add these functions from the C# GUI or how can I know which are all these funtions from the C# GUI?.
Tnx for help me.
|
|
|
|
|
|
Noel,
On a WinForm, delegates are used to wire component/control events to the method that handles them. For a bit of background have a look at this article by Maysam here at The Code Project: Link. When you are working on a GUI (which is a WinForm) in Visual Studio, click on the control that you are interested in modifying and then look at the Properties window on the right side of the screen. If you click on the small yellow lightning bolt, you have an event editor built into the IDE. This provides a list of the events that you asked about in your last question. Double click on any event that you are interested in editing and it will (1) automatically code the delegate for you and (2) take you to the code view for your form so that you can add the code for the method that is fired when the event occurs. Anytime you return back to the design view, you can easily find the code for the method again by double clicking the event in the Event editor window. More specifically for your question about the "Form Closing" event, click on the topmost area of the form in the design view, click the yellow lightning in the Properties window, and scroll down to the "Closing" event. Double click on it and you're ready to code!
You can also find more information about all of the events for controls and components at Microsoft's site: http://msdn.microsoft.com. Search for whatever class you are interested in and it will have a members page that includes a description of all events. Here's an example for the combobox: Link.
Hope that this helps. Best of luck with your WinForms.
-CS
|
|
|
|
|
Tnx C_Simpkins!!
That´s all rigth, I tested your sugerences and it helped me.
Bye.
|
|
|
|
|
Not a problem. Take care and good luck.
-CS
|
|
|
|
|
Hi!
I'm trying to get handles to all the program-windows which the user is able to see and work with. I'm doing the loop with EnumWindows and in the callback-function I have to filter out needless stuff. Everything works fine if I try to get all windows from the taskbar, but I have problems retrieving the ones from the systray (Norton InternetSecurity or NetLimiter for example). What's unique on them? IsVisible(...) ends up without success and I tried several other things but nothing worked. Does someone has an idea or knows a solution? Would be great.
Thanks!
|
|
|
|
|
They dont have a windows, so the user is not able to see the windows, which makes them fall out of your scope anyway, doesnt it?
Most of the times, these little buggers are "helpers", e.g. frontends you can pop-up for some service running in the background.
What is unique with them is that they are not visible in the Taskbar, nor on the Screen. Why dont you write one yourself, which would then exhibit some kind of behaviour you could track.
Cheers
Sid
|
|
|
|
|
Hi sebs2004, thanks for your reply!
You're right, the windows are not in my scope so it doesn't greatly matter. If one of them is going to be opened, the IsVisible(...)-function will retrieve it because they're in the visible area.
|
|
|
|
|
Hi,
I am new to C#, we had an app that stored ms word doc in ms access as ole objects you could click on and open, that was done in VB6.
Is there a way doing this with C# and .Net ??
Thanks
Bob Menard
|
|
|
|
|
Hey
Look at this example on opening the serial port in Framwork 2.0:
http://msmvps.com/coad/
as you can see he is using:
<br />
port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);<br />
I cant find DataReceived in my serialPort propertie? and no SerialDataReceivedEventHandler exist?
Am i doing wrong or have thay removed this things?
|
|
|
|
|
I have been doing a bit of research as to user control and system lock down for an application I am working on. I have found that the only true way to control what all users of a system can access or do on the system is through group policies. Strangely enough there is nothing out there on Microsofts web site to even get me started on creating, adding and or editing existing group policies on a machine through a C#.net application. The application I am working on requires that it be able to impose restrictions on all, or individual users of Windows XP based machine both home and pro. Will someone please point me in the right direction or assist me in what I can do to accomplich this in my application. I would be extremely greatful. I have tried creating a system lock down app. which does direct registry edits that is set in the run once key of the local machine so that it will run when each user logs on but do to registry edit restrictions on limited users all I get are secrurity access errors on those accounts which does me no good. Let me know if any of you have suggestions as to the most practicle way to accomplish this. If you have any questions as to details, let me know by posting them here. Thanks again!
Well through further study it seems that home version does not support group policies or administrative templates so that is out the window. So what I need then is assistance in getting my lock down app to run on regular limited user accounts as though it was an adminstrator in order for those restritions to be applied to the account. Or if someone knows how to apply registry value edits across all user accounts from just within the admin account (this would be optimal). Let me know
|
|
|
|
|
Group Policies are nothing but registry hacks to begin with. The template your talking about are really just text files that the Group Policy editor uses to put up an interface so you can select and change the values going into the Registry. Group Policies only need to be changed once, when their setup. So having your users run your app constantly is pointless.
Most Group Policy options are not done in the users registry space anyway, so your really wasting your time there.
Most of the keys and values are only available to Power Users and Administrators, so normal users won't be able to make the changes anyway. You COULD run your app as another user, like an Administrator, but that requires that you either manually launch the app by holding down Shift, then right-clicking the icon and selecting "Run As...", or your application could be launched by another app, but that would involve sending the Administrator username and password with the app. Not a good idea.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks for your reply. While I have been waiting for replies I have been searching MSDN for answers and have stumbled on exactly what you are saying. Group policies are just reg hacks and I did run into the "RUN AS" option but you made a very good point about exposing the admin info by placing it in a bat file or something just to run the one app. I wasnt planning on having the app run everytime a user logs on just once through the run once key in the local machine registry key. But still not a very efficient way to handle the problem. Specially since I want the administrator to be able to adjust the restrictions from time to time.
For example the app needs to be able to disalbe MyComputer, Run, Search from the start menu. Disable registry tools, CMD, all that sort of stuff. I have all the hacks (keys and values that need to be added to the registry) but they all specify that they need to be placed in the Current_User key of the registry and some state they need to be placed there and in the Local_Machine key in order to work.
You stated that there are keys and values in a location in the registry where these changes can be made which does not require changes to be made to each individual users registry space. Where exactly is this key. It would be optimal to just run the app from the admin account and have it affect all the user accounts. Also, what if I need to affect a specific user account with a specific restriction but not every account. How do I specify a specific user and edit its registry space from within the admin account?
Pretty complex, no doubt. But its what I am working on and trying to learn all I can at the same time. If you have any suggestions, tutorials, sites, or code you could show me to help me out I would be most greatful.
Thanks...
Schleichermann
|
|
|
|
|
Schleichermann wrote:
just once through the run once key in the local machine registry key.
The contents of this key is run under the logged in user at login time. You'll run into the same security problem you've been running into.
Schleichermann wrote:
You stated that there are keys and values in a location in the registry where these changes can be made which does not require changes to be made to each individual users registry space. Where exactly is this key.
It's not one key, it's many, many, many of them. For instance, under IE there are two ways to set Proxy information. One is by individual and the other is a machine based version where this setting overrides the users settings. Users can modify the Proxy settings, but they won't work because IE can use the machine settings instead.
Schleichermann wrote:
It would be optimal to just run the app from the admin account and have it affect all the user accounts. Also, what if I need to affect a specific user account with a specific restriction but not every account. How do I specify a specific user and edit its registry space from within the admin account?
This is all functionality that is supplied by Active Directory. Group Policies are attached to OU's that contain machines and users. Each OU can have multiple Group Policy objects attached to them. Any changes made to the copy in the OU are automatically deployed to all the machines and users.
You might want to check into that before you go banging your head against a solution that can easily be broken.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I have files in EXCEL and ACCESS. I need to be able to read two files and update one based on the other. Will I be able to do that with C#?
|
|
|
|
|
|
Hi, I am writing a window application for encrypting and decrypting messages. But the decryption method (shown below) gives me different characters each time, also the characters are different on each computer. Please take a look at the code and let me know what could be wrong. Thanks.
private void cmdDecrypt_Click(object sender, System.EventArgs e)
{
double tok;
int ptr;
int z;
string decSt = "";
for (z = 0;z
|
|
|
|
|
Hi!
Just from taking a quick look at the code I can't see what could be wrong, but why don't you use one of the tried and tested existing encryption/decryption methods available in the framework?
If you don't have a strong background in mathematics and encryption I guess everything you can think up as encryption algorithm can be broken quite easily.
And lots of people use DES, AES, Rijndael etc. without complaints, so I guess the framework's implementation of these algorithms is correct.
Regards,
mav
|
|
|
|
|
I'm trying to write a regular expression which seems easy enough but is elusive.
I need to strip some info from a html table. The pattern is simple :
1,2 * [b] tag followed by
{ anything } followed by
optional [em] followed by
{ anything } followed by
1 or more [span]
This is what I've got so far :
(?:
[b]
(?<SubPackage>.*?)
[/b]
)+
(?:.|\s)*?
(?:
[em](?<SubText>.*?)[/em]
)
Which seems to work fine until I make the '[em]' group 'zero or more' * . That part is then just ignored.
|
|
|
|
|
Hi,
I want to convert javascript functions Relative URL to absolute URL.
I have all the javascript urls extracted from a web page this being done from the HTML DOM of web page and the page is being browsed in webbrowser control in my c# project.
I want to get the absolute url of a javascript function. Presently i using the simulating the onclick event of Browser through MSHTML and capturing the url in beforenavigate event but that ends up in a chaos as it sends reuqest for navigation and takes up time. This scenario is quite cumbersome in cases
where there are a no. of javascript functions and for each a request is being sent.
One possible way is to stop the browsing once i have the url, however that doesnt seems to be a good way to solve the problem.
some examples
javascript:OpenPage('http://google.com');
Absolute Path:- http://google.com
javascript:LinkToPage2('/sports','/games.htm')
This being on the domain of yahoo.com so
Absolute Path:- http://www.yahoo.com/sports/games.htm
--
some code
---
for(int j = 0; j < anchors.length; ++ j)
{
link = (mshtml.IHTMLAnchorElement)anchors.item(j, null);
if (link.href.ToLower().StartsWith("javascript:"))
{
ele = (mshtml.IHTMLElement)link;
if (cnt == count)
{
currentEle = ele;
currentDoc = doc;
found = true;
break;
}
---
more code
---
currentEle.Click()
}
Now capturing the url in before navigate event
private void BeforeNav(object sender, NavigateEventArgs arg)
{
try
{
string Url = arg.Url
----
----
Any suggestions!
the woods are lovely dark and deep.
but i have promises to keep.
there are miles to go before i sleep...
there are miles to go before i sleep...
|
|
|
|