|
Oh wait! If you'll give me your email address, I'll send you all my code for either your approval, or a list of ambiguous hints and criticisms about where I might have gone wrong before I check it in to TFS. Oh yeah, don't forget to include a lecture on the evils of asking a question on CodeProject. You know - so we don't foster dependency and laziness.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
At least he is honest about it and providing a comment to explain it. You'd be usually the first to sneak something into the solution to get the kid in trouble
A downvote just costs some points, and we have enough to spend.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
It's not about the points. It's about down-voting an answer the is CORRECT, because that reflects on ME.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
So does the rest of the thread.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
And I already had that rep, so no harm, no foul. You should have seen the stuff I didn't post...
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
So here we are. I provided an answer (two, in all actuality), and my answers were down-voted because some pompous ass decided that you didn't deserve the answer I provided.
I didn't provide any guidance, because I don't know if you're TRULY serious about being a programmer, or just taking an elective course to fulfill diploma requirements.
If you're serious, you gotta learn to THINK like a programmer. That means taking a project, breaking it down into logical steps, writing psuedo-code, and then writing actual code.
I'm assuming your instructor taught you about functions, and how they work. Actually, they're called METHODS, and all methods technically return a value, whether it's void or some other type. Methods also (optionally) accept one or more parameters. So let's break down your requirement into easily consumable requirements:
0) write a program that demonstrate the use of a function (method)
1) the function calculates an average of five values
2) the function returns the calculated average
Notice that there is no specification regarding WHERE the function gets the five values. This means you can set up a globally accessible collection of values, or pass parameters to the function. It's your choice how to proceed here.
Once you've decided which way you're going to provide the consumable data (the five values), you can craft your method prototype accordingly.
The body of the method has two processes - calculate the average of the values provided, and return the resulting average.
It's really just that simple (if you were in class for the instructor's guidance regarding the assignment, and paying attention).
If you want definitions for any of the nomenclature I've used above, google is your friend. You certainly shouldn't expect any specific help here, because after all, this is a homework question, and Bill simply won't let that happen.
----------------
Now, that too way too much f*ckin time to type. I don't really care if you are serious about being a programmer, or that this is even homework. I'm not your instructor, and it took LESS of my VALUABLE time to simply "give you the codez" than to give you most of the lesson you should have gotten from your instructor.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
modified 13-Apr-18 15:31pm.
|
|
|
|
|
|
With what? I did what Bill should have done if he was truly concerned with the OP learning something. Instead, he chose to treat everyone that provided real answers like they were 12-year-olds, and scold us for just giving the OP what he wanted.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
John Simmons / outlaw programmer wrote: ... all methods technically return a value, whether it's void or some other type A method with the 'void specification does not return anything: if the compiler encounters a 'return statement in a 'void Method followed by any .NET Type instance, it will throw an error. Of course, the 'return flow of control statement ... by itself ... is valid.
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
modified 15-Apr-18 4:07am.
|
|
|
|
|
Hello
Below id my C# code for finding the status of a website. I get a ok, what I want is to get a 200.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace _200_Test2
{
class Program
{
static void Main(string[] args)
{
{
WebRequest request = WebRequest.Create("http://www.cnn.com/");
try
{
using (WebResponse response = request.GetResponse())
{
HttpWebResponse httpResponse = (HttpWebResponse)response;
Console.WriteLine(httpResponse.StatusCode);
Console.ReadKey();
}
}
catch (WebException e)
{
using (WebResponse response = e.Response)
{
HttpWebResponse httpResponse = (HttpWebResponse)response;
Console.WriteLine("Error code: {0}", httpResponse.StatusCode);
using (Stream data = response.GetResponseStream())
{
string text = new StreamReader(data).ReadToEnd();
Console.WriteLine(text);
}
}
}
}
}
}
}
I try for days now to get a simple 200.
Maybe someone can look at this and tell me what I am going wrong.
Thank You
renny
|
|
|
|
|
But 200 is OK! The property you are referring to also says the same, HttpStatusCode Enumeration (System.Net), only the difference is that your property is an enum and it might be getting translated to a readable form. Try this,
Console.WriteLine((int)httpResponse.StatusCode);
But again, remember, it is always better to use the readable/understandable names of the state; OK, Bad request, etc. Rather than the HTTP codes.
And yes, similarly for the error printing, you would need to use the following,
Console.WriteLine("Error code: {0}", (int)httpResponse.StatusCode);
Read the guide on MDN for more on HTTP codes and also the MSDN link I provided above to understand a bit more about this HTTP status code and how .NET supports it.
200 OK - HTTP | MDN
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Thank you all very much
|
|
|
|
|
See HttpStatusCode Enumeration (System.Net)[^] for the enumeration details. The 200 value is interpreted by the HttpWebResponse object. If you want to see the actual status line then you need to use POST/GET to receive the raw HTML source.
|
|
|
|
|
Thank you all for your help.
renny
|
|
|
|
|
Hello,
I created a new user defined function in excel using c#,what i want to get is when a user open an excel file, clic on a cell and write =myFunction() press enter, data should be displayed in the excel file. these data are retrieved from sql server database and stocked in a 2D array of object, my problem is when i try to display this array in excel range i got this exception
Exception de HRESULT : 0x800A03EC
Below is my code :
public static void LoadViewData()
{
var target = (ExcelReference)XlCall.Excel(XlCall.xlfCaller);
var sheetName = (string)XlCall.Excel(XlCall.xlSheetNm, target);
var application = (Microsoft.Office.Interop.Excel.Application)ExcelDnaUtil.Application;
var sheet = application.Sheets[Regex.Replace(sheetName, @"\[[^]]*\]", string.Empty)];
object[,] result = LoadFromDbData();
var startCell =sheet.Cells[target.RowFirst + 1, target.ColumnFirst];
var endCell =sheet.Cells[target.RowFirst+ result.GetUpperBound(0) - result.GetLowerBound(0) + 1,
target.ColumnFirst+ result.GetUpperBound(1) - result.GetLowerBound(1) + 1];
var writeRange = sheet.Range[startCell, endCell];
writeRange.Value2 = result;
}
target returns the correct value of the cell where the user has written the formula (=myFunction())
sheetName returns the correct activeSheet in which the user writes the formula
result contains the data retrieved from sql server, it is an array of object[854,8]
startcell and endcell represents the range from which cell to which cell data will be displayed
when debugging, all variables contain the correct values, the exception appears in this instruction :
writeRange.Value2 = result;
Anyone has already worked with this or can help please ?
Thanks
|
|
|
|
|
0x800A03EC in Excel is a rather generic error.
In this case, you can't assign an array to a single cells Value2 property. You actually have to iterate through each cell in the array and assign the value of that cell to the corresponding cell in the worksheet.
|
|
|
|
|
We have a medical device that is connected to the LAN but is not on Active Directory. The instrument is running Windows Embedded as a service.
When a user logs into the device we want to validate them against AD. I've found plenty of example of validating users, but they all seem to assume that the code is being run under an account of an AD user.
How to I validate a user against AD when the instrument isn't on AD?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
The device should able to connect AD to validate the user.
Or
you could create a web service that can connect to AD and let the medical device call that web service to verify the user.
|
|
|
|
|
Keviniano Gayo wrote: The device should able to connect AD to validate the user.
Unless someone logs into Windows on the device, it won't connect. Here's how I'm trying
using (var context = new PrincipalContext(ContextType.Domain, credentials.ServerName, credentials.UserName, credentials.Password))
{
validated = context.ValidateCredentials(userName, password);
}
Again, this works if someone is logged into Windows. if not, it doesn't
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I see.. i haven't tried connecting to AD without logging into windows.
I used the same code as above to verify the user in AD.
Perhaps calling a custom web service to verify a user in AD would be the best route.
|
|
|
|
|
Hi,
I have a folder named "Data_base" stored somewhere in my pc. I need the full path of this folder by searching only its name in C#.
void getPath(string name)
{
// need code
}
string folderName="Data_base";
getPath(folderName);
Please Help . . .
|
|
|
|
|
See Directory Methods (System.IO)[^]. You will need to start at the root and enumerate all directories recursively until you find the one you are looking for.
|
|
|
|
|
thanks for your reply.
Got the solution, but ends up with another problem "Access to the path 'D:\System Volume Information' is denied" . And i didn't find any solution to this. So instead of placing the Data_base anywhere i decided to place it in the application installation folder itself.
Now the path can be easily read by using the code in runtime
string appFileName = Environment.GetCommandLineArgs()[0];
string directory = Path.GetDirectoryName(appFileName);
MessageBox.Show(directory);
|
|
|
|
|
Quote: The System Volume Information folder is a hidden system folder that the System Restore tool uses to store its information and restore points. There is a System Volume Information folder on every partition on your computer.
Never store user data in the application folder. A normal user did not have write access when using the recommended Progam Files folder. Use one of the application data folders instead. Which one to use depends on roaming support and if shared access is required. See the AppData properties in the Application Class (System.Windows.Forms)[^] to get these pathes.
|
|
|
|
|
Thanks for the reply...
i don't want to use System Volume Information folder. But during enumeration process automatically the checking comes here, then generates an exception and terminates further execution. Is there any method to avoid these kind of system folders checking during enumeration?.
|
|
|
|
|