|
Hi
I have DatePicker and the Maxdate is set to today:
I am struggling with the MinDate.
I need to set the Mindate to the 1st of 3 Months back(Keep in mind that the current month will be 3rd Month).
Ex.1
For instance if we work it out as today the MinDate has to be: 01 January 2010
Ex.2
if today is the 16th of April 2010 the min date has to be: 01 Feb 2010
I hope someone can help me with this as I am really struggling with this calculation
Thank you in advanced
modified on Tuesday, March 30, 2010 5:39 AM
|
|
|
|
|
I think this is what you want
minDate = DateAdd(DateInterval.Month, -2, Today)
minDate = DateAdd(DateInterval.Day, (Today.Day - 1) * -1, Today)
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
Thank you Steven, but if I work it from todays day it should be 01/01/2010 but the result your code gives is 3/1/2010.
I do appreciate your effort in helping.I'll try to work with this code and try to change it.
Thank you so much
|
|
|
|
|
Thank you so much Steven
I have changed the second line of code and replaced today with mindate and its working perfect.
Im just wondering now what would happen if this month has 31 days and 3 months back has only 30.
|
|
|
|
|
Member 4420534 wrote: Im just wondering now what would happen if this month has 31 days and 3 months back has only 30
Either reset your system clock to an appropriate date (not forgetting Feburary only has 28 days or 29 on Leap years).
Define a DateTime varable and use the DateSerial function to populate it with your test date, then use the testing dateTime variable instead of the current system date, to test your code.
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
Can anyone tell me how to resize an external application window from within a vb.net form? I know how to start and external application using process.start but now i need to know how to set its size when it starts.
|
|
|
|
|
Take a look at Pinvoke - SetWindowPos[^]
Tarakeshwar Reddy
There are two kinds of people, those who do the work and those who take the credit. Try to be in the first group; there is less competition there. - Indira Gandhi
|
|
|
|
|
Thanks for the help I think that will do just what I want
|
|
|
|
|
I have a webpage with text boxes, Radio Buttons and a Button.
User is to fill in the boxes and select a radio button, fill in the message box and then press send.
I want to send to an email address dependant on the radio button choice, and I cannot get it to work.
Here is the code
Public Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strName As String
Dim strAddress As String
Dim strMessage As String
Dim strType As String
Dim strSendTo As String
Dim strSendFrom As String = "WebAddress"
Dim CompleteMessage As String
strName = ContactName.Text()
strAddress = ContactAddress.Text()
strMessage = TextBox1.Text()
strType = RadioButtonList1.SelectedValue
Select Case strType
Case "sales"
strSendTo = "silverfox@live.co.uk"
Case "contractors"
strSendTo = "colin@fosbern.co.uk"
Case "general"
strSendTo = "pat@fosbern.co.uk"
Case Else
strSendTo = "enquiries@fosbern.co.uk"
End Select
CompleteMessage = "Message From Website " & vbNewLine & strSendFrom & vbNewLine & strSendTo _
& vbNewLine & vbNewLine & strType & vbNewLine & strMessage
Sendmsg(, strSendTo, CompleteMessage)
End Sub
Sendmsg is called, here, so far is what I have,
Public Sub Sendmsg(Optional ByVal msgfrom As String = "", Optional ByVal msgto As String = "", _
Optional ByVal msgmessage As String = "")
Dim SendMessage As New MailMessage
Try
With SendMessage
.To (msgto)
.From (msgFrom)
.Body (msgmessage)
.send
End With
Catch ex As Exception
End Try
End Sub
But it is starting to fall apart.
Arrghhh! I have been at this for ages.
I have the following imports
Imports System
Imports System.Net
Imports System.Net.Mail
Imports System.Net.Mail.MailMessage
It is having problems with assigning values to the to and from variables.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
|
|
|
|
|
Something like this?
Public Sub SendMessage(ByVal sTOList As String, ByVal sSubject As String, _
ByVal sBody As String, ByVal sCallingRoutine As String)
Dim oMsg As New MailMessage
With oMsg
.From = New MailAddress("xxxxxx@xxxxx.com")
For Each sAddr As String In Split(sTOList, ";")
.To.Add(sAddr)
Next
.Priority = MailPriority.Normal
.Subject = sSubject
.Body = sBody
End With
Try
Dim oSMTP As New SmtpClient
oSMTP.Host = "xxxxxxxx"
oSMTP.Send(oMsg)
Catch ex As Exception
MessageBox.Show("Could not send the status email message." & ControlChars.CrLf & _ ex.ToString, sCallingRoutine, MessageBoxButtons.OK, MessageBoxIcon.Stop)
End Try
End Sub
'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
|
|
|
|
|
Thanks, I was too tired to try again last night, but I shall have a crack with this method tonight.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
|
|
|
|
|
Problem Solved
All it took was to go and make a cup of tea!
Code so far...
Public Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strName As String
Dim strAddress As String
Dim strMessage As String
Dim strType As String
Dim strSendTo As String
Dim strSendFrom As String = "WebSite"
Dim CompleteMessage As String
strName = ContactName.Text()
strAddress = ContactAddress.Text()
strMessage = TextBox1.Text()
strType = RadioButtonList1.SelectedValue
Select Case strType
Case "sales"
strSendTo = "sales@ACME.co.uk"
Case "contractors"
strSendTo = "colin@ACME.co.uk"
Case "general"
strSendTo = "pat@ACME.co.uk"
Case Else
strSendTo = "enquiries@ACME.co.uk"
End Select
CompleteMessage = "Message From Website " "
I want the complete message to show the name of the sender, their address on the next line and the type on the third.
Then a two line gap for the message itself.
So, How do I add a Carriage Return to the message?
I have tried googling, but found unsatisfactory answers.
------------------------------------
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 Monday, March 29, 2010 3:02 PM
|
|
|
|
|
CompleteMessage = "The person's name" & ControlChars.CrLf & _
"The address" & ControlChars.crlf & ControlChars.crlf & _
"The remaining part of the message....................."
'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
|
|
|
|
|
My teacher want's me to design a program that does this. "Design a program that has five buttons, one for each grade. Each time you press a button it increments that grade by one. At the same time it updates a label that displays the current percent of students that passed the exam (grade higher than F)." This is what I have so far...
Public Class Form1
Private Sub btnA_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnA.Click
Static intA As Integer = 0
intA = intA + 1
lblGradea.Text = intA
End Sub
Private Sub btnB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnB.Click
Static intB As Integer = 0
intB = intB + 1
lblGradeb.Text = intB
End Sub
Private Sub btnC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnC.Click
Static intC As Integer = 0
intC = intC + 1
lblGradec.Text = intC
End Sub
Private Sub btnD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnD.Click
Static intD As Integer = 0
intD = intD + 1
lblGraded.Text = intD
End Sub
Private Sub btnF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnF.Click
Static intF As Integer = 0
intF = intF + 1
lblGradef.Text = intF
End Sub
End Class
I need help on that part that displays what percentage of students are passing. I assume you have to add together the toal number of grades and then divide by the total number above F and display that in a label. But I cant seem to figure that out...Thanks
modified on Tuesday, March 30, 2010 10:18 AM
|
|
|
|
|
My interpretation of the problem is that every time you press a button, the number of students with that particular grade is incremented.
That means that your result must be sum(intA to intE)/ sum(intA to intF).
|
|
|
|
|
I don't normally do student's homework, but seeing as you have attempted to solve the problem here is some pointers...
Remove the lines that declare the STATIC integer and make the PRIVATE member variables e.g.
Public Class Form1
Private intA As Integer
Private intB as Integer
Private intC as Integer
Private intD as Integer
Private intF as Integer
In the Form_Load Event handler, initiate the starting values e.g.
intA = 0
intB = 0
Now all you need is a Function to return the averages.
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
 I figured it out Thank you both for steering me in the right direction. Not sure if its the most effcient way of making the program but it does what it's supposed to. Here is the final code...
