GlobalVariables for my webform app

Home / Uncategorized / GlobalVariables for my webform app

Question:
I have a problem with creating GlobalVariables for my webform app. I am creating a webform app with Visual Studio 2015, VB.net, ASP.net I followed the instruction that I found on this and other sites but with no successs. I did the folowwing:
1 Create the module file: Module1.vb With this scripts:
Public Module GlobalVariables2 Public ModuleEMAIL As String = "ModuleEMAIL@zzzzzzzz" End Module

Public Class GlobalVariables Public Shared Property clasEMAIL As String = "clasEMAIL@zzzzzzzz" End Class
But when ever I try to call the variables a compiler error occur.

Function fnBtnText() Button1.Text = GlobalVariables.clasEMAIL ‘ generate: Compiler Error Message: BC30451: ‘GlobalVariables’ is not declared. It may be inaccessible due to its protection level.
Button2.Text = ModuleEMAIL

‘generate: Compiler Error Message: BC30451: ‘ModuleEMAIL’ is not declared. It may be inaccessible due to its protection level. End Function

What meas “protection level” in this case? When the scripts are moved tot another spacename area the same happens. What am I doing wrong? Did I missed something? I hope someone van help me out. Many greatigs, Ton Daamen


Answer:
Not sure what the problem with your solution is, but your code worked for me when I created a new solution.

Try this:-

GlobalForm.aspx
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="GlobalForm.aspx.vb" Inherits="WebApplication3.GlobalForm" %>







Code Behind
Public Class GlobalForm
Inherits System.Web.UI.Page

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Button1.Text = GlobalVariables.clasEMAIL
End Sub

Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Button2.Text = ModuleEMAIL
End Sub

End Class

GlobalVariables Class
Public Class GlobalVariables
Public Shared Property clasEMAIL As String = "clasEMAIL@zzzzzzzz"
End Class

GlobalVariables2 Module
Module GlobalVariables2
Public ModuleEMAIL As String = "ModuleEMAIL@zzzzzzzz"
End Module
Read more

Leave a Reply

Your email address will not be published. Required fields are marked *