|
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
|
|
|
|
|
32 or 64 bit?
AFAIK there is no 64 bit version.
That may be an issue
try here for help
http://support.microsoft.com/kb/278604[^]
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
|
|
|
|
|
|
Sorry, didn't spot that in the question.
You may have to compile as 32 bit. (x86)
That's pushed my envelope of knowledge on it.
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
|
|
|
|
|
how to I change the settings.
|
|
|
|
|
Since you cannot mix 32 and 64 bit code in the same process, you have to recompile your app not as Any COPU, but as x86. This forces your code to be compiled as a 32-bit app. There are no 64-bit Jet or Ole drivers, so you have no choice but to recompile your app.
|
|
|
|
|
how do I check that it is compiled as a 32 bit application?
|
|
|
|
|
For C#: Project menu -> <myprojectname> Properties. It's on the Build tab -> Platform Target.
For VB.NET: Project menu -> <myprojectname> Properties. It's on the Compile tab, click on the Advanced Compile Options button. It's the Target CPU option.
|
|
|
|
|
64 bit,
i have looked at the support link with no resolution, any other idea.
|
|
|
|