Babu16 Posted February 1, 2018 Posted February 1, 2018 Hi all, I have written the following Random function to generate 8 character string, but the challenge is that in first iteration, this is generating as expected (8 character random string), from 2 iteration on wards, it's keep adding the previous strings, for example, first iteration (8 characters), 2nd iteration (16 characters) and keep on adding 8 until all iterations are complete. But my expectation is to generate 8 characters random string on each iteration, Can you please help me on this? For $k = 1 To 5 RandomName() Next Func RandomName() Global $FirstName Global $LastName Global $aSpace[3] Global $digits = 8 For $i = 1 To $digits $aSpace[0] = Chr(Random(65, 90, 1)) ;A-Z $FirstName &= $aSpace[Random(1)] Next MsgBox(0, "String Generator", "String Generated: Fname: " & $FirstName) For $j= 1 to $digits $aSpace[0] = Chr(Random(65, 90, 1)) ;A-Z $LastName &= $aSpace[Random(1)] Next MsgBox(0, "String Generator", "String Generated:LName: " & $LastName) EndFunc
Developers Jos Posted February 1, 2018 Developers Posted February 1, 2018 You are defining the variables at the top of the Func as Global without initializing them, so they will survive the Func and not be reinitialized with the second call of the Func. Make them local or initialize them like: Global $FirstName = "" Local is normally preferred. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
jdelaney Posted February 1, 2018 Posted February 1, 2018 (edited) Redefine the variables to empty in the loop. Edit: too slow Edited February 1, 2018 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Babu16 Posted February 1, 2018 Author Posted February 1, 2018 Thank you, the problem has resolved by changing to Local
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now