RSS Forums RSS
Please support our VB.NET advertiser: Programming Forums
Views: 7771 | Replies: 8 | Thread Tools  Display Modes
Reply
Join Date: Apr 2003
Posts: 2
Reputation: meandmymachine is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
meandmymachine meandmymachine is offline Offline
Newbie Poster

Why won't this code work?

  #1  
Apr 23rd, 2003
I've found some code in a book on Visual Basic.NET that doesn't seem to work properly.(The book is "Learning Visual Basic.NET Through Applications" by Clayton E.Crooks II (Charles River Media) ISBN 1-58450-242-8).

The essential problem is that the code seems to be okay on the CD which came with the book, but when I copy it into Visual Basic.NET Standard Edition, it reports some errors. I haven't reproduced the code here because it's quite long but if anyone can help, I'll gladly send it to them. All contributions gratefully accepted.

meandmymachine
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2002
Location: Tucson, AZ - formerly LI, NY
Posts: 631
Reputation: aeinstein is just really nice aeinstein is just really nice aeinstein is just really nice aeinstein is just really nice aeinstein is just really nice 
Rep Power: 12
Solved Threads: 8
Colleague
aeinstein's Avatar
aeinstein aeinstein is offline Offline
Team Member - aka kaynine
  #2  
Apr 23rd, 2003
copy & post the code here.
Reply With Quote  
Join Date: Apr 2003
Posts: 2
Reputation: meandmymachine is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
meandmymachine meandmymachine is offline Offline
Newbie Poster

Why won't this code work?

  #3  
Apr 24th, 2003
Hi Kaynine

Thanks for answering my distress call. Below I've listed the errors and below that I've reproduced the code. As I mentioned, it's not actually my code but source published in a book teaching VB.NET, which makes it all the more baffling. Many thanks for your assistance.

meandmymachine


ERROR LIST

1. "Namespace for 'System.Web.Mail' cannot be found" (line 1).

2. "Type 'MailMessage()' not defined" (line 5).

3. "Name 'MailFormat' is not declared" (line 179).

4. "Name 'MailPriority' is not declared" (line 181).

5. "Name 'SmtpMail' is not declared" (line 185 & line 191).

6. "Type 'MailAttachment' is not defined" (line 203).




Imports System.Web.Mail

Public Class Form1
Inherits System.Windows.Forms.Form
Dim msg As New MailMessage()


#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents txtTo As System.Windows.Forms.TextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents txtFrom As System.Windows.Forms.TextBox
Friend WithEvents txtServer As System.Windows.Forms.TextBox
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents txtSubject As System.Windows.Forms.TextBox
Friend WithEvents btnSend As System.Windows.Forms.Button
Friend WithEvents txtBody As System.Windows.Forms.TextBox
Friend WithEvents btnAttach As System.Windows.Forms.Button
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.txtBody = New System.Windows.Forms.TextBox()
Me.txtTo = New System.Windows.Forms.TextBox()
Me.Label1 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.txtFrom = New System.Windows.Forms.TextBox()
Me.txtServer = New System.Windows.Forms.TextBox()
Me.Label3 = New System.Windows.Forms.Label()
Me.Label4 = New System.Windows.Forms.Label()
Me.txtSubject = New System.Windows.Forms.TextBox()
Me.btnSend = New System.Windows.Forms.Button()
Me.btnAttach = New System.Windows.Forms.Button()
Me.Label5 = New System.Windows.Forms.Label()
Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog()
Me.SuspendLayout()
'
'txtBody
'
Me.txtBody.Location = New System.Drawing.Point(16, 144)
Me.txtBody.Multiline = True
Me.txtBody.Name = "txtBody"
Me.txtBody.Size = New System.Drawing.Size(456, 184)
Me.txtBody.TabIndex = 0
Me.txtBody.Text = ""
'
'txtTo
'
Me.txtTo.Location = New System.Drawing.Point(64, 16)
Me.txtTo.Name = "txtTo"
Me.txtTo.Size = New System.Drawing.Size(176, 20)
Me.txtTo.TabIndex = 1
Me.txtTo.Text = ""
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(24, 16)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(32, 23)
Me.Label1.TabIndex = 2
Me.Label1.Text = "To:"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(16, 48)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(40, 23)
Me.Label2.TabIndex = 3
Me.Label2.Text = "From: "
'
'txtFrom
'
Me.txtFrom.Location = New System.Drawing.Point(64, 48)
Me.txtFrom.Name = "txtFrom"
Me.txtFrom.Size = New System.Drawing.Size(176, 20)
Me.txtFrom.TabIndex = 4
Me.txtFrom.Text = ""
'
'txtServer
'
Me.txtServer.Location = New System.Drawing.Point(304, 16)
Me.txtServer.Name = "txtServer"
Me.txtServer.Size = New System.Drawing.Size(176, 20)
Me.txtServer.TabIndex = 5
Me.txtServer.Text = ""
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(256, 16)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(48, 23)
Me.Label3.TabIndex = 6
Me.Label3.Text = "Server:"
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(8, 80)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(48, 23)
Me.Label4.TabIndex = 7
Me.Label4.Text = "Subject:"
'
'txtSubject
'
Me.txtSubject.Location = New System.Drawing.Point(64, 80)
Me.txtSubject.Name = "txtSubject"
Me.txtSubject.Size = New System.Drawing.Size(176, 20)
Me.txtSubject.TabIndex = 8
Me.txtSubject.Text = ""
'
'btnSend
'
Me.btnSend.Location = New System.Drawing.Point(392, 56)
Me.btnSend.Name = "btnSend"
Me.btnSend.TabIndex = 9
Me.btnSend.Text = "Send"
'
'btnAttach
'
Me.btnAttach.Location = New System.Drawing.Point(392, 88)
Me.btnAttach.Name = "btnAttach"
Me.btnAttach.TabIndex = 10
Me.btnAttach.Text = "Attach"
'
'Label5
'
Me.Label5.Location = New System.Drawing.Point(16, 120)
Me.Label5.Name = "Label5"
Me.Label5.TabIndex = 11
Me.Label5.Text = "Message:"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(488, 334)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label5, Me.btnAttach, Me.btnSend, Me.txtSubject, Me.Label4, Me.Label3, Me.txtServer, Me.txtFrom, Me.Label2, Me.Label1, Me.txtTo, Me.txtBody})
Me.Name = "Form1"
Me.Text = "SMTP Mail"
Me.ResumeLayout(False)

