Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default Public variable problem

I have nine module 1 to module 9. Each module handle one location of
Voucher.
How to define following two public variable ? Need to define in each
module ?

Public gerr_Cnt As Long
Public gShErr As Worksheet


Module 1
Option Explicit
'~~ 2006/11/24
Public gcJap As New clsConfigJap
Public gerr_Cnt As Long
Public gShErr As Worksheet

Sub Voucher_JAP_Step_1()
.....
end

Module 2
Option Explicit

Public gcSin As New clsConfigSin
Public gerr_Cnt As Long
Public gShErr As Worksheet

Sub Voucher_SIN_Step_1()
.....
end

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Public variable problem

What you are trying will error, with "ambiguous name".
Public variables in modules are global to the project, so you cannot
duplicate names.
If they are different variables, give them different name.
Otherwise just declare in one module as public and they will be available to
all modules.

Depending on your structure, could you expose them through the class for
each location ?

NickHK
As a side-line, depending on the similarity of your different location
classes, would using an Interface/Implements be better ?
Then you may only need a single module, because you can :

'Declare the object as the Interface
Dim MyLocation As ILocation

'Set the object to the required class, as each Implements ILocation
Private Sub CommandButton1_Click()

Select Case UCase(InputBox("First letter of the location."))
Case "J"
Set MyLocation = New CJapan
Case "S"
Set MyLocation = New CSingapore
Case Else
Set MyLocation = Nothing
MsgBox "Invalid"
End Select

If Not MyLocation Is Nothing Then MyLocation.Step1

End Sub

"moonhk" wrote in message
ups.com...
I have nine module 1 to module 9. Each module handle one location of
Voucher.
How to define following two public variable ? Need to define in each
module ?

Public gerr_Cnt As Long
Public gShErr As Worksheet


Module 1
Option Explicit
'~~ 2006/11/24
Public gcJap As New clsConfigJap
Public gerr_Cnt As Long
Public gShErr As Worksheet

Sub Voucher_JAP_Step_1()
....
end

Module 2
Option Explicit

Public gcSin As New clsConfigSin
Public gerr_Cnt As Long
Public gShErr As Worksheet

Sub Voucher_SIN_Step_1()
....
end



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default Public variable problem

The error message is not "ambiguous name". May be Object not set. Now,
my problem seem working ok.

In each module, I have 3 steps
1. Base on raw data file, build Account mapping
2. Build Summary base on raw data file
3. Build Upload text file, upload to ERP system

If run step 1 ,step 2 and then step 3 without error run under same
module(e.g. JAP)
Then ,select other module (eg.Singapore) may have error.

I just want define below two lines as public variable
Public gerr_Cnt As Long
Public gShErr As Worksheet

Also, how to using Interface/Implements in classes module ?

NickHK wrote:
What you are trying will error, with "ambiguous name".
Public variables in modules are global to the project, so you cannot
duplicate names.
If they are different variables, give them different name.
Otherwise just declare in one module as public and they will be available to
all modules.

Depending on your structure, could you expose them through the class for
each location ?

NickHK
As a side-line, depending on the similarity of your different location
classes, would using an Interface/Implements be better ?
Then you may only need a single module, because you can :

'Declare the object as the Interface
Dim MyLocation As ILocation

'Set the object to the required class, as each Implements ILocation
Private Sub CommandButton1_Click()

Select Case UCase(InputBox("First letter of the location."))
Case "J"
Set MyLocation = New CJapan
Case "S"
Set MyLocation = New CSingapore
Case Else
Set MyLocation = Nothing
MsgBox "Invalid"
End Select

If Not MyLocation Is Nothing Then MyLocation.Step1

End Sub

"moonhk" wrote in message
ups.com...
I have nine module 1 to module 9. Each module handle one location of
Voucher.
How to define following two public variable ? Need to define in each
module ?

Public gerr_Cnt As Long
Public gShErr As Worksheet


Module 1
Option Explicit
'~~ 2006/11/24
Public gcJap As New clsConfigJap
Public gerr_Cnt As Long
Public gShErr As Worksheet

Sub Voucher_JAP_Step_1()
....
end

Module 2
Option Explicit

Public gcSin As New clsConfigSin
Public gerr_Cnt As Long
Public gShErr As Worksheet

Sub Voucher_SIN_Step_1()
....
end


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Public variable Jack New Users to Excel 4 March 18th 06 09:35 PM
Reset public variable Alex St-Pierre Excel Programming 5 January 31st 06 03:20 PM
How to declare variable as public. Mark Excel Programming 3 April 7th 05 06:27 PM
Public Variable Jason Excel Programming 4 April 12th 04 07:06 PM
public variable marwan hefnawy Excel Programming 1 September 5th 03 08:54 AM


All times are GMT +1. The time now is 04:40 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"