Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Raynard Fischer   on Nov 20 In MS Office Category.

  
Question Answered By: Opal Alexander   on Nov 20

I seem to be in the minority here, but I really don't like this
solution. Pass the variable  to the sub. Then, any form or module
can use the sub not just this one form and this one variable. There
is also no problem with changing the name of x and missing the
reference to it in the module. The sub code  is more robust and the
code is more maintainable.



:: This code is in Forms -> UserForm1:
:: '------------------------------
:: Option Explicit
:: Public x As Integer
::
:: Private Sub OK_Button_Click()
:: If Yes_Button Then x = 1
:: If No_Button Then x = 2
:: MsgBox (x)
:: Call Var_Test

Call Var_Test(x)


:: End Sub
::
:: Private Sub Cancel_Button_Click()
:: Unload UserForm1
:: End Sub
:: '------------------------------
::
:: And this code is in Module1:
:: '------------------------------
:: Option Explicit
:: Public x As Integer

Delete the line  above.


:: Sub Var_Test()

Sub Var_Test(x as Integer)

:: MsgBox (x)
:: Unload UserForm1
:: End Sub

Share: 

 

This Question has 7 more answer(s). View Complete Question Thread

 


Tagged: