Results 1 to 22 of 22

Thread: 4 Great .NET Questions, HELP ME PLEASE

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Location
    UK
    Posts
    99

    Talking 4 Great .NET Questions, HELP ME PLEASE

    first of all the jump to vb.net from vb6 is huge, there are so many diffrences and there is some mad ide intergradion going on between languages, i have a few questions, please help me!

    1.) wheni create my application and i add a text box to a form, if i make a new sub in the form1 class i get the textbox1. dropdown menu, but if i make the sub outside of the class i dont get it, how to i inherit or import that textbox is it someit to do with makeing the friends, the code looks like this, when thery are threded:

    +Public Class form1
    +Public Sub SMTP

    the above is a threded view, there isnt any code for smtp, well there is but it is irelevent, i need to beable to get the textbox1. drop down menu thats avalible within the form1 class.

    2.) when i make a new class, i cant get messagebox, do i have to inherit or import from the base class or somit?, can someone post the code for this please

    3.) what is the diffrence between a class and a modual, when should i use a class and when should i use a modual?

    4.) this is my final question, what componet should i use for file trancfers, not winsock or the winsockapi?, or are those still the best, is there a new better .net alternative?

    many tnx in advance TRAcER out

  2. #2
    Junior Member
    Join Date
    Jun 2002
    Posts
    16

    Looking for the same thing

    If you find anything let me know and I'd do the same. Check the last post I had on accessing form controls via a sub in a module

  3. #3
    Junior Member
    Join Date
    Jun 2002
    Posts
    16

    class and module diffs

    A class can be thought more of like an object that allows you to create and set your own properties. You are not going to set custom properties. Everything in .Net is a class or an object to be accurate. You'll note the base classes such as system.windows etc etc. You can inherit from a current class and build ontop of the functionality in a custom one for your needs.

    A module is really for organizing code and seperating it from your forms code. e.g. The code behind methodology in .Net.

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    1) you can add a parameter to the Sub routine that will accept a reference to that textbox


    Sub mySub(ByRef myForm As Form)


    call it using mySub(me.Text1)


    that should work.

    2) What do you mean you cant get a message box.
    System.Windows.Forms.MesageBox.Show("hello")

    is that what you mean?

    3) Classes are objects. Modules are more global access stuff. It is more acceptable to always use classes. Modules dont even exist in other OOP languages. It is only in VB .NE for compatability with VB6.

    4) You need to look into System.Net.Sockets classes for winsock operations.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5
    Hyperactive Member
    Join Date
    Feb 2002
    Posts
    261
    Originally posted by Cander

    3) Classes are objects. Modules are more global access stuff. It is more acceptable to always use classes. Modules dont even exist in other OOP languages. It is only in VB .NE for compatability with VB6.
    Modules are exactly like classes in which all of its members are shared members.

    Shared (aka 'Static' in other languages) class members is neither a Visual Basic only concept, nor a new concept to OOP.

  6. #6
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Thats right. I was under the impression that modules did not have constructors and such so you couldnt really call it a class, but they do in fact have constructors.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Location
    UK
    Posts
    99
    "1) you can add a parameter to the Sub routine that will accept a reference to that textbox

    Sub mySub(ByRef myForm As Form)

    call it using mySub(me.Text1)

    that should work."

    ok about that, rember that .net creates the form as:

    +public class form1

    i cant seem to get it to work, the form is called from1 and the sub that needs the dropdown menu is called SMTP, basicly, i wasnt sure i i could do the following, i have code to write stuff to file, would i be better to put that code in a sub or a class? i wanted a class coz its tidyer, but i dont have a good undertsanding of class's

  8. #8
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    oopps I screwed up..change
    ByRef myForm As Form


    change the As Form to whatever control you need to pass to the sub
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Location
    UK
    Posts
    99
    so it would be:

    public sub SMTP(ByRef public class form1 As textbox1)

    ?? is that right ??

  10. #10
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    no

    ByRef mytextbox As TextBox
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Location
    UK
    Posts
    99
    i still dont get it or its not working, here is the info, can u write the stuff i need or that line?, im sure i will get it soon ,

    the sub is called SMTP
    the form is called form1
    th textbox on form1 is called textbox1

    in a threded/indentation view it looks like:

    +public class form1
    +public sub SMTP
    what is it that i need to change or add? should it be:

    +public class form1
    +public sub SMTP(ByRef public class form1 textbox1 As TextBox)

    its wrong i think, but what is it ment to be?, i you could write it the way it should be or tell me where its ment to be, im gonna have this working in not time many tnx dude, i have learnt lots already

  12. #12
    Hyperactive Member
    Join Date
    Feb 2002
    Posts
    261
    Are you trying to declare a procedure outside of a class?

    If so, then that's what's causing your errors. Everything is a 'Class' (er, 'Object' when its running), and all procedures, variables, events, etc.. need to be inside a class.

    This is probably what you want:

    Code:
    Public Class Form1
    
        'Your code
        '...
        '...
    
         Public Sub SMTP(ByRef tbTxtBx as TextBox)
    
              'Do whatever you need to do in here.
    
         End Sub
    
         '...
         '...
         'More code
    
    End Class

    EDIT:

    Wait a minute, are you trying to use a TextBox that you've already drawn on the Form? Then this is even easier.
    If you expand the 'Windows Forms Designer Generated Code' region, you will find the declarations for your TextBox. You can just access the TextBox from anywhere in your code (as long as you code inside a class).

    Oh, and what do you mean 'mad ide integration'? A universal IDE is awesome. Dont think VB.NET is even similar to VB6. I read a 600+ page book that covers (though not completely) the conversion between VB6 and VB.NET. VB.NET is a completely different language altogether.
    Last edited by Hu Flung Dung; Aug 13th, 2002 at 09:49 PM.

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Location
    UK
    Posts
    99
    dude, i said vb6 and vb.net are diffrent by planets, but since i know 0% c or c++ i am haveing touble with vb.net coz basicly its c now , im gonna try finding that declaration for the textbox, and the point of this is to get access to the textbox from out side the form1 class, i can do it from the inside but i wanna do it fom the out side

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Location
    UK
    Posts
    99
    mkay, that wont work coz my code is not inside the class, so we are back to square 1, any other ideas guys, i think we are makeing real progress here

  15. #15
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089

    hi

    First it would be better if you post your code (which I huess wont be much )

    Secondly, from What I understand from your post is that u r trying to write a sub outside the form class. Which would possible only if you enclosed it in another class ( for this is necessary in OOP)

    I hope this helps.

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Location
    UK
    Posts
    99
    this is what i have so far, the code is irelevent but hey, u asked for it and you got it:

    Public Sub SMTP(ByRef tbTxtBx As TextBox)

    Imports System.Web.Mail
    Dim mailinfo As New System.Web.Mail.MailMessage()
    With mailinfo
    .From = "you@urplace"
    .To = "myself$my.house"
    .Subject = "My SMTP Test"
    .Body = "My New Message"
    End With

    SmtpMail.SmtpServer = "MyServerName"
    SmtpMail.Send(mailinfo)

    End Sub

    Public Class Form1
    Inherits System.Windows.Forms.Form

    #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 Label1 As System.Windows.Forms.Label
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox4 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox5 As System.Windows.Forms.TextBox
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    Me.Label1 = New System.Windows.Forms.Label()
    Me.TextBox1 = New System.Windows.Forms.TextBox()
    Me.Label2 = New System.Windows.Forms.Label()
    Me.Label3 = New System.Windows.Forms.Label()
    Me.Label4 = New System.Windows.Forms.Label()
    Me.Label5 = New System.Windows.Forms.Label()
    Me.TextBox2 = New System.Windows.Forms.TextBox()
    Me.TextBox3 = New System.Windows.Forms.TextBox()
    Me.TextBox4 = New System.Windows.Forms.TextBox()
    Me.TextBox5 = New System.Windows.Forms.TextBox()
    Me.Button1 = New System.Windows.Forms.Button()
    Me.Button2 = New System.Windows.Forms.Button()
    Me.SuspendLayout()
    '
    'Label1
    '
    Me.Label1.BackColor = System.Drawing.Color.Black
    Me.Label1.Font = New System.Drawing.Font("Arial Black", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.Label1.ForeColor = System.Drawing.Color.White
    Me.Label1.Location = New System.Drawing.Point(8, 56)
    Me.Label1.Name = "Label1"
    Me.Label1.Size = New System.Drawing.Size(144, 24)
    Me.Label1.TabIndex = 0
    Me.Label1.Text = "SMTP SERVER"
    '
    'TextBox1
    '
    Me.TextBox1.Location = New System.Drawing.Point(232, 8)
    Me.TextBox1.Name = "TextBox1"
    Me.TextBox1.Size = New System.Drawing.Size(248, 20)
    Me.TextBox1.TabIndex = 1
    Me.TextBox1.Text = ""
    '
    'Label2
    '
    Me.Label2.BackColor = System.Drawing.Color.Black
    Me.Label2.Font = New System.Drawing.Font("Arial Black", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.Label2.ForeColor = System.Drawing.Color.White
    Me.Label2.Location = New System.Drawing.Point(8, 104)
    Me.Label2.Name = "Label2"
    Me.Label2.Size = New System.Drawing.Size(128, 24)
    Me.Label2.TabIndex = 2
    Me.Label2.Text = "POP SERVER"
    '
    'Label3
    '
    Me.Label3.BackColor = System.Drawing.Color.Black
    Me.Label3.Font = New System.Drawing.Font("Arial Black", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.Label3.ForeColor = System.Drawing.Color.White
    Me.Label3.Location = New System.Drawing.Point(8, 152)
    Me.Label3.Name = "Label3"
    Me.Label3.Size = New System.Drawing.Size(120, 24)
    Me.Label3.TabIndex = 3
    Me.Label3.Text = "USER NAME"
    '
    'Label4
    '
    Me.Label4.BackColor = System.Drawing.Color.Black
    Me.Label4.Font = New System.Drawing.Font("Arial Black", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.Label4.ForeColor = System.Drawing.Color.White
    Me.Label4.Location = New System.Drawing.Point(8, 200)
    Me.Label4.Name = "Label4"
    Me.Label4.Size = New System.Drawing.Size(120, 24)
    Me.Label4.TabIndex = 4
    Me.Label4.Text = "PASSWORD"
    '
    'Label5
    '
    Me.Label5.BackColor = System.Drawing.Color.Black
    Me.Label5.Font = New System.Drawing.Font("Arial Black", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
    Me.Label5.ForeColor = System.Drawing.Color.White
    Me.Label5.Location = New System.Drawing.Point(8, 8)
    Me.Label5.Name = "Label5"
    Me.Label5.Size = New System.Drawing.Size(160, 24)
    Me.Label5.TabIndex = 5
    Me.Label5.Text = "EMAIL ADDRESS"
    '
    'TextBox2
    '
    Me.TextBox2.Location = New System.Drawing.Point(232, 56)
    Me.TextBox2.Name = "TextBox2"
    Me.TextBox2.Size = New System.Drawing.Size(248, 20)
    Me.TextBox2.TabIndex = 6
    Me.TextBox2.Text = "TextBox2"
    '
    'TextBox3
    '
    Me.TextBox3.Location = New System.Drawing.Point(232, 104)
    Me.TextBox3.Name = "TextBox3"
    Me.TextBox3.Size = New System.Drawing.Size(248, 20)
    Me.TextBox3.TabIndex = 7
    Me.TextBox3.Text = "TextBox3"
    '
    'TextBox4
    '
    Me.TextBox4.Location = New System.Drawing.Point(232, 152)
    Me.TextBox4.Name = "TextBox4"
    Me.TextBox4.Size = New System.Drawing.Size(248, 20)
    Me.TextBox4.TabIndex = 8
    Me.TextBox4.Text = "TextBox4"
    '
    'TextBox5
    '
    Me.TextBox5.Location = New System.Drawing.Point(232, 200)
    Me.TextBox5.Name = "TextBox5"
    Me.TextBox5.Size = New System.Drawing.Size(248, 20)
    Me.TextBox5.TabIndex = 9
    Me.TextBox5.Text = "TextBox5"
    '
    'Button1
    '
    Me.Button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup
    Me.Button1.ForeColor = System.Drawing.Color.FromArgb(CType(224, Byte), CType(224, Byte), CType(224, Byte))
    Me.Button1.Location = New System.Drawing.Point(360, 240)
    Me.Button1.Name = "Button1"
    Me.Button1.Size = New System.Drawing.Size(120, 24)
    Me.Button1.TabIndex = 10
    Me.Button1.Text = "OK"
    '
    'Button2
    '
    Me.Button2.FlatStyle = System.Windows.Forms.FlatStyle.Popup
    Me.Button2.ForeColor = System.Drawing.Color.FromArgb(CType(224, Byte), CType(224, Byte), CType(224, Byte))
    Me.Button2.Location = New System.Drawing.Point(240, 240)
    Me.Button2.Name = "Button2"
    Me.Button2.Size = New System.Drawing.Size(112, 24)
    Me.Button2.TabIndex = 11
    Me.Button2.Text = "Cancel"
    '
    'Form1
    '
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.BackColor = System.Drawing.Color.Black
    Me.ClientSize = New System.Drawing.Size(488, 272)
    Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button2, Me.Button1, Me.TextBox5, Me.TextBox4, Me.TextBox3, Me.TextBox2, Me.Label5, Me.Label4, Me.Label3, Me.Label2, Me.TextBox1, Me.Label1})
    Me.Name = "Form1"
    Me.Text = "DOTNET MAIL Configuration"
    Me.ResumeLayout(False)

    End Sub

    #End Region

    End Class

  17. #17
    Hyperactive Member
    Join Date
    Feb 2002
    Posts
    261
    Originally posted by TrAcER
    dude, i said vb6 and vb.net are diffrent by planets, but since i know 0% c or c++ i am haveing touble with vb.net coz basicly its c now , im gonna try finding that declaration for the textbox, and the point of this is to get access to the textbox from out side the form1 class, i can do it from the inside but i wanna do it fom the out side
    You wanna access the text box on Form1 from another class?

    Code:
    Public Class Form1
         
         Dim X as new Whatever()
    
         Public Sub SendTextBox()
    
              X.RecieveTextBox( <your text box name goes here> )
    
         End Sub
    
    End Class
    
    Public Class Whatever
    
         Public Sub RecieveTextBox(ByRef tbText as TextBox)
    
              'Do whatever you want with the text box in here.
              'Or make a global variable, so I can access the text box
              'from other procedures in this class.
    
         End Sub
    
    End Class
    Hmm, I hope this is what you want.

    You must realize, EVERYTHING is either a class itself, or inside a class, and you have to pass objects to other classes through procedures like what I've mentioned above. You cannot write any code (except when importing namespaces) outside of any class.

    Why dont you put your SMTP procedure inside the Form1 class? Then you dont need to pass a text box to it.

    Oh, and your supposed to put: "Imports System.Web.Mail" on the first line of your code file. It goes before everything else, including class declarations.
    Last edited by Hu Flung Dung; Aug 14th, 2002 at 11:45 AM.

  18. #18
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    Like mentioned before: Every sub must be located in a class (or in a standard module, which is basically a class with only shared procedures).
    As long as you keep putting the SMTP sub outside of a class it won't work.

  19. #19

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Location
    UK
    Posts
    99
    lol, ok i think i got it, how woul i do it if i wanted to make another class out side of th form1 class? in threded/indentation view:

    +public class form1
    +public class SMTP

    how would iget the textbox access from the smtp class, since nither from1 or SMTP are related

    btw i hope the people reading this are learning, mabey sorting out some of there own propblems

  20. #20

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Location
    UK
    Posts
    99
    hmmm, help me again, lol as i did kinda steal the code from a tutorial(the the smtp bit) im a bit stuck i put the inport thing in above everything but did some checking as to why its haveing errors and Imports System.Web.Mail doesnt exist, it only goes as far as system there is not web bit? how do i fix this, i notice this happen to alot of tutorail like i have bits missing?

  21. #21

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Location
    UK
    Posts
    99
    muuhahahhahahahahahhaha got it, it works, now i know about puting all my stuff in class's , now, how do i use 2 textbox's e.g:
    Public Sub SMTP(ByRef textbox1 As TextBox)
    that works but what if i have 2 textbox's on the form and need access to them coz there are about 6 on mine and i need access to them all, also, i still dont know why this tutorial say use system.web.mail if it doesnt even exist am i missing something?

  22. #22
    Hyperactive Member
    Join Date
    Feb 2002
    Posts
    261
    Originally posted by TrAcER
    muuhahahhahahahahahhaha got it, it works, now i know about puting all my stuff in class's , now, how do i use 2 textbox's e.g:
    Public Sub SMTP(ByRef textbox1 As TextBox)
    that works but what if i have 2 textbox's on the form and need access to them coz there are about 6 on mine and i need access to them all, also, i still dont know why this tutorial say use system.web.mail if it doesnt even exist am i missing something?
    Maybe you have to add a reference to it.

    How are you trying to learn VB.NET? You really should go pick up a good VB.NET book and start reading it.
    www.wrox.com sells awesome programming books.

    Oh, and did you read my above posts? You are asking the same questions I've already answered.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width