William Hunter Active Member Licensed User Longtime User Sep 13, 2013 #1 I have a declared variable in a SERVICE module. I wish to use AHPreferenceActivity in the Main module to input the value of that variable, then in SubInitializeConnectVariables pass it to the SERVICE module for use there. What is the proper syntax to do this? Any help greatly appreciated.
I have a declared variable in a SERVICE module. I wish to use AHPreferenceActivity in the Main module to input the value of that variable, then in SubInitializeConnectVariables pass it to the SERVICE module for use there. What is the proper syntax to do this? Any help greatly appreciated.
NJDude Expert Licensed User Longtime User Sep 13, 2013 #2 You have to declare those variables in Process_Globals, then, from the service you can get the name and value like this: Code: Copy LocalVariable = Main.Myvariable Upvote 0
You have to declare those variables in Process_Globals, then, from the service you can get the name and value like this: Code: Copy LocalVariable = Main.Myvariable
William Hunter Active Member Licensed User Longtime User Sep 13, 2013 #3 NJDude said: You have to declare those variables in Process_Globals, then, from the service you can get the name and value like this: Code: Copy LocalVariable = Main.Myvariable Click to expand... Thank you for your response NJDude. I think I didn’t express my query as well as I should have. I have declared the variable in the service as below: Code: Copy Sub Process_Globals Public port As Int End Sub In the Main module I am using AHPreferenceActivity as a means of inputting the variable to the application. The code I am using is below: Code: Copy Sub InitializeConnectVariables ServerService.port = manager.GetString("edit1") End Sub I had thought this would pass the value from the Main module to the variable in the Service module. But, it doesn’t do this. I’m at a loss to understand how to do this. If you have any thoughts please pass them along. Best regards Upvote 0
NJDude said: You have to declare those variables in Process_Globals, then, from the service you can get the name and value like this: Code: Copy LocalVariable = Main.Myvariable Click to expand... Thank you for your response NJDude. I think I didn’t express my query as well as I should have. I have declared the variable in the service as below: Code: Copy Sub Process_Globals Public port As Int End Sub In the Main module I am using AHPreferenceActivity as a means of inputting the variable to the application. The code I am using is below: Code: Copy Sub InitializeConnectVariables ServerService.port = manager.GetString("edit1") End Sub I had thought this would pass the value from the Main module to the variable in the Service module. But, it doesn’t do this. I’m at a loss to understand how to do this. If you have any thoughts please pass them along. Best regards
Erel B4X founder Staff member Licensed User Longtime User Sep 13, 2013 #4 The above code is correct. It will set the value of 'port' variable in the service to the value of manager.GetString(...). Upvote 0
The above code is correct. It will set the value of 'port' variable in the service to the value of manager.GetString(...).
William Hunter Active Member Licensed User Longtime User Sep 13, 2013 #5 Erel said: The above code is correct. It will set the value of 'port' variable in the service to the value of manager.GetString(...). Click to expand... Thank you Erel. I was sure my code was correct. But, I was getting some strange behavior. The code below does pass the variable to the Service: Code: Copy Sub InitializeConnectVariables ServerService.port = manager.GetString("edit1") Log("Port used Main: " & ServerService.port) 'variable correctly fetched StartDialog = manager.GetBoolean("check1") End Sub What led me astray was that after initializing the connect variable, ServerService.port was no longer accessible for use in the Main module. The code below, in Sub Activity Create, did not display the port no, only a 0. I took this to mean that the variable was not passed to ServerService.port in Sub InitializeConnectVariables. Not so. Code: Copy lblIP.Text = "Device address: " & ssocket.GetMyWifiIP & ":" & ServerService.port msgBoxURL = ssocket.GetMyWifiIP & ":" & ServerService.port I am using your HttpServerExample. The only changes I have made are purely cosmetic. I ran into this problem when trying to use AHPreferenceActivity to input various settings. I have tried many ways to work around this, but to no avail. The strange thing about this is, if I manually give ServerService.port a value, in the service module, as in the code below, all is well. Code: Copy Public port As Int = 5555 Do you have any thoughts? Regards Upvote 0
Erel said: The above code is correct. It will set the value of 'port' variable in the service to the value of manager.GetString(...). Click to expand... Thank you Erel. I was sure my code was correct. But, I was getting some strange behavior. The code below does pass the variable to the Service: Code: Copy Sub InitializeConnectVariables ServerService.port = manager.GetString("edit1") Log("Port used Main: " & ServerService.port) 'variable correctly fetched StartDialog = manager.GetBoolean("check1") End Sub What led me astray was that after initializing the connect variable, ServerService.port was no longer accessible for use in the Main module. The code below, in Sub Activity Create, did not display the port no, only a 0. I took this to mean that the variable was not passed to ServerService.port in Sub InitializeConnectVariables. Not so. Code: Copy lblIP.Text = "Device address: " & ssocket.GetMyWifiIP & ":" & ServerService.port msgBoxURL = ssocket.GetMyWifiIP & ":" & ServerService.port I am using your HttpServerExample. The only changes I have made are purely cosmetic. I ran into this problem when trying to use AHPreferenceActivity to input various settings. I have tried many ways to work around this, but to no avail. The strange thing about this is, if I manually give ServerService.port a value, in the service module, as in the code below, all is well. Code: Copy Public port As Int = 5555 Do you have any thoughts? Regards
Erel B4X founder Staff member Licensed User Longtime User Sep 15, 2013 #6 ServerService.port will return the current value of the global variable port. If you are getting an unexpected value then it means that the value is changed somewhere in the program. Upvote 0
ServerService.port will return the current value of the global variable port. If you are getting an unexpected value then it means that the value is changed somewhere in the program.