|
I hadn't thought of that. Readability is another factor, though it doesn't directly affect execution speed
|
|
|
|
|
I am trying to convert clock time to a double, and am getting an error, can someone use another pair of eyes to assist with this. See the code below. Thanks
static void Main(string[] args)
{
string[] timeArray = new string[6]{ "08:17", "15:26", "18:32", "00:46", "10:38", "13:56" };
double[] decTimeArray = new double[6];
for (int x = 0; x < timeArray.Length; x++)
{
decTimeArray[x] = ConvertTime(timeArray[x]);
}
for (int x = 0; x < timeArray.Length; x++)
{
Console.WriteLine(timeArray[x] + " " + decTimeArray[x]);
}
Console.ReadKey();
}
}
public static double ConvertTime(string rawTime)
{
int hours;
int minutes;
double dminutes;
double decimalTime;
string delimStr = ":";
char[] delimiter = delimStr.ToCharArray();
string[] split;
split = rawTime.Split(delimiter);
hours = Convert.ToInt32(split[0]);
minutes = Convert.ToInt32(split[1]);
if (minutes < 7)
dminutes = 0.00;
else if (minutes < 22)
dminutes = 0.25;
else if (minutes < 37)
dminutes = 0.50;
else if (minutes < 53)
dminutes = 0.75;
else dminutes = 1.0;
return decimalTime = dminutes + hours;
|
|
|
|
|
Still at it?
To get a time span expressed as a floating-point number of hours but rounded to a quarter, I would try something along these lines (code not tested):
private double ToHoursButRoundedToQuarter(string s) {
TimeSpan span=TimeSpan.Parse(s);
int minutes=span.TotalMinutes+7;
int quarters=minutes/15;
return quarters*0.25;
}
|
|
|
|
|
Your code makes very little sense to me. Why not use DateTime and/or TimeSpan ?
|
|
|
|
|
This was working, but right now I am getting the following error:
Expected class, delegate,enum, interface, or struct
I am new to c#, and in a class where we are not using the timespan yet, and will not touch on that in this semester. I you could look at the code I have supplied, and maybe help me find the error, that would be great.
Thanks
|
|
|
|
|
|
that's cheating. The challenge is to locate the error (and to get someone else to that for you).
|
|
|
|
|
Lol
|
|
|
|
|
From the code you posted and the error you say you are getting, I think your brackets are off. You should have { } wrapped around your class methods (Main and ConvertTime) and also to enclose them.
|
|
|
|
|
Thanks, that's what I needed, another pair of eyes. I must have deleted a bracket accidentally. Runs fine now.
|
|
|
|
|
I am a beginner at C# and have been given an assignment that I am having trouble starting. Any help would be useful! Here is the project:
Write a program to print all combinations of hours, minutes and seconds in military time format HH:MM:SS using nested loops.
Like I said, I'm new to this, only 2 weeks in... so keep that in mind!
Thanks,
Bonnie
|
|
|
|
|
It often helps very much when trying to get help with homework assignments if you show what you have come up with so far.
Do you know what nested loops means? Have you given that a try, and if so how far did you get?
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
the problem is, with all those nested loops, the app is taking all day.
|
|
|
|
|
Groan.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Nested loops, yes. You'd need 3.
Choosing the bounds of these loops is trivial.
As to outputting, where do you want them to go?
System.Console.WriteLine("{0}:{1}:{2}", h, m, s);
(warning: untested)
Seems reasonable to me.
|
|
|
|
|
It's almost as if the answer is written in your question. If only a certain part were written in all lower case and there was a DateTime object that supported addition your problem would be solved.
|
|
|
|
|
Hi All,
I'm developing a software for geostatistical modeling, and I need to visualize 3d spatial data and doing some basic 3d actions e.g rotation, zoom, slicing, color mapping, gridding and so on. What is the best way for doing this? Shall I use a 3rd party control?
|
|
|
|
|
Couldn't you just use OpenGL?
|
|
|
|
|
I'm not familiar with openGL. which one is prefered, OpenGL or DirectX?
|
|
|
|
|
OpenGL, for several reasons - I'll just list a few:
* easy to use inside winforms (even in C#, check the TAO framework)
* if you manage to crash it, windows will still be alive
* easier low-level manipulation of eg vertices (good for visualization)
* full access to all hardware features (the gpu manufacturer will make sure of it)
DirectX isn't "bad" for 3D visualization though, it's fine to use it.
|
|
|
|
|
Is there any free openGl control implementing basic actions for .NET or I have to design one by myself?
|
|
|
|
|
The TAO framework has one
|
|
|
|
|
Hello,
I have created a datagridview using C# windows application and I am having formatting issues with the data once the datagridview has been populated. The way I have this set up is before I bind the data to the binding source I add a new row which contains combo boxes. These Como boxes are used to populate the new headers. Once the headers have been modified the data needs to be formatted to data types the system can handle. For example, the datagridview populates dates as mm/dd/yyyy 00.00.00 AM but I need to reformat this to mm/dd/yyyy. I have created a method that loops through each cell in the first row and captures the new header (which works) but when the code that is suppose to reformat the column runs, it doesn't work. the code I have to reformat the columns based on the logic used is dataGridView1.Columns[c].DefaultCellStyle.Format = "d";. However, this doesn't work. Can someone please help me? It is much appreciated. Here is what I have and if it is not enough then let me know and I can post more code.
private void button10_Click(object sender, EventArgs e)
{
if (radioButton1.Checked == true)
{
string[] newHeaders = new string[dataGridView1.ColumnCount];
int n = dataGridView1.ColumnCount;
int c = 0;
for (c = 0; c < n; c++)
{
newHeaders[c] = dataGridView1.Rows[0].Cells[c].Value.ToString();
if (newHeaders[c] == "A1ORDT")
{
dataGridView1.Columns[c].DefaultCellStyle.Format = "d";
}
}
}
else if (radioButton2.Checked == true)
{
//Add code for custom formatting
}
else
{
MessageBox.Show("Please select standard or custom formatting");
}
}
|
|
|
|
|
Hello
I have soft of a half problem, where i know the cause of the problem, but don't know how to solve it exactly.
What i want to achieve: I want to check if outlook, excel and word are installed in the host computer when the user launches the program and inform the user if there are some complications.
My problem: I have application that uses excel, word and outlook. In every computer that has Office installed the program works and i even don't have to publish my application, instead copying the release folder is enough. But the application doesn't even launch on hosts, instead i get cut off very beginning and therefore i can't even show my informative messages, that don't have office installed and i get clr20r3 error.
How far im to solve the problem: I have found a problem cause in the following quote
Reference to problem cause http://social.msdn.microsoft.com/forums/en-US/winformssetup/thread/53c2de93-ab33-41d0-b5dd-7ca5fbfa5c24/[^]
post 4
Hi all,<br />
<br />
I have found the solution to this issue, it is due to dependancies. (I've just found out one of my employee's installed a second program onto the first virtual machine) This is why it gives a filenotfound exception as it is trying to load this program.<br />
<br />
When you use third party dll's that are not installed on windows by default the built in publishing tool inside VS.NET will not include these in the distributable it builds for you. I do not understand why i doesnt do this but i am switching all my distribution to Install Shield from now on.<br />
<br />
To fix your applications what you need to do is to look at your references (in solution explorer and in insertable objects) and make sure that you copy these dll's and dependancys onto the machine you want to install to and do a regsvr32 -i <dll><br />
<br />
I hope this helps you guys,<br />
<br />
Kind Regards,<br />
Chris Allen<br />
Technical Director<br />
UK National Networks LTD</dll>
This post also explained shortly what i can do to solve this problem, tho it didn't help me much.
What i want to achieve: I would like to by pass this error and still be able to launch my program. And then show some informative messages to the user and take necessary actions.
What i have tried to solve the problem: I made sure that i had following 3 DLL files in my release folder and when i published they would be included.
Interop.Microsoft.Office.Interop.Outlook.dll
Interop.Microsoft.Office.Interop.Excel.dll
Interop.Microsoft.Office.Interop.Word.dll
So that all the DLL files for my dependencies in program would be there. And what happened was that i got a bit different error
PLATFORM VERSION INFO
Windows : 5.1.2600.131072 (Win32NT)
Common Language Runtime : 2.0.50727.1433
System.Deployment.dll : 2.0.50727.1433 (REDBITS.050727-1400)
mscorwks.dll : 2.0.50727.1433 (REDBITS.050727-1400)
dfdll.dll : 2.0.50727.1433 (REDBITS.050727-1400)
dfshim.dll : 2.0.50727.1433 (REDBITS.050727-1400)
SOURCES
Deployment url : file:
IDENTITIES
Deployment Identity : IOMailer.application, Version=1.0.0.0, Culture=neutral, PublicKeyToken=943730f75ed49f00, processorArchitecture=msil
APPLICATION SUMMARY
* Installable application.
ERROR SUMMARY
Below is a summary of the errors, details of these errors are listed later in the log.
* Activation of H:\IOMailer.application resulted in exception. Following failure messages were detected:
+ Downloading file: + Could not find a part of the path 'H:\Application Files\IOMailer_1_0_0_0\IOMailer.exe.manifest'.
+ Could not find a part of the path 'H:\Application Files\IOMailer_1_0_0_0\IOMailer.exe.manifest'.
+ Could not find a part of the path 'H:\Application Files\IOMailer_1_0_0_0\IOMailer.exe.manifest'.
COMPONENT STORE TRANSACTION FAILURE SUMMARY
No transaction error was detected.
WARNINGS
There were no warnings during this operation.
OPERATION PROGRESS STATUS
* [27.04.2009 16:52:45] : Activation of H:\IOMailer.application has started.
* [27.04.2009 16:52:45] : Processing of deployment manifest has successfully completed.
* [27.04.2009 16:52:45] : Installation of the application has started.
ERROR DETAILS
Following errors were detected during this operation.
* [27.04.2009 16:52:45] System.Deployment.Application.DeploymentDownloadException (Unknown subtype)
- Downloading file: - Source: System.Deployment
- Stack trace:
at System.Deployment.Application.SystemNetDownloader.DownloadSingleFile(DownloadQueueItem next)
at System.Deployment.Application.SystemNetDownloader.DownloadAllFiles()
at System.Deployment.Application.FileDownloader.Download(SubscriptionState subState)
at System.Deployment.Application.DownloadManager.DownloadManifestAsRawFile(Uri& sourceUri, String targetPath, IDownloadNotification notification, DownloadOptions options, ServerInformation& serverInformation)
at System.Deployment.Application.DownloadManager.DownloadApplicationManifest(AssemblyManifest deploymentManifest, String targetDir, Uri deploymentUri, IDownloadNotification notification, DownloadOptions options, Uri& appSourceUri, String& appManifestPath)
at System.Deployment.Application.ApplicationActivator.DownloadApplication(SubscriptionState subState, ActivationDescription actDesc, Int64 transactionId, TempDirectory& downloadTemp)
at System.Deployment.Application.ApplicationActivator.InstallApplication(SubscriptionState& subState, ActivationDescription actDesc)
at System.Deployment.Application.ApplicationActivator.PerformDeploymentActivation(Uri activationUri, Boolean isShortcut, String textualSubId, String deploymentProviderUrlFromExtension)
at System.Deployment.Application.ApplicationActivator.ActivateDeploymentWorker(Object state)
--- Inner Exception ---
System.Net.WebException
- Could not find a part of the path 'H:\Application Files\IOMailer_1_0_0_0\IOMailer.exe.manifest'.
- Source: System
- Stack trace:
at System.Net.FileWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.FileWebRequest.GetResponse()
at System.Deployment.Application.SystemNetDownloader.DownloadSingleFile(DownloadQueueItem next)
--- Inner Exception ---
System.Net.WebException
- Could not find a part of the path 'H:\Application Files\IOMailer_1_0_0_0\IOMailer.exe.manifest'.
- Source: System
- Stack trace:
at System.Net.FileWebResponse..ctor(FileWebRequest request, Uri uri, FileAccess access, Boolean asyncHint)
at System.Net.FileWebRequest.GetResponseCallback(Object state)
--- Inner Exception ---
System.IO.DirectoryNotFoundException
- Could not find a part of the path 'H:\Application Files\IOMailer_1_0_0_0\IOMailer.exe.manifest'.
- Source: mscorlib
- Stack trace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync)
at System.Net.FileWebStream..ctor(FileWebRequest request, String path, FileMode mode, FileAccess access, FileShare sharing, Int32 length, Boolean async)
at System.Net.FileWebResponse..ctor(FileWebRequest request, Uri uri, FileAccess access, Boolean asyncHint)
COMPONENT STORE TRANSACTION DETAILS
No transaction information is available.
I have also tried to dig into this problem, but in all the explanation there are things that i don't understand and therefore can't rinse out the right solution.
Summary: I hope i have given enough information so you would be able to suggest me with simple solutions
Thanks
Hendrik
|
|
|
|
|
Does the file (H:\Application Files\IOMailer_1_0_0_0\IOMailer.exe.manifest) exists?
|
|
|
|
|