hitechoutlaw Posted March 25, 2003 Posted March 25, 2003 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 Quote
*Gurus* Derek Stone Posted March 25, 2003 *Gurus* Posted March 25, 2003 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. Quote Posting Guidelines
Moderators Robby Posted March 25, 2003 Moderators Posted March 25, 2003 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. Quote Visit...Bassic Software
hitechoutlaw Posted March 25, 2003 Author Posted March 25, 2003 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. Quote
hitechoutlaw Posted March 26, 2003 Author Posted March 26, 2003 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? Quote
bpayne111 Posted March 26, 2003 Posted March 26, 2003 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 Quote i'm not lazy i'm just resting before i get tired.
hitechoutlaw Posted March 26, 2003 Author Posted March 26, 2003 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? Quote
hitechoutlaw Posted March 26, 2003 Author Posted March 26, 2003 and o yeah, i says its in the line: myForm.Label5.Text = "Blah Blah Blah" maybe that will help more Quote
*Experts* jfackler Posted March 26, 2003 *Experts* Posted March 26, 2003 I think you have to instantiated your myform dim myform as new form1 I don't think myform exists Quote
hitechoutlaw Posted March 26, 2003 Author Posted March 26, 2003 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 :( Quote
*Experts* jfackler Posted March 26, 2003 *Experts* Posted March 26, 2003 Read bpayne111 note above.... Quote
hitechoutlaw Posted March 26, 2003 Author Posted March 26, 2003 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 Quote
*Experts* jfackler Posted March 26, 2003 *Experts* Posted March 26, 2003 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 Quote
hitechoutlaw Posted March 26, 2003 Author Posted March 26, 2003 o i see it now. does the form have to be reloded to show any chages to labels? thanks again Quote
*Experts* jfackler Posted March 26, 2003 *Experts* Posted March 26, 2003 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 Quote
hitechoutlaw Posted March 26, 2003 Author Posted March 26, 2003 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? Quote
*Experts* jfackler Posted March 26, 2003 *Experts* Posted March 26, 2003 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 Quote
hitechoutlaw Posted March 26, 2003 Author Posted March 26, 2003 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 Quote
*Experts* jfackler Posted March 26, 2003 *Experts* Posted March 26, 2003 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 Quote
*Experts* jfackler Posted March 26, 2003 *Experts* Posted March 26, 2003 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. Quote
hitechoutlaw Posted March 28, 2003 Author Posted March 28, 2003 ok i've got all the labeling written and i cant find out how to add items to a combo box. nething will help, thx and o ya, ".Items.Add" wont work Quote
*Experts* jfackler Posted March 29, 2003 *Experts* Posted March 29, 2003 ComboBox1.Items.Add("hello") Quote
hitechoutlaw Posted March 29, 2003 Author Posted March 29, 2003 like i said, that wont work, thanks for ur reply though Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.