class variables and module variables

nobenbien

New Member
Joined
Jul 25, 2011
Messages
4
I'm struggling with the next problem.

In excel a put a number in Cel A1: 10
next I created a simple userform with only one button.
I've also created a classmodule named: Retreivedata

The click procedure (for the userform) reads:

Dim dataretreival As New retreivedata
Public number As Double

Sub CommandButton1_Click()
number = 999
MsgBox number
dataretreival.getdata
MsgBox number ' msgbox answers with 999, but i would like this to be 10
End Sub

The code for getdata (for the class dataretreival) reads:

Sub getdata()
number = Range("a1").Value 'this value is 10, from the workbook cel A1
MsgBox number msgbox answers with "blank, nothing" but i would like this to be 10
End Sub

How can I solve this small problem, what am I doiing wrong.

Please help
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
You shoud place the Public declaration statement in a standard module, not a userform module. But in any case, what is it exactly that you are trying to class? With just one control on your userform (a button) it isn't a group of controls, so it kind of sounds like you want to class range A1:A10 for reasons that escape me. Maybe what you need is an array whose elements are the values in A1:A10.

I'm also wondering why you are wondering why the mesage box displays 999 when you are declaring the "number" variable, defining it as 999 and then showing the "number" variable as the Message Box prompt. My next question is not at all intended to sound like a wise guy, honestly just factually asking to help, what else would you expect the message box to display, and why?
 
Upvote 0
What I'm trying to do is :

I want to read the value of the cel A1 (in this case 10, but the user of the program may alter that number).

Next I want to use that number in my classes.

But somehow this doesn't work.

Best regards, klaas
 
Upvote 0

Forum statistics

Threads
1,224,550
Messages
6,179,462
Members
452,915
Latest member
hannnahheileen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top