End Sub

#End Region


Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click

With msg
.From = txtFrom.Text
.To = txtTo.Text
.Subject = txtSubject.Text
.BodyFormat = MailFormat.Text
.Body = txtBody.Text
.Priority = MailPriority.Normal
End With

If txtServer.Text <> "" Then
SmtpMail.SmtpServer = txtServer.Text
Else
MsgBox("Please enter a valid SMTP server", MsgBoxStyle.Critical, "SMTP Server Error")
Exit Sub
End If

SmtpMail.Send(msg)

End Sub


Private Sub btnAttach_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAttach.Click
OpenFileDialog1.InitialDirectory = "c:\"
OpenFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
OpenFileDialog1.FilterIndex = 2

If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
Debug.WriteLine(OpenFileDialog1.FileName())
msg.Attachments.Add(New MailAttachment(OpenFileDialog1.FileName))
End If

End Sub

End Class
Reply With Quote  
Join Date: May 2002
Location: Tucson, AZ - formerly LI, NY
Posts: 631
Reputation: aeinstein is just really nice aeinstein is just really nice aeinstein is just really nice aeinstein is just really nice aeinstein is just really nice 
Rep Power: 12
Solved Threads: 8
Colleague
aeinstein's Avatar
aeinstein aeinstein is offline Offline
Team Member - aka kaynine
  #4  
Apr 26th, 2003
i know nothing about programming; request was to facilitate others in coming to your assistance.
Reply With Quote  
Join Date: Feb 2002
Location: New York
Posts: 862
Reputation: Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light Tekmaven is a glorious beacon of light 
Rep Power: 12
Solved Threads: 17
Moderator
Tekmaven's Avatar
Tekmaven Tekmaven is offline Offline
The C# Man, Myth, Legend
  #5  
May 3rd, 2003
Sorry about the delay, I'm kinda busy. Your doing this in a Windows Forms Application, not a Web Appliction. Make a new Web Application, and it will work :-)
-Ryan Hoffman

ASP.NET Specialist / Webmaster, Extended64.com.
Please do not email or PM me with support questions. Please direct them to the forums instead.
Reply With Quote  
Join Date: May 2004
Posts: 27
Reputation: srikkanthan is on a distinguished road 
Rep Power: 5
Solved Threads: 0
srikkanthan srikkanthan is offline Offline
Light Poster

Re: Why won't this code work?

  #6  
May 12th, 2004
why don't u try and a reference to System.Web assembly (Project->Add Reference)....
Reply With Quote  
Join Date: Jun 2004
Posts: 1
Reputation: malebuterfly is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
malebuterfly malebuterfly is offline Offline
Newbie Poster

Re: Why won't this code work?

  #7  
Jun 10th, 2004
oh.this programming what I learn in the book is coreect.It can reunning.next time I tell you where the wrong in your code.in the way I come from china .can we make friends.my icq is 217824718.
Reply With Quote  
Join Date: Jul 2004
Posts: 6
Reputation: lkexpert is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
lkexpert lkexpert is offline Offline
Newbie Poster

Re: Why won't this code work?

  #8  
Jul 26th, 2004
What error u getting
Reply With Quote  
Join Date: Aug 2006
Location: India
Posts: 812
Reputation: arjunsasidharan is on a distinguished road 
Rep Power: 4
Solved Threads: 13
arjunsasidharan's Avatar
arjunsasidharan arjunsasidharan is offline Offline
Practically a Posting Shark

Re: Why won't this code work?

  #9  
Feb 14th, 2007
Originally Posted by lkexpert View Post
What error u getting


Hey guys.. its simple.. Add the Webrefference System.web n it shoud work.. :cheesy:
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 9:09 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC