|
Hello,
I'd like to know if there is an easy way to subtract two times, e.g:
HH:MM:SS,DDD
00:00:53,040
00:00:48,600
____________ -
??:??:??,???
I am now splitting the times (.split(":") ), putting the values back together as one decimal number, subtracting, and placing the ":"'s back (which is the hardest part). Now there must be an easier way to do this, but I don't know how. Somebody please help me out on this one?
Thanks in advance,
Zaegra
Motivation is the key to software development.
|
|
|
|
|
DateTime, Parse, Subtract
|
|
|
|
|
Use the time span class TimeSpan instead of DateTime
Natza Mitzi
|
|
|
|
|
Natza Mitzi wrote: Use the time span class TimeSpan instead of DateTime
And how exactly would that help the OP where Lucs answer wouldn't?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Not true. You still have to use the DateTime class and the RESULT of the Subtract would be a TimeSpan.
|
|
|
|
|
Yes, that's true. Thanks all for your reply, I will try this tomorrow. Always nice to know that there are people willing to help you out!
Motivation is the key to software development.
|
|
|
|
|
Whenever calculating time I like to see it as a time span and not a date, I find it cleaner logically and its a safer when negative values might be present (they always come when you least expect it). When using a TimeSpan you convert twice and test for negative values once...
Natza Mitzi
|
|
|
|
|
when i tried using a few api functions like FindWindow
they didn't work for me
no error was produced in the debug mode(ie i ran using F5)
how is that??
is there a new way to use api in vb 2008
cause in older vb it is working??
TheMrProgrammer
|
|
|
|
|
Ya, using api in .net is different from VB 6.0. In VB 6.0 we often uses api call but in .net. Here is an example,
<DllImport("KERNEL32.DLL", EntryPoint:="GetSystemDirectoryW", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Public Function GetSystemDirectory(ByVal Buffer _
As StringBuilder, ByVal Size As Integer) As Long
' Leave function empty - DLLImport attribute
' forces calls to GetSystemDirectory to
' be forwarded to GetSystemDirectory in KERNEL32.DLL
End Function
Please use google for futher clarification.
|
|
|
|
|
The process is known as PInvoke or P/Invoke.
If you search MSDN, or Google on those terms you will get lots of examples.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi,
The program I am writing now needs to send data through the serial port automatically. So far, I have been able to put it into a queue list and send it out using a timer. The problem is, the data sent is in two parts and must come consecutively after each part. After that, the timer kicks in and send another two part data.
Does anyone have any ideas on how to do it?
|
|
|
|
|
Your description isn't very clear. How to do what?? Send the data? It sounds like you already have that part down. Use a Timer? Look into System.Threading.Timer[^].
|
|
|
|
|
Hmmmm, the main idea is to queue a list of test to send through the serialport. I have got it down with a timer and queue list. The problem is the test themselves. Each test has a function that calls the device connected to the serial port. However, the functions itself is in two parts. I need to send it one after the other.
For example, (Test 1,2,3,etc) -> queue them -> send through serialport.
But each test, e.g Test 1 - function "a" and function "b" needs to be sent consecutively.
Anyh ideas on how to work around it? I tried putting it into an array and sending it out as an array but the device can't process the information fast enough. I need at least a 2sec delay.
|
|
|
|
|
I don't know how you designed the code, the quick'n'dirty method to pacing something like this at a 2 second interval would be Thread.Sleep(2000).
Normally, I'd probably build a component that handles it's own queue and keeps not only the message that should be sent, but with it, a delay time for how long until the item should be sent. Pop the item off the queue, check it's delay time and setup a Threading.Timer with the delay value and return. The Timer callback will call your code that sends the data to the device.
|
|
|
|
|
That sounds like a good idea. I'll give it a go and see if it works with it. Thanks a lot
|
|
|
|
|
Right, tested this out but I have a problem of with the string "DataSend". Every time it checks for the the varible that I want, it just repeats itself. For example, I queued the test according to "c", "a", and then "c" again. So the queue sends out "c", "a",and lastly "c". The first time it runs, works perfectly. When the timer tick even kicks in, and sends out the next variable "a", I checked it for "a" and it goes well. After that, I checked for the third variable "c", it skips that and goes straight to "a" instead. What happened here? I don't really understand why it refuses to move forward.
Timer1 tick event
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If tasklist.Count > 0 Then
'Run the next test
DataSend = tasklist.Dequeue()
ListBox1.Items.RemoveAt(0)
serialPort.Write(DataSend)
If DataSend.Contains("c") = True Then
Timer2.Enabled = True
Timer1.Enabled = False
ElseIf DataSend.Contains("b") = True Then
serialPort.Write(DataSend)
Timer1.Enabled = True
Timer2.Enabled = False
ElseIf DataSend.Contains("a") = True Then
serialPort.Write(DataSend)
Timer1.Enabled = True
Timer2.Enabled = False
End If
Else
serialPort.Close()
PortStatus.Text = serialPort.PortName & " disconnected."
Disconnect.Enabled = False
Connect.Enabled = True
Timer1.Enabled = False
Timer2.Enabled = False
MsgBox("Finished All Test")
End If
End Sub
Timer 2 tick event, just an event to extend the time for variable "c"
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
serialPort.Write("p" & vbCrLf)
Timer2.Enabled = False
Timer1.Enabled = True
End Sub
I tried making the string empty before dequeue but it doesn't work. Any ideas on how to work around this?
|
|
|
|
|
This might be a possible bug in vs2005 (I know there is a 2008 but have to use 2005 for this one), I did do a search in google but couldn't find an explanation.
I have a usercontrol that's very simple, it just holds a state (and adjusts its text value).
When I place this usercontrol on a form, from time to time I get build errors.
It's easy to fix but very annoying.
Fix = go into designer off the form and delete the project namespace
so: the control is declared like: projectname.usercontrolname
when I delete the projectname. it builds fine and works fine.
Anyone know if this is a bug or how I can fix this, it's really getting on my nervs.
Thanks in advance
|
|
|
|
|
For what it is worth, I have had a similar problem in VS 2003 with datasets.
I would get a build error, and then I would find that the studio had "very helpfully" corrected the generated code.
I would "decorrect" it, and it would work fine, until the next time I built the project.
Finally I just started an entirely new solution / project, recreated all controls, etc, and copied all my own code. No problems after that.
I guess it depends on how badly it gets on your nerves, if it is worth the trouble.
My advice is free, and you may get what you paid for.
|
|
|
|
|
Johan Hakkesteegt wrote: Finally I just started an entirely new solution / project, recreated all controls, etc, and copied all my own code. No problems after that.
Tried that to but didn't help me
I did find that it only happens when I have the form open in design mode, so my fix at the moment is making sure I don't have any of the forms open in design mode when building
|
|
|
|
|
I must say that VS 2005 never liked me, so I switched back to 2003 and made due until VS 2008 came out.
Which brings to mind, if you need to use 2005 because the app is in .net 2.0, I think you can use VS 2008 and just not convert the project to .net 3.5
My advice is free, and you may get what you paid for.
|
|
|
|
|
Johan Hakkesteegt wrote: Which brings to mind, if you need to use 2005 because the app is in .net 2.0, I think you can use VS 2008 and just not convert the project to .net 3.5
I know there is an option in 2008 that lets you specify the framework you want to use (when creating a new project its on the right upper corner I think).
But the framework is not why I can't use 2008, this project is an add-on for another program, the creators of that program created a sdk + some wizards and those wizards only work in 2005 (there working on a 2008 version but there very slow )
I don't use the wizards much but when starting out on something like this they can be handy from time to time.
|
|
|
|
|
Hi
I'm trying to script a scheduled task, and I'm using WMI do do this, but I'm not able to define the name for the new, scheduled task I'm scripting. I only get a generic name such as AT1 or AT2.
My script is as follows:
strComputer = InputBox("Machine you're genrating shedule on",_
"Scheduled task configurator")
if strComputer="" then
wscript.quit
end if
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
JobID = "PendingInfoCheck"
Set objNewJob = objWMIService.Get("Win32_ScheduledJob")
errJobCreated = objNewJob.Create _
("C:\script.vbs", "********030000.000000-420", _
True , 1 OR 2 OR 4 OR 8 OR 16 OR 32 OR 64, , , JobID)
Wscript.Echo errJobCreated
I've tried to set the JobID, and it worked once, but nothing after the first time.
Please Help
TheScripter
|
|
|
|
|
There's no way to do it with WMI. All of the fields that would describe a "normal" job using the Task Schedular UI are not the same as WMI created jobs. You can modify a WMI created job, but once done, you can no longer use WMI to alter the job. There is no way to properly name a job using WMI.
|
|
|
|
|
Hi, I only have VB6 and need to write a program to parse mpeg4-asp frames (each frame is a "bitstream" ie a stream of sequential bits flowing across byte/word/longword boundaries).
Unfortunately VB6 has no unsigned data types, nor native bit operations, making masking and shifting left/right very difficult as you have to write your own functions to take into account (test for and fudge) the sign bit (eg bit 31 of the bit range 31..0 for long). Since any given file could have cumulative bitstreams of 4Gb, imaging how much life gets sucked out of the PC when using a per-bit home-grown function call with all the right masking and signbit testing/fixing complexity...
Does anyone know of system calls (eg kernel32) or some such which makes bitstream operations easy (eg rotate/shift longword/word/byte left and right, integer value of an arbitrarily positioned set of bits, etc) ?
Assume XP-SP3, and latest Java runtime if that helps, but no .NET since an objective is to be able to run on .NET-free PCs.
|
|
|
|
|
Don't be an idiot - get VB.Net or C# express and use it. IT COSTS NOTHING and you will get a lot more support from the forums.
VB6 is dead and no longer supported, do not waste your time starting with VB6
Never underestimate the power of human stupidity
RAH
|
|
|
|
|