UserForm <-> Module TextBox share

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Simple question. I'm a VBA programmer who has just switched to VB .net. I'm
using a UserForm called Form1 with a text box called TextBox1.

I'd like to reference the number in the text box in the module called Engine
by using the following statement

Dim num as Double
num = Form1.TextBox1.Value

However, I can not see the TextBox1 after I finish typing "Form1". What's
going on?
 
Marknanh,

Start setting option strict on in top of your program, in the beginning it
will give some problems and than you can for a while set it to off. Using it
helps you to find errors and gives programs which process faster.

The code
Dim num as Double
num = Form1.TextBox1.Value
should be

Dim num as Double
num = Cdbl(me.TextBox1.Text)

Which says

Set the value in the textbox in my class (me), which is your form, as a
double value in the field num.

I hope this helps?

Cor
 
Simple question. I'm a VBA programmer who has just switched to VB .net. I'm
using a UserForm called Form1 with a text box called TextBox1.

I'd like to reference the number in the text box in the module called Engine
by using the following statement

Dim num as Double
num = Form1.TextBox1.Value

However, I can not see the TextBox1 after I finish typing "Form1". What's
going on?

In addition to Cor's comment, is "Form1" the name of the instance of your
form? Or is it the name of the form class?

In other words, did you do something like this anywhere:

Dim Form1 As New UserForm

num = Form1.TextBox1.Text

If Form1 is the name of your form *class* then you must get the value of
the textbox using an *instance* of the class and not the class name.

HTH a little

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top