'Adam Wike
'Computer Programming 1
'Grade Counter
'Created on March 28, 2010
'Last Modified on March 30, 2010
Public Class Form1
'Declared all variables
Private intA As Integer
Private intB As Integer
Private intC As Integer
Private intD As Integer
Private intF As Integer
Private intE As Integer
'Sets the variables to 0
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
intA = 0
intB = 0
intC = 0
intD = 0
intF = 0
End Sub
'Sets up the counter and calculates the percentage for each button
Private Sub btnA_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnA.Click
intA = intA + 1
lblGradea.Text = intA
intE = ((intA + intB + intC + intD) / (intA + intB + intC + intD + intF)) * 100
lblPassing.Text = Math.Round(intE, 2) & "%"
End Sub
Private Sub btnB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnB.Click
intB = intB + 1
lblGradeb.Text = intB
intE = ((intA + intB + intC + intD) / (intA + intB + intC + intD + intF)) * 100
lblPassing.Text = Math.Round(intE, 2) & "%"
End Sub
Private Sub btnC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnC.Click
intC = intC + 1
lblGradec.Text = intC
intE = ((intA + intB + intC + intD) / (intA + intB + intC + intD + intF)) * 100
lblPassing.Text = Math.Round(intE, 2) & "%"
End Sub
Private Sub btnD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnD.Click
intD = intD + 1
lblGraded.Text = intD
intE = ((intA + intB + intC + intD) / (intA + intB + intC + intD + intF)) * 100
lblPassing.Text = Math.Round(intE, 2) & "%"
End Sub
Private Sub btnF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnF.Click
intF = intF + 1
lblGradef.Text = intF
intE = ((intA + intB + intC + intD) / (intA + intB + intC + intD + intF)) * 100
lblPassing.Text = Math.Round(intE, 2) & "%"
End Sub
End Class
|
|
|
|
|
adamwike wrote: intE = ((intA + intB + intC + intD) / (intA + intB + intC + intD + intF)) * 100
lblPassing.Text = Math.Round(intE, 2) & "%"
The above should not be repeated in every button click event. Consider making in a sub-routine for example :
Private Sub CalcIntE()
intE = ((intA + intB + intC + intD) / (intA + intB + intC + intD + intF)) * 100
lblPassing.Text = Math.Round(intE, 2) & "%"
End Sub
Then replace the necessary code in each button click event with CalcIntE
for example
Private Sub btnA_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnA.Click
intA = intA + 1
lblGradea.Text = intA
CalcIntE
End Sub
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
Your right, that is a lot less confusing and makes the program look less cluttered. Thanks!
|
|
|
|
|
adamwike wrote: that is a lot less confusing and makes the program look less cluttered
Not only that, but more importantly, it is more maintainable.
Steve Jowett
-------------------------
Real programmers don't comment their code. If it was hard to write, it should be hard to read.
|
|
|
|
|
i want to copy web page contents into a text file or excel using any script
how it will possible
please guide me
Regards
|
|
|
|
|
Use the HTTP classes to navigate tot he desired page and obtain its contents. then use the TextWriter to dump it to a filestream.
That is one method.
|
|
|
|
|
mates,
Is it possible to have to checkbox in single column of datagridview? If possible, how to do that? Thanks.
C# コードMicrosoft End User
2000-2008
「「「「「「「「「「「「「「「「「「「「「「「「「「「「
The best things in life are free
」」」」」」」」」」」」」」」」」」」」」」」」」」」」
|
|
|
|
|
|
I have installed an application that I have written on a windows 7 6g bit machine I am getting the follow error
Microsoft.Jet.OleDb.4.0 provider is not registered on the local machine.
any idea on how to fix it
by compiling code to x86 the program works in win 7 64 bit edition
modified on Sunday, March 28, 2010 9:49 PM
|
|
|
|