ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Example form Book (https://www.excelbanter.com/excel-programming/375184-example-form-book.html)

Jim May

Example form Book
 
This code is right-out-of-the-book:

(In sheet1 Object module)
Option Explicit
Option Base 1
Dim Sales() As String
Sub CommandButton1_Click()
Static i As Integer
i = i + 1
ReDim Preserve Sales(i)
Sales(i) = InputBox("Sales Figures?")
End Sub

I created using the Control Box a
Command Button with (name) CommandButton1

After I click and enter 123

When I go to the Immediate window and
Enter ? Sales(i) << and return

I get "Compile error"
"Sub or Function not defined"

What's wrong??
TIA,
Jim



Tom Ogilvy

Example form Book
 
in a general module put in the declaration

Public Sales() as String

remove the
Dim Sales() as String
from the sheet module.

You could make a variable public in the sheet module, but it won't allow you
to do that with an array.

Otherwise, you would need to create a "property get" to return values from
the array. If that is what the book is heading for, then you wouldn't want
to move the array to a general module.

--
Regards,
Tom Ogilvy




--
Regards,
Tom Ogilvy



"Jim May" wrote:

This code is right-out-of-the-book:

(In sheet1 Object module)
Option Explicit
Option Base 1
Dim Sales() As String
Sub CommandButton1_Click()
Static i As Integer
i = i + 1
ReDim Preserve Sales(i)
Sales(i) = InputBox("Sales Figures?")
End Sub

I created using the Control Box a
Command Button with (name) CommandButton1

After I click and enter 123

When I go to the Immediate window and
Enter ? Sales(i) << and return

I get "Compile error"
"Sub or Function not defined"

What's wrong??
TIA,
Jim





All times are GMT +1. The time now is 03:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com