module

hitechoutlaw

Regular
Joined
Mar 22, 2003
Messages
77
Location
USA
i'm doing a website for school on Curency Conversion, i was going to make a program to convert what the person inputs. i was thinking about using a module to store all the conversions so i can just call them from that.

i think a module is what i want but i'm new to stuff like that, and if it is a module how do i call functions from it?

thx
 
The use of modules in any object-oriented application is a poor decision. The reason(s) (God forbid there be more than one) why Microsoft included the ability to use modules in .NET blows my mind, and I prefer not to think about it. Instead, look towards using shared (static) members of a class. They're coded like so:

Visual Basic:
Class Dog

    Public Shared Sub Bark()
        'Dog barks
    End Sub 'Bark

End Class 'Dog
You can call the function like so:
Visual Basic:
Dog.Bark()
It's rather simple, as you can see.
 
You really should not use modules, you can use Property or Function in a seperate class.

You can check MSDN on this or wait a few minutes for someone here to explain.
 
the reason i said modules was because some1 helped me build a program in VB6 so i assumed it would be the same in .net.

thank guys i'll check out the MSDN to learn more on the subject.
 
ok i made a class for the labeling of the the labels and when i put in:

Label5.text = "sumthang"

it says:

"Reference to a non-shared member requires an object reference."

how do i do this?
 
you need to pass a pointer to that object to your class... or edit the label in the form's code

ie

public class Fake

public sub ChangeLabel(byval myForm as Form)

myForm.label1.text = "this"

end sub
end class

now your label will be accessible in that function
 
When i click button 1 it, it says:

An unhandled exception of type 'System.NullReferenceException' occurred in Curency Conversion.exe

Additional information: Object reference not set to an instance of an object.


here is my code:

Code:
    Class Label
        Public Shared Sub lbl5()
            Dim myForm As Form1
            myForm.Label5.Text = "Blah Blah Blah"
        End Sub
    End Class

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Label.lbl5()
    End Sub

does ne1 know what is wrong?
 
i changed it to

Dim myform as new form1()

now it doesnt do anything, it justs sits there and nothing changes, maybe my code is wrong some where but i've failed to see where. it all looks right to me :(
 
oops, hehe, i didnt see that post.

i added:

(byval myForm as Form1)

and now i cant call it, i says it requires an object Reference. i dont know what to put in the () while calling it.

thanks to all who is helping
 
Visual Basic:
Class Label
        Public Shared Sub lbl5(ByVal myform As Form1)

            myform.Label5.Text = "Blah Blah Blah"
        End Sub
    End Class

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim myf As New Form1()
        Me.Label.lbl5(myf)
        myf.Show()



    End Sub

End Class
this works but I don't know if it's what you want.
Jon
 
Your first iteration actually works also
Visual Basic:
 Class Label
        Public Shared Sub lbl5()
            Dim myForm As New Form1()
            myForm.Label5.Text = "Blah Blah Blah"
            myForm.Show()
        End Sub
    End Class

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Label.lbl5()
    End Sub
 
if u do "myForm.Show()" it loads another form, then u have two open, how come the .refresh() doesnt work, well i dunno wut is for but it didnt do what i was hoping when i tried it. is there a way to do it with out having to load another form?
 
Visual Basic:
Class Label
        Public Shared Sub lbl5()
            
            Form1.ActiveForm.Controls(1).Text = "Blah Blah Blah"
           
        End Sub
    End Class

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Label.lbl5()
    End Sub
cut and paste this I think it does what you want.....if the index of your label5 is 1
 
ok the index is 0, is there an easy way to find the index or set it? what is the index really?

thanks man u helped alot i might be able to finish it off from here with out problem but .NET is sooo differnt from 6 so i might be back in the near future.

thx again
 
Visual Basic:
    Class Label
        Public Shared Sub lbl5()

            Dim connum As Integer = 0
            For connum = 0 To Form1.ActiveForm.Controls.Count() - 1
                If Form1.ActiveForm.Controls(connum).Name() = "Label5" Then
                    Form1.ActiveForm.Controls(connum).Text = "blah blah blah"
                End If
            Next
           
        End Sub
    End Class

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Label.lbl5()
    End Sub
ok I think this will do the trick no matter what the index of your label5 is.
Jon
 
Back
Top