|
I guess its very simple. You should take a variable to save the time during which timer is running. whenever user clicks start it should start the timer from zero and when he stops it you just take the difference using TimeSpan object and add it to the variable you are using for saving the time.
Ahsan Ullah
Senior Software Engineer
|
|
|
|
|
There are couple of ways to do this:
(1) Use the timer object (this is very simple)
(2) Use the DateTime class.
Best Regards,
Sam Xavier
www.componentone.com
|
|
|
|
|
Use the StopWatch class. Use the Start and Stop methods to control it and the Elapsed property to get the total time.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
* I need help in learning how to set grammar in SAPI 5.1 to perform Voice command
The code I have is able to do dictation, now I just wanted to expand to do voice command with a preset XML grammar.
Please help up
Sample code will helps too. - boyzwong@gmail.com
Thank you
'Default Imports
Imports System
Imports System.Data
Imports System.Deployment
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Xml
Imports SpeechLib.SpeechGrammarWordType
'Custom Imports
Imports SpeechLib
Public Class Form1
'Declares
Dim WithEvents RecoContext As SpSharedRecoContext 'The Main Recognition Object Used throughout the whole program. -- Shared Object: More Info on this later.
Dim Grammar As ISpeechRecoGrammar 'The Grammar Object so the program knows what is going on. -- Instanced Object: More Info on this later.
Dim CharCount As Integer 'This is used to count the amount of chars that are in the text box.
''''Subs Start Here
'Start Button. This will engage reco, and start the entire process.
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
If (RecoContext Is Nothing) Then
RecoContext = New SpSharedRecoContextClass 'Create a new Reco Context Class
Grammar = RecoContext.CreateGrammar 'Setup the Grammar
'Grammar.DictationLoad() 'Load the Grammar
Grammar.CmdLoadFromFile("c:\gram.xml", SpeechLib.SpeechLoadOption.SLODynamic)
End If
lblstatus.Text = "Recognition Started" 'Change the Label to let the user know whats up
Grammar.DictationSetState(SpeechRuleState.SGDSActive) 'Turns on the Recognition. This is Vitally important
'This is so the user doesn't break the program by
'trying to start the recognition after its already started.
btnstart.Enabled = False
btnstop.Enabled = True
End Sub
'Stop Button. This will stop stop the recoginition
Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
Grammar.DictationSetState(SpeechRuleState.SGDSInactive) 'Turns off the Recognition. It will go dormant.
lblStatus.Text = "Recognition Stopped" 'Change the label to let the user know whats up
'Again This is so the user doesn't go breaking things accidently
btnStart.Enabled = True
btnStop.Enabled = False
End Sub
'This is the hypothesis sub. The hypothesis is not the final recognition. This will fire many times per word. You do not want to print anything that is final from the hypothesis.
'This is not required for the final recognition. But it is vital to understand it.
Private Sub OnHypo(ByVal StreamNumber As Integer, ByVal StreamPosition As Object, ByVal Result As ISpeechRecoResult) Handles RecoContext.Hypothesis
btnStop.Enabled = False 'Don't allow the user to stop the recognition until it has completed.
'The button will re-enable in the OnReco Event
'This is so you don't kepp printing the same text over and over. It could take up just a tiny bit more processor power
'Its good to not do un-needed things.
If lblStatus.Text <> "Receiving" Then
lblStatus.Text = "Receiving"
End If
End Sub
'This sub is fired when the reco engine detects a set of words. This is what you want to use to print or sendkey.
'Use this sub for the final printing of words.
Private Sub OnReco(ByVal StreamNumber As Integer, ByVal StreamPosition As Object, ByVal RecognitionType As SpeechRecognitionType, ByVal Result As ISpeechRecoResult) Handles RecoContext.Recognition
Dim recoResult As String = Result.PhraseInfo.GetText 'Create a new string, and assign the recognized text to it.
'This block will print to the textbox built into the program
'If you would prefer to use the SendKeys method, Comment out this entire block. And Uncomment the SendKeys Line.
txtBox.SelectionStart = CharCount
txtBox.SelectedText = recoResult & " "
CharCount = CharCount + 1 + Len(recoResult)
If txtbox.Text.Contains("testing") Then
Beep()
End If
'Uncomment the next line if you want to send the text to the selected window rather than constrain it to the textbox.
'SendKeys.Send(recoResult & " ") 'This line sends the result via SendKeys to the top window.
lblStatus.Text = "Finished Dictating"
btnStop.Enabled = True
End Sub
End Class
XML
<!-- Language ID = British English -->
<GRAMMAR LANGID="413" LEXDELIMITER="|" WORDTYPE="LEXICAL">
<RULE NAME="HelloWorld" TOPLEVEL="ACTIVE">
<!-- when the user says the following pronunciation, "Hiya" will be displayed -->
<P>Hello World</P>
</RULE>
</GRAMMAR>
modified on Thursday, July 31, 2008 5:57 PM
|
|
|
|
|
cw342cw wrote: Sample code will helps too. - boyzwong@gmail.com
Not a good idea to put email address in the post. You open yourself up to spammers. There is an email link at the bottom of the post that people may use if they really want to send you an email.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hi all,
I am trying to assign image to unknown control as follows.
abcd(ByRef element As System.Windows.Forms.Control)
{
CType(element, PictureBox).Image = frmMain.DefInstance.imlMain("Image1")
}
But, its giving casting error. Please let me know the solution.
Thanks in Advance.
AR Reddy
|
|
|
|
|
if typeof(element)==typeof(PictureBox)
CType(element, PictureBox).Image = frmMain.DefInstance.imlMain("Image1")
else
yadada yadda
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios
Discounted or Free Software for Students:
DreamSpark - downloads.channel8.msdn.com
MSDN Academic Alliance - www.msdnaa.com
|
|
|
|
|
Hi Thomas,
Thanks for the reply.
yadada yadda ????
what should we do if the element is not a picturebox type?
Thanks in advance,
AR Reddy
|
|
|
|
|
You don't have to do anything, you just have the initial if statement. When something isn't iffed then the function just ends. Besides, I had to include yadda yadda because I needed to add some technical lingo that no one would understand .
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios
Discounted or Free Software for Students:
DreamSpark - downloads.channel8.msdn.com
MSDN Academic Alliance - www.msdnaa.com
|
|
|
|
|
Thanks!
AR Reddy
|
|
|
|
|
For starters, you seem to be mixing C# elements with VB code.
Second, assuming that imlMain is an image list, the .Net version does not have a default property. Because of this, you must explicitly reference the Images collection.
Third, DefInstance is a hack Microsoft added to the .Net framework to manage code translated from VB6. Assuming that this method is inside the form being referenced, this should work:
Public Sub abcd(ByRef element As System.Windows.Forms.Control)
CType(element, PictureBox).Image = Me.imlMain.Images("Image1")
End Sub
Properly, though, you should make sure that element really is a PictureBox. The easiest way to do this is with TryCast rather than CType. They do the same basic thing, but TryCast will return Nothing if the conversion fails. Your method would then look like this:
Public Sub abcd(ByRef element As System.Windows.Forms.Control)
Dim PB As PictureBox = TryCast(element, PictureBox)
If PB IsNot Nothing Then PB.Image = Me.imlMain.Images("Image1")
End Sub
|
|
|
|
|
As far I as I am concerned (since I do this to), a mix of multiple languages to convey a clear message is considered a type of pseudocode. You don't have to know any particular language to understand the basics of pseudocode.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios
Discounted or Free Software for Students:
DreamSpark - downloads.channel8.msdn.com
MSDN Academic Alliance - www.msdnaa.com
|
|
|
|
|
Just covering all the bases.
|
|
|
|
|
Here is a little code snippet...
Private Sub TextNet_Change()
If TextNet <> "" Then
Dim DCalcVat As Long
Dim DCalcGross As Long
Dim DCalNet As Long
DCalcNet = TextNet
LabelFrameNet = DCalcNet
DCalcVat = DCalcNet / 100 * 17.5
TextVat = DCalcVat
DCalcVat = TextVat
LabelFrameVat = TextVat
DCalcGross = DCalcNet + TextVat
TextGross = DCalcGross
LabelFrameGross = DCalcGross
End If
End Sub
I want the TextBox (TextGross) and the Lable (LabelFrameGross) to both show the final DCalcGross value.
(I know it is Dim'd as a Long, but I tried Double wich is why it is currently a (D)CalcGross)
Am I missing something here?
------------------------------------
"I want you to imagine I have a blaster in my hand" - Zaphod Beeblebrox.
"You DO have a blaster in your hand" - Freighter Pilot
"Yeah, so you don't have to tax your imagination too hard" - Zaphod Beeblebrox
|
|
|
|
|
TextBox = format(DCalcGross, "0.00")
LabelFrameGross = format(DCalcGross, "0.00")
Tim
|
|
|
|
|
Thank you my friend.
It is amazing how easy that was, I don't know why I didn't get there myself.
I must have been having a "Dim" day!
------------------------------------
"I want you to imagine I have a blaster in my hand" - Zaphod Beeblebrox.
"You DO have a blaster in your hand" - Freighter Pilot
"Yeah, so you don't have to tax your imagination too hard" - Zaphod Beeblebrox
|
|
|
|
|
Sorry, this is a stupid question.
I have a class library project stored in a file "c:\test1" It creates a .dll named test1.dll. I want to rename the entire project and assembly to "final" which will create "final.dll". I'm finding that if I copy the project to a different folder I can't load it. What's the solution. Basically I want to "save project as..."
Thanks
|
|
|
|
|
You need to change the solution properties.
VS2008:
1) Right-click project properties
2) Edit Assembly Name
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios
Discounted or Free Software for Students:
DreamSpark - downloads.channel8.msdn.com
MSDN Academic Alliance - www.msdnaa.com
|
|
|
|
|
|
Hi
I want to access the items added in the list box or combo box on right click.
Example
List box contains:
ITEM(0)"First"
ITEM(1)"Second"
ITEM(2)"Third"
values have been populated and program is running now i "Right Click" on list box
what i want , the index number of the item on which mouse was Right clicked.
Thanx in anticipation
Riaz Ahmed
0300-2668545
Software Engineer
DCCTechnologies
riaz.ahmed@dcc.com.pk
|
|
|
|
|
On mouse up event of list box you can use IndexFromPoint method to get index of item which has been clicked. This index can be used to retrieve the actual listbox item, such as –
------------------------------------------
Private Sub ListBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseUp
Dim ItemName As String
If e.Button = Windows.Forms.MouseButtons.Right Then
ItemName = Me.ListBox1.Items.Item(Me.ListBox1.IndexFromPoint(e.X, e.Y)).ToString()
MessageBox.Show(ItemName)
End If
End Sub
-------------------------------------------
I hope this helps .
-Dave.
------------------------------------
http://www.componentone.com
------------------------------------
|
|
|
|
|
Hi All,
I want to check the menuitem visibilty. Menu items will be coming through recordset and will loop through the recordset. For each menuitem, I want to check the visibility like as follows.
frmMain.DefInstance.Controls(rstRef.Fields("cname")).Visible
but, abouve code is giving cast error.
if we hardcode the menu Item, its working fine. like as follows
frmMain.DefInstance.MenuItem1.Visible
But, if I want to check the menu item visibilty dynamically, how can I do?
Please let me know.
Thanks in Advance.
AR Reddy
|
|
|
|
|
for each mi as menuitem in frmmain.definstance.controls
if mi.visible = true then
'your code
end if
next
"I love deadlines. I like the whooshing sound they make as they fly by." (DNA)
|
|
|
|
|
Hi Jones,
Thanks a lot. Its working with little bit modifications. Thanks again.
AR Reddy
|
|
|
|
|
Hi Smithers-Jones,
With the given code is working fine but, its looping through all the menuitems that are in the form. But I want to checkfor few menus (that will come from recordset) only.
so from your given code, if I check mi.Name, Im not getting menu name.
like as follows,
Dim str as String = recset("cname")
for each mi as menuitem in frmmain.definstance.controls
if mi.Name == str
if mi.visible = true then
'your code
end if
next
So i am not able to check visibility property for few menu items.
How can I do this. Please let me know the solution if you get a chance to look into this.
Thanks in Advance,
AR Reddy
|
|
|
|