Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • *Gurus*
Posted

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:

 

Class Dog

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

End Class 'Dog

You can call the function like so:

Dog.Bark()

It's rather simple, as you can see.

Posted

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.

Posted

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?

Posted

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

i'm not lazy i'm just resting before i get tired.
Posted

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:

 

   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?

Posted

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 :(

Posted

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

  • *Experts*
Posted

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

  • *Experts*
Posted

Your first iteration actually works also

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

Posted
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?
  • *Experts*
Posted

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

Posted

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

  • *Experts*
Posted

   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

  • *Experts*
Posted
The index of a control is assigned as you add the control to the form....last control added has an index of 0, first control added has greatest index.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...