Enknown Posted August 6, 2003 Posted August 6, 2003 I am totally new with VB.NET... I have a question here, I first created a Form (Form1) and plant a TextBox (TextBox1) on it. Then I created a Module (Module1), in this Module I have Sub Main() Now I want to retrive the value from TextBox1, how would I do that? In VB6 I would just do *something* like this: Sub Main() Dim sTest as String sTest = Form1.TextBox1.Text End Sub But How would I do It in VB.NET? Quote
jorge Posted August 6, 2003 Posted August 6, 2003 (edited) Sub Main() 'Set frm1 to your form1 Dim frm1 as Form1 Dim sTest as String sTest = Form1.TextBox1.Text End Sub In .net you need to dim each form agen. //edit: sry if the code was incorect, did nog have a comp with vb.net near at that time Edited August 6, 2003 by jorge Quote Jorge - http://www.blackdot.be/?page=apache.htm
*Experts* Bucky Posted August 6, 2003 *Experts* Posted August 6, 2003 Er, that is partially correct. You need to create a new variable to hold a new instance of the form, and then show the form using Application.Run() (only in Sub Main, that is). Public Shared Sub Main() Dim frm1 As New Form1() ' A new instance of Form 1 Dim sTest As String Application.Run(frm1) ' The code stays here until frm1 is closed sTest = frm1.TextBox1.Text End Sub ' Now the program ends Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
*Experts* Volte Posted August 6, 2003 *Experts* Posted August 6, 2003 I have absolutely no idea what you're trying to do, but I can tell you right now that that code will not do it. 1) You should not ever ever ever use modules, due to the fact that they eliminate the concept of OOP -- always use Shared procedures inside classes.'in MyClass.vb or whatever Public Shared Sub Main() 2) You need to instantiate the instance of your form:Dim frm1 As [b]New[/b] Form1 3) If you are using Sub Main(), you must manually start the main window message loop, using Application.Run(). After lines, put Application.Run(frm1)and the program will successfully start. 4) That last line, sTest = Form1.TextBox1.Textshould be this:sTest = [b]frm1[/b].TextBox1.Textbecause you need to use the instance of the class, not the class itself. At that point, it should execute... Once the program closes, the last sText line will execute. Quote
Enknown Posted August 7, 2003 Author Posted August 7, 2003 MANY THANKS! I keep *thinking* VB6 in VB.NET so I only confuse myself :rolleyes: 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.