Sep-28-2018, 03:12 PM
I will try to put this as explanatory as possible since more questions or replies may/could come from this question, but I have about 400 lines of codes, 13 functions, and about 12 global variables. As I am coming to a close with all the functions working with each other, I notice that when the code finishes without errors, some of my global variables are not being reset. They are retaining their values until a certain period and then finally gives the variable a new value. I will post as much code as I can without giving sensitive data. How would you properly declare a global variable with use for multiple functions as well as re-assigning the variables when needed?
CustomerName = ""
Currently I have been assinging my global variables within the function that they are first called/created from. What is highlighted red is setup because it seems I have to declare some value before using the global variable. In other words, it seems to never let me just declare a global variable-I have to set the value as well. I have no global variables assigned or created outside any functions. Again I have 13 total functions with at least 8 functions having at least one global variable. I feel I am going about this the wrong way. Any suggestions? Thanks.
Note: If possible, I would love to post the entire script with sensitive data removed because I would love to hear everyones opinion on the code. So if this is something that becomes requested frequently, I will do my best to post the entire code.
def FindCustName(CustomerSaleID): global CustomerName global Vin global Fnum CustomerName = "" Vin = str(CustomerIndex[int(float(LoadedSales['CC'][InxLoc]))][2])[-8:] FNum= str(CustomerIndex[CustomerSaleID][3]) if ItemTag == "Lube" or str(CurHA).find("EntPrise") > 0: CustomerName = str(CustomerIndex[CustomerSaleID][3]) return CustomerName else: CustomerName = str(CustomerIndex[CustomerSaleID][0]) return CustomerNameglobal CustomerName
CustomerName = ""
Currently I have been assinging my global variables within the function that they are first called/created from. What is highlighted red is setup because it seems I have to declare some value before using the global variable. In other words, it seems to never let me just declare a global variable-I have to set the value as well. I have no global variables assigned or created outside any functions. Again I have 13 total functions with at least 8 functions having at least one global variable. I feel I am going about this the wrong way. Any suggestions? Thanks.
Note: If possible, I would love to post the entire script with sensitive data removed because I would love to hear everyones opinion on the code. So if this is something that becomes requested frequently, I will do my best to post the entire code.