When developing software with VB, you often need to share data between different forms, but it is not convenient for software debugging and modification when excessive use global variables. There are usually two solutions.
The first method: Define global variables, then use directly in various forms, such as Public StringPublic strcustomername as string
Second method: Add a module to define variables, then define some public processes or functions to set up and get this data, such as DIM STRCUSTOMERID AS STRINGDIM STRCUSTOMERNAME AS STRING
Public Sub SetCustomerid (Customerid As String) STRCUSTOMERID = Customeridend Sub
Public function getcustomerid () AS string getcustomerid = strcustomeridend function
Public SUB SetCustomername (Customername As String) STRCUSTOMERNAME = CustomernameEnd Sub
Public function getcustomername () as string getcustomername = strcustomernameend function
In fact, these two methods have a shortcoming. When using the first method, when the global variable is too frequent in the process or function, it will bring a lot of workload to the debug and modification, and sometimes catastrophic consequences. When using the second method, if there are many shared data, there is a need to define a lot of set * and get * functions. The younger brother's experience is limited, I hope that you have a lot of prawn, and you will welcome it to Email: Xbxue@163.com.