|
This is a Windows Print Preview window that gets loaded from the Main window/app. When I end the process in the Task manager, task manager responds with application not responding for both the main app and the print preview. Task manager then shut both down, main app and print preview.
|
|
|
|
|
I want to pick a value from a DateTimePicker in 'MM/dd/yyyy hh:mm tt' format, add 00 as second with it, store it in a DateTime variable and save it to database. Suppose if I pick the value 05/28/2010 9:25 AM or 05/28/2010 9:25:34 AM from the DateTimePicker, it'll be stored in the variable and saved to database as 05/28/2010 9:25:00 AM irrespective of what value is chosen from the DateTimePicker for second. I'm using the following statement but it's getting failed during the format conversion while storing it in the DateTime variable generating an error.
Dim dtmReminderTime As DateTime
dtmReminderTime = DateTime.Parse(Format(dtpReminderTime.Value, "MM/dd/yyyy hh:mm") + ":00 " + Format(dtpReminderTime.Value, "tt"))
I tried the other way but failed:
dtmReminderTime = Convert.ToDateTime(Format(dtpReminderTime.Value, "MM/dd/yyyy hh:mm") + ":00 " + Format(dtpReminderTime.Value, "tt"))
I have also tried using culture specific information but of no avail. Please help.
|
|
|
|
|
Don't convert datetimes (or floats or anything that isn't really a string) to strings just for performing some operation on it, there always is a better way.
If your DateTime holds some seconds, and you want to get rid of them, try this (example is C# code, VB is similar):
DateTime dt1=myDateTimePicker.Value;
DateTime dtWithoutSeconds=dt1.AddSeconds(-dt1.Second);
Warning: if the initial DateTime holds fractions of a millisecond (e.g. when it comes from DateTime.Now) then this technique won't work, as there is no easy way to get the amount of ticks that corresponds to that fraction of a millisecond.
|
|
|
|
|
Dim dtmReminderTime As Date = Nothing
With dtpReminderTime.Value
dtmReminderTime = New Date(.Year, .Month, .Day, .Hour, .Minute, 0)
End With
Debug.Writeline(dtmReminderTime.ToString)
I don't speak Idiot - please talk slowly and clearly
'This space for rent'
Driven to the arms of Heineken by the wife
|
|
|
|
|
I'm trying to match a certain DateTime value with the current system DateTime. I have a timer and a label on a form. Timer interval is set to 1000. When the form loads, the timer starts ticking. As soon as the current DateTime matches the value of the variable, it shows a message in the label.
When I'm writing the following code, the values don't match even if the current system DateTime is equal to the variable. Label1 isn't showing 'Times Matched':
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim dtmNow As DateTime
dim dtmVar as DateTime=#04/28/2010 03:25:00 AM#
dtmNow = Now
If dtmVar = dtmNow Then Label1.Text = "Times Matched"
End Sub
But when I'm writing the same code by parsing 'Now' into DateTime it's working fine.
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim dtmNow As DateTime
dim dtmVar as DateTime=#04/28/2010 03:25:00 AM#
dtmNow = DateTime.Parse(Now.ToString)
If dtmVar = dtmNow Then Label1.Text = "Times Matched"
End Sub
Why is it so? The default format of 'Now' is the same as I have stored in dtmVar variable. So there's no question of format mismatch. Does that mean 'Now' is not actually a DateTime property?
Provided, my O.S. is Windows Vista Ultimate and all date/time settings are set to default.
Regards.
|
|
|
|
|
DateTime has a resolution of 1 tick, i.e. one 10 millionth of a second.
DateTime.ToString() shows time to some resolution, probably up to a second or so; this means two DateTimes that look the same (as they produce the same ToString result) may be actually quite different.
It is in general a bad idea to compare two DateTimes for equality.
Have you ever done floating point calculations? There too it is a bad idea to test for equality.
Either you need to allow some tolerance, as in If value1 < value2+somethingSmall (pretty common in floating-point algorithms), or you really need an inequality test, as in if Now>=alarmTime
|
|
|
|
|
Hi:
I have an application, which I can only change via script. I need to find a way to clean the keyboard buffer and then block it, because sometimes press the keys too fast and run events in the application that should not run. I can not change the hard code. Hopefully I can help
|
|
|
|
|
What do you mean "only change via script"? Are you saying that this application has it's own scripting language? Are yousaying that you can only use VBScript? What?
|
|
|
|
|
Is there a simple way to convert a decimal to an hexidecimal?
|
|
|
|
|
Since everything is represented internally in Binary, the only "hexadecimal conversion" you're going to get would be when it's formatted into a string for display or some other human-readable purpose. That would be String.Format("{0:X}", value) .
|
|
|
|
|
In VB.Net...
dim string hex = Convert.ToString(i, 16);
Or in VB6...
use a textbox and three labels:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
KeyAscii = 0
Label1.Caption = Hex$(Text1.Text)
If Len(Label1.Caption) < 4 Then
Label2.Caption = "00"
Label3.Caption = Label1.Caption
Else
Label2.Caption = Left$(Label1.Caption, 2)
Label3.Caption = Right$(Label1.Caption, 2)
End If
End If
End Sub
Run the program, type any integer legal number value and press ENTER.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
modified on Friday, April 30, 2010 10:27 AM
|
|
|
|
|
Dalek Dave wrote: Label1.Caption
That looks very vb6 to me...........in fact it all does.
Are you crossing to the dark side?
|
|
|
|
|
Shhh!
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
|
|
|
|
|
|
Thanks for the help guys
|
|
|
|
|
I have a project that I'm working on and my boss wants me to add the buttons to the tool strip at runtime based on different things (those I'll worry about later). I've gotten pretty far on my own but am now stuck on the "click event". I can get the buttons to display but can't get them to do anything once they are there other than look good. I'm in the testing stage now so it's nothing impressive but as I said it works up to the point of displaying in the manner I need it to.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Create a button for the tool strip
Dim btnSomething As New ToolStripButton
btnSomething.Text = "Test 1"
btnSomething.Image = Image.FromFile("F:\VisualBasic\ToolStripTest\images\eventlog.ico")
btnSomething.TextImageRelation = TextImageRelation.ImageAboveText
btnSomething.ToolTipText = "This is Just a Test"
Dim btnSomething2 As New ToolStripButton
btnSomething2.Text = "Test 2"
btnSomething2.Image = Image.FromFile("F:\VisualBasic\ToolStripTest\images\eventlog.ico")
btnSomething2.TextImageRelation = TextImageRelation.ImageAboveText
btnSomething2.ToolTipText = "This is Just a Test again"
'Display a separator with followed by the two created buttons followed by another separator
ToolStrip1.Items.Add(New System.Windows.Forms.ToolStripSeparator)
ToolStrip1.Items.Add(btnSomething)
ToolStrip1.Items.Add(btnSomething2)
ToolStrip1.Items.Add(New System.Windows.Forms.ToolStripSeparator)
End Sub
Thank you all in advance...
modified on Friday, April 30, 2010 12:37 PM
|
|
|
|
|
AddHandler btnSomething.Click, AddressOf ClickRoutine 'add handler here
where click Routine is some predefined subroutine
Thanks for taking the time, now go away and grow up and return in a newer, more polite and less shouty and ignorant form. - Dalek Dave
|
|
|
|
|
I have added
btnSomething.ToolTipText = "This is Just a Test"
AddHandler btnSomething.Click, AddressOf ClickRoutine
(included the line above it to show location)
and I get the following error message:
Method 'Public Sub ClickRoutine()' does not have the same signature as delegate 'Delegate Sub EventHandler(sender As Object, e As System.EventArgs)'
if I make it ClickRoutine() I get:
'AddressOf' operand must be the name of a method (without parentheses).
I did create the following:
Sub ClickRoutine()
MessageBox.Show("It works")
End Sub
Now if I add a second button to the form I can call that no problem:
AddHandler btnSomething.Click, AddressOf Button2_Click
|
|
|
|
|
I seem to have answered by own question in a round about way. I have made the following changes and it now works:
btnSomething.ToolTipText = "This is Just a Test"
AddHandler btnSomething.Click, AddressOf ClickRoutine
and
Private Sub ClickRoutine(ByVal sender As System.Object, ByVal e As System.EventArgs)
MessageBox.Show("It works")
End Sub
by adding the ByVal sender As System.Object, ByVal e As System.EventArgs that seems to allow it to work. I guess we learn something new every day...
|
|
|
|
|
Hi
You need to add a delegate to the ToolStripButton to handle it's Click event. First create the routines that you want to fire when the user clicks on the button (remember that it must have the same signature as a 'normal' click event handler). For example in your app you could create 2 routines like so
Private Sub btnSomething_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
MsgBox(CType(sender, ToolStripButton).ToolTipText & ", " & CType(sender, ToolStripButton).Text)
End Sub
Private Sub btnSomething2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
MsgBox(CType(sender, ToolStripButton).ToolTipText & ", " & CType(sender, ToolStripButton).Text)
End Sub
Then when you create the buttons add your delegates like this
Dim btnSomething As New ToolStripButton
btnSomething.Text = "Test 1"
btnSomething.TextImageRelation = TextImageRelation.ImageAboveText
btnSomething.ToolTipText = "This is Just a Test"
AddHandler btnSomething.Click, AddressOf btnSomething_Click
Dim btnSomething2 As New ToolStripButton
btnSomething2.Text = "Test 2"
btnSomething2.TextImageRelation = TextImageRelation.ImageAboveText
btnSomething2.ToolTipText = "This is Just a Test again"
AddHandler btnSomething2.Click, AddressOf btnSomething2_Click
ToolStrip1.Items.Add(New System.Windows.Forms.ToolStripSeparator)
ToolStrip1.Items.Add(btnSomething)
ToolStrip1.Items.Add(btnSomething2)
ToolStrip1.Items.Add(New System.Windows.Forms.ToolStripSeparator)
then you should get the click events to fire. See thread 2 or 3 down for further example
Happy Coding
|
|
|
|
|
Ok so this is now working great, and I really do appreciate the help. Of three forums this is the only one I've gotten a response on.
Now I've been trying to figure out how to get this to work with a module. The "buttons" need to be available to different forms in the project thus the reason for adding them at run time.
I've tried:
ToolStrip1.Items.Add(Call Buttons(btnSomething2))
as I have used Call 'sub in the module'('variable') in the past and it has worked. Though when I try it in this respect I get "Expression Expected" where Call is.
This is the Module I created:
Module ToolStripBtns
Sub Buttons()
Dim btnSomething As New ToolStripButton
btnSomething.Text = "Test 1"
btnSomething.Image = Image.FromFile("F:\VisualBasic\ToolStripTest\images\eventlog.ico")
btnSomething.TextImageRelation = TextImageRelation.ImageAboveText
btnSomething.ToolTipText = "This is Just a Test"
AddHandler btnSomething.Click, AddressOf btnSomething_Click
End Sub
Private Sub btnSomething_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
MsgBox(CType(sender, ToolStripButton).ToolTipText & ", " & CType(sender, ToolStripButton).Text)
End Sub
End Module
I trimmed out some of the "junk" to make it shorter...
Thank you again!
|
|
|
|
|
Hi
Try this
Module ToolStripBase
Public Enum ButtonFunction
Something1
Something2
End Enum
Public Function CreateButton(ByVal ButtonImage As Image, ByVal ButtonText As String, ByVal ButtonToolTipText As String, ByVal MyFunction As ButtonFunction) As ToolStripButton
Dim btnSomething As New ToolStripButton
btnSomething.Text = ButtonText
btnSomething.Image = ButtonImage
btnSomething.TextImageRelation = TextImageRelation.ImageAboveText
btnSomething.ToolTipText = ButtonToolTipText
Select Case MyFunction
Case ButtonFunction.Something1
AddHandler btnSomething.Click, AddressOf SomethingClick
Case ButtonFunction.Something2
AddHandler btnSomething.Click, AddressOf Something2Click
End Select
Return btnSomething
End Function
Private Sub SomethingClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
MsgBox(CType(sender, ToolStripButton).ToolTipText & ", " & CType(sender, ToolStripButton).Text)
End Sub
Private Sub Something2Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
MsgBox(CType(sender, ToolStripButton).ToolTipText & ", " & CType(sender, ToolStripButton).Text)
End Sub
End Module
Then from each form you can create each button as it is needed like this
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim MyToolStrip As New ToolStrip
Dim Button1 As ToolStripButton = ToolStripBase.CreateButton(Nothing, "Test 1", "This a test", ButtonFunction.Something1)
Dim Button2 As ToolStripButton = ToolStripBase.CreateButton(Nothing, "Test 2", "This another test", ButtonFunction.Something1)
MyToolStrip.Items.Add(Button1)
MyToolStrip.Items.Add(Button2)
MyToolStrip.Parent = Me
End Sub
Happy Coding
|
|
|
|
|
This so far has been the best idea/method for doing what I need to. I'm just wondering is there a way to pass a value from the Form to the module? For example I created a copy button that would be used to copy selected text. I have another version with a Class that has the copy function locally to the form and works fine, but I can't see a way to get that working from the Module. I'm basically typing about 90% of the code on each form which isn't really much of a savings. I understand that this part of the project is a bit out of my league and I do appreciate your help. Thank you again!!
|
|
|
|
|
Hello every one. My objective is to read data from .xls and process in VB.net application. I do have a desktop application which even reads data from a remote DB. I have the following clarification and issues
- The application will be installed on different systems and we cannot make it sure that all the systems should have MS Office installed and that too a particular version
- Can’t we somehow access data from and to excel files without using Ms Excel components, so that the application should also work on a system where MS Excel is not installed also
Regards
Nishkarsh
|
|
|
|
|
You can read/write Excel sheets using OleDb, an example of which you can find here[^]. I'm not quite sure, but I don't think you need Excel installed at all in order to use this method. ANy other method requires Excel to be installed.
|
|
|
|