|
How to set DateTimePicker date one month later
|
|
|
|
|
It depends on what you mean, one month later than what?
If you mean one month from another DateTimePicker then
Me.DateTimePicker2.Value = Me.DateTimePicker1.Value.AddMonths(1)
If you mean from todays date then
Me.DateTimePicker1.Value = Me.DateTimePicker1.Value.AddMonths(1)
If that doesn't get you there, please be a little more specific.
Thanks
|
|
|
|
|
|
A wild, adventurous, and untested guess: dateTimePicker.Value=dateTimePicker.Value.AddMonths(1)
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Luc Pattyn wrote: A wild, adventurous,
Stop living dangerously!
|
|
|
|
|
why?
adding a meesage to the VB forum always is an adventure, you never know what the outcome will be.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
You don't have to go as far as adding a message........just visiting the VB Forum is a wild adventure, the savage beast that is a poorly asked question is always lurking in the shadows, just waiting to jump out, to be rapidly shot down by quick CG response
|
|
|
|
|
Hello all!
So I'm having a little problem refreshing dynamic buttons on a form. I'm slowly making progress, but I want to make sure I'm doing it the right way, or maybe there is a better way. So here is some code.
So this gets the data from the database so we know what buttons to load, etc,
Private Function GetButtonData() As List(Of ButtonInfo)
Dim constr As New SqlConnection(PVDBConn)
'Dim PVDBConn As New SqlConnection("")
'cmdUpd = New SqlCommand("SelVisName", constr)
cmdUpd.CommandType = CommandType.StoredProcedure
Dim lst As New List(Of ButtonInfo)
Dim da As New SqlDataAdapter("SELECT VisId, VisName, VisEnabled, VisFlag, visPort, VisCpuName FROM tblVis ORDER BY VisId", constr)
Dim t As New DataTable
Try
constr.Open()
'PVDBConn.Open()
da.Fill(t)
For Each r As DataRow In t.Rows
lst.Add(New ButtonInfo(CInt(r("VisId")), CStr(r("VisName")), CBool(r("VisEnabled")), CBool(r("VisFlag")), CStr(r("VisPort")), CStr(r("VisCpuName"))))
Next
Here is the code that will load the buttons on the form. I have this procedure in the OnLoad event of the form. This is the first form and the main form of the program.
Private Sub GetButtonOnScreen()
GetButtonData()
Buttons = GetButtonData()
For Each bi As ButtonInfo In Buttons
If bi.Enabled Then
'Dim prtLabel As New Label,
' MsgBox(prtLabel.Text.ToString)
Dim newbutton As New Button
'this is were it determines the color is red or blue
If bi.HasChanges Then
newbutton.Image = My.Resources.pvmetal2red
Else
newbutton.Image = My.Resources.pvmetal3
End If
newbutton.Text = bi.VisText
Dim MinFont As New Font("arial", 12, FontStyle.Bold)
newbutton.Font = MinFont
newbutton.TextAlign = ContentAlignment.MiddleCenter
newbutton.Tag = bi
newbutton.Width = 102
newbutton.Height = 42
newbutton.BackColor = Color.AliceBlue
'Plus 80 for Top
newbutton.Top = 80 '+ (0 + bi.VisId)
newbutton.Left = -95 + (100 * bi.VisId)
If newbutton.Left >= 906 Then
' newbutton.Top = 160 '+ '(0 + bi.VisId)
newbutton.Top = 180
newbutton.Left = -1095 + (100 * bi.VisId)
' MsgBox(newbutton.Location.ToString)
End If
If newbutton.Left >= 906 Then
'newbutton.Top = 240 '+' (0 + bi.VisId)
newbutton.Top = 280
newbutton.Left = -2095 + (100 * bi.VisId)
End If
If newbutton.Left >= 906 Then
newbutton.Top = 380 '+ '(0 + bi.VisId)
newbutton.Left = -3095 + (100 * bi.VisId)
End If
If newbutton.Left >= 906 Then
newbutton.Top = 480 '+ (0 + bi.VisId)
newbutton.Left = -4095 + (100 * bi.VisId)
End If
If newbutton.Left >= 906 Then
newbutton.Top = 580 '+ (0 + bi.VisId)
newbutton.Left = -5095 + (100 * bi.VisId)
End If
If newbutton.Left >= 906 Then
newbutton.Top = 680 '+ (0 + bi.VisId)
newbutton.Left = -6095 + (100 * bi.VisId)
End If
If newbutton.Left >= 906 Then
newbutton.Top = 780 '+ (0 + bi.VisId)
newbutton.Left = -7095 + (100 * bi.VisId)
End If
If newbutton.Left >= 906 Then
newbutton.Top = 880 '+ (0 + bi.VisId)
newbutton.Left = -8095 + (100 * bi.VisId)
End If
If newbutton.Left >= 906 Then
newbutton.Top = 980 '+ (0 + bi.VisId)
newbutton.Left = -9095 + (100 * bi.VisId)
End If
If newbutton.Left >= 906 Then
newbutton.Top = 1080 '+ (0 + bi.VisId)
newbutton.Left = -10095 + (100 * bi.VisId)
End If
If newbutton.Left >= 906 Then
newbutton.Top = 1180 '+ (0 + bi.VisId)
newbutton.Left = -11095 + (100 * bi.VisId)
End If
newbutton.Name = bi.VisId.ToString
' newbutton.Tag = bi.PortId.ToString
AddHandler newbutton.Click, AddressOf Buttons_Click
Me.Controls.Add(newbutton)
End If
Next
End Sub
So I have a procedure written to refresh the buttons. Not sure if this is the best way.
GetButtonData()
Buttons = GetButtonData()
For Each bi As ButtonInfo In Buttons
If bi.Enabled Then
Dim newbutton As New Button
newbutton.Text = bi.VisText
Dim MinFont As New Font("arial", 12, FontStyle.Bold)
newbutton.Font = MinFont
newbutton.TextAlign = ContentAlignment.MiddleCenter
newbutton.Tag = bi
newbutton.Width = 102
newbutton.Height = 42
newbutton.BackColor = Color.AliceBlue
newbutton.Name = bi.VisId.ToString
If bi.HasChanges Then
'' newbutton.Image = My.Resources.pvmetal2red
''' newbutton.BackColor = Color.Gray
'''' newbutton.ForeColor = Color.DarkOrange
''''''' newbutton.Image = My.Resources.pvmetal3
chString = bi.VisId
Else
'''''''' newbutton.Image = My.Resources.pvmetal3
End If
Dim con As Control
For Each con In Me.Controls
If con.Name = chString Then
Me.Controls.Remove(con)
Me.Controls.Add(con)
End If
Next
'Plus 80 for Top
newbutton.Top = 80 '+ (0 + bi.VisId)
newbutton.Left = -95 + (100 * bi.VisId)
If newbutton.Left >= 906 Then
' newbutton.Top = 160 '+ '(0 + bi.VisId)
newbutton.Top = 180
newbutton.Left = -1095 + (100 * bi.VisId)
' MsgBox(newbutton.Location.ToString)
End If
If newbutton.Left >= 906 Then
'newbutton.Top = 240 '+' (0 + bi.VisId)
newbutton.Top = 280
newbutton.Left = -2095 + (100 * bi.VisId)
End If
If newbutton.Left >= 906 Then
newbutton.Top = 380 '+ '(0 + bi.VisId)
newbutton.Left = -3095 + (100 * bi.VisId)
End If
If newbutton.Left >= 906 Then
newbutton.Top = 480 '+ (0 + bi.VisId)
newbutton.Left = -4095 + (100 * bi.VisId)
End If
If newbutton.Left >= 906 Then
newbutton.Top = 580 '+ (0 + bi.VisId)
newbutton.Left = -5095 + (100 * bi.VisId)
End If
If newbutton.Left >= 906 Then
newbutton.Top = 680 '+ (0 + bi.VisId)
newbutton.Left = -6095 + (100 * bi.VisId)
End If
If newbutton.Left >= 906 Then
newbutton.Top = 780 '+ (0 + bi.VisId)
newbutton.Left = -7095 + (100 * bi.VisId)
End If
If newbutton.Left >= 906 Then
newbutton.Top = 880 '+ (0 + bi.VisId)
newbutton.Left = -8095 + (100 * bi.VisId)
End If
If newbutton.Left >= 906 Then
newbutton.Top = 980 '+ (0 + bi.VisId)
newbutton.Left = -9095 + (100 * bi.VisId)
End If
If newbutton.Left >= 906 Then
newbutton.Top = 1080 '+ (0 + bi.VisId)
newbutton.Left = -10095 + (100 * bi.VisId)
End If
If newbutton.Left >= 906 Then
newbutton.Top = 1180 '+ (0 + bi.VisId)
newbutton.Left = -11095 + (100 * bi.VisId)
End If
'''''''''''' newbutton.Name = bi.VisId.ToString
AddHandler newbutton.Click, AddressOf Buttons_Click
'''Me.Controls.Add(newbutton)
End If
Next
I have to remove the buttons, then add them back in.
Thanks for the help!
Rudy
|
|
|
|
|
You using the button_id to determine the left position of your button...
Thats really cruel ... if I may say so.
On the other hand you can do your "If newbutton.Left >= 906 Then" in a loop, but I think
you should have a break and think about what way you should choose to determine the left position.
[edit]
I meant left position not top.
[/edit]
modified on Thursday, October 29, 2009 11:11 AM
|
|
|
|
|
Ouch... Ok, let me try to understand this...
You have a series of buttons defined in your database, and you're trying to lay them out in a left-to-right, top-to-bottom format...
I think you need to come at this from a different angle. Let's set aside the actual coordinates for a second, and think of how you want to lay it out.
0 1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18 19
20 21 22 23 24 25 26 27 28 29
Something this simple has to have a pattern, and that's what algorithms are all about.
Now, if you're doing this in a static grid (As in all the controls are the same size, and all of the rows have the same number of controls), this becomes REALLY simple. Instead of using the "visid" to calculate the "Left", use it to figure out what row and column you're in.
Row Number = ID / Number of Controls in Row, rounded down
Column Number = ID Mod Number of Controls in Row
(Mod = modulus operator. A Mod B = Remainder when calculating A/B)
Example, using above grid:
ID = 17
Column Count (Number of controls in row) = 10
Row number = 17 / 10 = 1.7, rounded down to 1 -- Row 1 (Second row, since first is zero)
Column number = 17 Mod 10 = 7 -- Column 7 (8th column)
See where I'm going with this?
|
|
|
|
|
Hi Guys!
Wow! I wasn't even thinking that was my problem. But I'll do anything to make it better.
So Ian, ID=17 refers to how many rows I will have. In my database, I have an ENABLED column. So if there is a TRUE value, than the button will be built. Your right about the layout, that's exactly how I will have it. But I also need to have it so if button 23, 24, 25 is not loaded, there will be a empty space there. So each button is always locked to it's location, so if I want two groups, I can have 1 to 20 and then 40 to 60. And I have a big gap between 20 to 40.
Thanks for your help!
Rudy
|
|
|
|
|
Well, if you use the VisId field as the ID in the calculation I posted, that's exactly what you'll get.
Of course, if your buttons start at 1, you might want to subtract 1 so it starts at the top-left corner. Since the formulas are based on the ID, and not just counting through as they go, any missing IDs will cause it to skip a spot.
|
|
|
|
|
Thanks Ian! I'll give it a shot. May have to bug you if I get stuck writing out the code.
Thanks again!
Rudy
|
|
|
|
|
hi
in c language we use ellipses for unlimited no of arguments in a function
similarly what we can use in vb.net
|
|
|
|
|
look up paramarray
'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous
'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous
|
|
|
|
|
|
hi expert
i want to insert in table current datetime in sql server 2005
|
|
|
|
|
|
This is a SQL question, you should ask it in the SQL forum. You should also explain what you've tried, and where you're stuck. Although it's so trivial that the only place to be stuck would be the place where you refuse to do any research of your own, and have chosen not to own any books on the subject.
getdate()
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Hi,
I'm trying to verify a PIN code of an EMV Card using VB.
Thanks
|
|
|
|
|
Good luck with that. What have you tried ? Did you have a question ? Are you stuck somewhere ? Where ? What code do you have so far, and what is going wrong ?
If you have no idea how to do this, you could try posting on the job boards or rentacoder to hire someone to do this for you. Be careful tho, some lazy people bid on jobs there, then post them here without doing any work themselves.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Hi,
I have a project contains 10 forms, and in Form3 when I give
Dim Dtb1 as New Datatable
Then it says the error cannot give the "New" instance to the object.
But When I added another few forms, and in Form10, when I give
Dim Dtb11 as New Datatable
Simply It's accepting. What does it mean Am i have any virus? Or any other problem ?
Thanks
|
|
|
|
|
Paramu1973 wrote: I have a project contains 10 forms, and in Form3 when I give
Dim Dtb1 as New Datatable
What is it with people in other countries and illegible variable names ?
Paramu1973 wrote: Then it says the error cannot give the "New" instance to the object.
What is the ACTUAL error message ?
Paramu1973 wrote: Form10, when I give
Dim Dtb11 as New Datatable
Are you TRYING to make your code hard to maintain ?
Paramu1973 wrote: Am i have any virus?
yes, you have a virus that stops datatables from being created on forms called Form3. It's quite common.
Seriously. How could this be a virus ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
You sir, have obviously not researched the (apparently) wild virus titled refuse2readAbook.win32/mac
it has something to do with spreading from machine to man. Like the swine flu.
|
|
|
|
|
Oink. I resent that. Swines aren't machines.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|