how to make a result available to all procedures

tony.reynolds

Board Regular
Joined
Jul 8, 2010
Messages
97
I refer to post http://www.mrexcel.com/forum/showthread.php?t=550350 where I then wrote this simple code the produce the machine serialnumber

Code:
 Const sKey As String = "SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName"
  
  MsgBox QueryValue(sKey, HKEY_LOCAL_MACHINE, "ComputerName")

I would like the function to refer to to the serial number to return the name of the licenced user or if the serial number is not in the list of users it returns "Not Licensed"

So

Code:
Function MachineReigistration()
 
LicencedTo = "Not Licensed"
If SerialNumber = "MCA074075" Then LicensedTo = "Tony"
If SerialNumber = "MCA069595" Then LicensedTo = "Ellen"
If SerialNumber = "MCA073878" Then LicensedTo = "Estelle"
If SerialNumber = "MCA026058" Then LicensedTo = "Leonie"
If SerialNumber = "MCA026062" Then LicensedTo = "Doug"
 
End Function

So in any code within the Project we can check..

Code:
Sub TestMachineRegistration()
 
If LicensedTo = "Not Licensed" then Exit Sub
 
'Procedure here if all ok
 
MsgBox LicensedTo
 
End Sub

Can someone help me do this
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Code:
Public LicencedTo = "Not Licensed"

Function MachineReigistration()
    Select Case SerialNumber
        Case "MCA074075": LicensedTo = "Tony"
        Case "MCA069595": LicensedTo = "Ellen"
        Case "MCA073878": LicensedTo = "Estelle"
        Case "MCA026058": LicensedTo = "Leonie"
        Case "MCA026062": LicensedTo = "Doug"
    End Select
End Function
 
Last edited:
Upvote 0
Code:
Public LicencedTo = "Not Licensed"
 
Function MachineReigistration()
    Select Case SerialNumber
        Case "MCA074075": LicensedTo = "Tony"
        Case "MCA069595": LicensedTo = "Ellen"
        Case "MCA073878": LicensedTo = "Estelle"
        Case "MCA026058": LicensedTo = "Leonie"
        Case "MCA026062": LicensedTo = "Doug"
    End Select
End Function

Sorry you've lost me

Can you show me how to call that function in a procedure?

Sub Test()

msgbox LicensedTo

End Sub
 
Upvote 0
Code:
Public LicensedTo As String

Sub TestMachineRegistration()
 
    LicensedTo = GetMachineReigistration
    
    If LicensedTo = vbNullString Then Exit Sub
     
    'Procedure here if all ok
    MsgBox LicensedTo
 
End Sub

Function GetMachineReigistration() As String
    
    ' Your code...
    
    Select Case SerialNumber
        Case "MCA074075": MachineReigistration = "Tony"
        Case "MCA069595": MachineReigistration = "Ellen"
        Case "MCA073878": MachineReigistration = "Estelle"
        Case "MCA026058": MachineReigistration = "Leonie"
        Case "MCA026062": MachineReigistration = "Doug"
    End Select

End Function
 
Upvote 0
Oops, didn't make one change:
Code:
Function GetMachineReigistration() As String
    
    ' Your code...
    
    Select Case SerialNumber
        Case "MCA074075": [B]GetMachineReigistration[/B] = "Tony"
        Case "MCA069595": [B]GetMachineReigistration[/B] = "Ellen"
        Case "MCA073878": [B]GetMachineReigistration[/B] = "Estelle"
        Case "MCA026058": [B]GetMachineReigistration[/B] = "Leonie"
        Case "MCA026062": [B]GetMachineReigistration[/B] = "Doug"
    End Select

End Function
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,808
Members
452,944
Latest member
2558216095

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