|
Hi,
I need to ask once you have created an List how do you compare each of the values within the List against another number?modified on Wednesday, March 10, 2010 12:03 AM
|
|
|
|
|
By looping through the List comparing each of the values to the number..?
|
|
|
|
|
The MSDN documentation contains all the information, in particular it describes List<T>.Find() and List<T>.Contains
|
|
|
|
|
Thanks Luc I will check it out. Appreciate the help
|
|
|
|
|
Hi,
I've had to go back to the drawing board and I need some help. Below is the code I am using to read a text file which contains around 20 numbers.
The readText Print works as expected showing all of the numbers within the text file.
I need to Print the nearest number (within the text file) that is above another which is a double and I'm not quite sure how?
{
readText = File.ReadAllText("C:\\PIn.txt");
string [] split = readText.Split(new Char [] {' '});
Print(readText);
}
|
|
|
|
|
Am I missing something?
1) Find target number in array
2) Get next element in array I know the language. I've read a book. - _Madmatt
|
|
|
|
|
there are three steps:
- you come up with a good algorithm
- you come up with reasonable code, implementing said algorithm
- and if you then have a specific problem and a specific question, you post algorithm, code, and problem description on CP, and someone helps you out.
|
|
|
|
|
You already have the answer to this question here[^]. I tried your code and it gives the correct result; what has changed since yesterday? txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
I have been looking for days as to how to get a Mac Address of a remote PC with C# without Admin Privileges. I use it for validation. The exe can only be run from one PC. First time the app is run, the MAC Address of the Computer where the app is running is recorded. Every time someone logs, the MAC Address of the Computer where the app is running from is checked. If the app is on a remote PC, the user needs Admin privileges to get the MAC Address.
1. WMI needs admin access.
2. nbtstat -a ipAddress
//When you try to run the nbtstat command with a command-line switch such as nbtstat -a remotename in Microsoft Windows XP or in Microsoft Windows Server 2003, the command does not run. Additionally, you receive the following error message:
//Failed to access NetBT Driver - NetBT may not be loaded.
//CAUSE: This issue occurs because users without administrator rights, including power user...This issue occurs because users without administrator rights, including power users, do not have sufficient permissions to run nbtstat when the user includes a command-line switch.
3. SendARP (iphlpapi.dll)
if (SendARP(RemoteIPAddress, 0, macByteArray, ref macAddrLen) != 0)
returns macByteArray==null
4.GetIpNetTable (iphlpapi.dll) returns null
Any other ideas?
|
|
|
|
|
Windows copies the physical MAC address from its hardware register to some software variable, which you can observe in many ways and modify in some ways (I don't recall all the details); the modified value remains in effect until the network gets disabled/re-enabled or disconnected/reconnected (not sure which). So you can not really trust it, unless you do a disable/re-enable (or...) from within your code, which is slow and probably hard to do.
|
|
|
|
|
I have a .NET 1.1 (for compatibility reasons) application that runs as a windows service. I have successfully ran it, except the only problem is im not able to invoke methods in the user32 dll i need to call. I have ran the exact same code as a normal process, and this doesn't seem to be happening. Ive also isolated and ran portions of the code just to tell if the invocations were even successful, and they weren't, so i know it's not a problem with my applications code. As far as i can guess running as a service changes some sort of permissions or something that doesn't allow me to invoke these methods. Anyway im not an expert on the windows os, so before i make myself sound even dumber im gonna shut up. One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs.
-Robert Firth
|
|
|
|
|
Hi,
jacobjordan wrote: user32 dll
jacobjordan wrote: doesn't allow me to invoke these methods
which functions exactly? anything related to user interaction? (a service has no desktop, no user, by default)
|
|
|
|
|
Add some exception handling to your code around the PInvoke calls and write to the error log in the catch blocks and you will be able to tell exactly what the problem is.
If it's a permission issue then you may need to specify a user to run the service as by setting the System.ServiceProcess.ServiceAccount[^]Dave
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
The methods im invoking are GetAsyncKeyState, GetWindowText, and GetForegroundWindow, all of which return values. No exceptions are being thrown when i invoke, only when i run my app as a service they return a value of 0 (since all return either ints, shorts, or intptrs). Obviously the methods aren't being called for some reason. One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs.
-Robert Firth
|
|
|
|
|
jacobjordan wrote: GetWindowText, and GetForegroundWindow
those are GUI functions, your service by default has no user and no desktop, hence no GUI.
You must tell it somehow to allow user interaction and specify the account type. I don't know the details.
|
|
|
|
|
As Luc said, these are GUI functions. As the service isn't using the logged in user(s) desktop(s) these functions will not suceed or will fail gracefuly.
Why does this need to be a service? An app minimized to the tray would be able to do the job perfectly.Dave
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
I need to have it running no matter who is logged on, or if nobody is logged on. I know there are probably other ways of doing that, but creating a service was the first thing that came to mind. I would love it if you could suggest and easier way. One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs.
-Robert Firth
|
|
|
|
|
I see your logic for a service but services are non GUI in the sense that they have no UI of their own and can't (since Vista) interact directly with a user's UI.
jacobjordan wrote: or if nobody is logged on
That makes no sense as those calls will be useless.
jacobjordan wrote: no matter who is logged on
You can place the path to your exe in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run and your app will run at start up for all users - you can run it minimized to tray, or invisible by setting the Visible of the main form and ShowInTaskbar to false.Dave
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Yes, sounds like a service.
However, what is a service going to do with some WindowText if it doesn't even know if anyone is logged in?
|
|
|
|
|
Found a good blog here[^] that may help you rethink and workaround your problemDave
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Im writing a class to be called by different forms, Ive got the forms name using the sender but im having trouble saving this to the class because i don't know what form is calling the function.
class Login
{
Form CurrentForm;
if (Sender is form1)
{
form1 temp = (form1)Sender;
this.CurrentForm = temp;
}
Is there any way to declare a new class variable at runtime such as form1 CurrentForm;
Thanks
|
|
|
|
|
Hi,
not sure what it is you want.
Your code needs to reside inside a method, probably an event handler with a "sender" parameter.
Anyway, the solution probably needs a simple this.CurrentForm=sender as Form; with CurrentForm declared as a general Form, not a specialized one.
OTOH, if you were to explain your needs at a higher level, maybe a different approach would be advisable.
|
|
|
|
|
Yeah but then i cant use any methods hat are in the forms class
if (Sender is form1)
{
form1 temp = (form1)Sender;
form1.login()
}
The above works but i cant use form1 outside the if statment, I need a way os saving it at runtime like the class varibles here.
class Login
{
Form CurrentForm;
|
|
|
|
|
if all candidate senders share some user-defined functionality (would be necessary if you want to invoke a method on such sending form), then the solution would be to define an interface, and make all those forms "implement" the interface, which should mean you add ", IMyFunctionality" to the class declaration, as in:
public class MyForm1 : Form, IMyCommonFormFunctionality { ... }
where you need to define the interface, something like (outside all classes!):
public interface IMyCommonFormFunctionality {
void login();
}
Then in your class, do:
IMyCommonFormFunctionality CurrentForm;
...
CurrentForm=sender as IMyCommonFormFunctionality;
BTW: by convention public method names should be CamelCased, i.e. start with an upper-case letter.
[ADDED]
I doubt very much that adding login logic to a bunch of forms is the right way to go. Object orientation dictates to separate concerns, not mix them like that.
[/ADDED]
|
|
|
|
|
For anyone who's familiar with Telerik's RadGrid...
I have placed all rows into EditMode by setting AllowMultiRowEdit = true, then doing this:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
foreach (GridItem item in RadGrid1.MasterTableView.Items)
{
if (item is GridEditableItem)
{
GridEditableItem editableItem = item as GridDataItem;
editableItem.Edit = true;
}
}
RadGrid1.Rebind();
}
The problem now is - I don't see any way to force the grid to save changes. I tried:
protected void cmdSaveChanges_Click(object sender, EventArgs e)
{
SqlDataSource1.Update();
}
But it didn't work. How do I save changes in the grid? I do NOT want Edit or Update button columns in the grid.Everything makes sense in someone's mind
|
|
|
|