Jump to content

ALFJ

Active Members
  • Posts

    21
  • Joined

  • Last visited

About ALFJ

  • Birthday 03/14/1973

Profile Information

  • Location
    NJ
  • Interests
    Computers, computer games, anything computers really!

ALFJ's Achievements

Seeker

Seeker (1/7)

0

Reputation

  1. Pretty good one, use it all the time for Random session generation Changed it a lil so you can choose the # of random characters to generate and return 10random characters if the $MaxChar is left blank when called. Func _RandSession($MaxChar=10) Local $Alph = StringSplit ('ABCDEFabcdef123456789', ''); Use these characters in the returned random string ($Str). Local $Str = '', $Last = '' For $A = 1 To $MaxChar; Start a for loop from 1 to $MaxChar Do $Ran = Random (1, $Alph[0], 1); Produce a random number within range of the $Alph array. Sleep (15); Sleep 15 milli-seconds to insure 0% CPU usage. Until $Ran <> $Last; Make sure the same number is not used twice. $Last = $Ran; Set the current random number to $Last so it is not used twice. Sleep (15); Sleep 15 milli-seconds to insure 0% CPU usage. $Str = $Str & $Alph[$Ran]; Update $Str with the newest random character. Next Return $Str EndFunc Example: ConsoleWrite('Random Session using 4 = ' & _RandSession(4) & @CRLF);Returns 4 random characters ConsoleWrite('Random Session using no input = ' & _RandSession() & @CRLF) ;Returns 10 Random Characters
  2. Ahh my keyboard is missing it LoL
  3. Well you could incorporate a wait delay on this as well, for my needs setting a pre-determined time I was willing to wait regardless of what I got worked better than waiting for the page to load and if it failed loading after a certain amount of time then either retry or skip it. Example $oIE.Navigate("http://www.yahoo.com","","","","") Local $TimeToWait = 0 While $oIE.ReadyState <> 4 Sleep(50) If $TimeToWait > 10000 Then Consolewrite("Failed to load the page in the Max allowed time to wait") Exitloop Else $TimeToWait = $TimeToWait + 50 EndIf WEnd You can also use Dale's Pre-made IE functions Included in the IE.au3, they also work with the $oIE shell object created, how ever I have not tested all of them, so if you do use one and it fails well someone in forum can probably tell you why. Dale has put more into the error handling, he has many nice functions, just remember to include the IE.au3 if you use any of the functions in there thought Example: $oIE.Navigate("http://www.yahoo.com","","","","") _IELoadWait($oIE) For what I use it for though using page wait delays instead of waiting for the page to load works better since some pages I don't care if it finishes loading, while others it's essential that it fully loads. It all depends on your needs. BTW codes up there have not been tested by me and might not be perfect but it gives you the idea if I missed something in them Good luck and Happy New Year!!
  4. This is exactly what I was looking for UEZ!!! I can avoid the arrays now that I can use this example to lets say pull out 1, 2 or more values. I was actually messing with something similar earlier but the $1, part was what was confusing me and not knowing much about the advanced characters I wasn't sure where my mistakes were, but with this example you provided, I just added an extra ,(.*) $1, $2, $3, $4 for the return and to extract 4 instead of 3. This example makes more sense to me now, since I was actually trying it with something similar to this earlier but being a newbie in the area I wasn't sure if I was even doing it right So I had given up on trying to figure it out for the day and just did it the way I know how to and not the way I wanted to learn how to. But thanks to that example, It gave me more hope, and the extra @LF you added on there also helps me understand doing it for multiple rows. $string = "Text1, Text2, Text3, Text4, Text5" $string = StringReplace($string, " ", "") $test = StringRegExpReplace($string, "(?i:(.*),(.*),(.*),(.*),(.*))", "$1");Text1 $test = StringRegExpReplace($string, "(?i:(.*),(.*),(.*),(.*),(.*))", "$2");Text2 $test = StringRegExpReplace($string, "(?i:(.*),(.*),(.*),(.*),(.*))", "$3");Text3 $test = StringRegExpReplace($string, "(?i:(.*),(.*),(.*),(.*),(.*))", "$4");Text4 $test = StringRegExpReplace($string, "(?i:(.*),(.*),(.*),(.*),(.*))", "$5");Text5 or using your method which is much cleaner especially if the line lets say has a lot of items in it: $string = "Text1, Text2, Text3, Text4, Text5" $string = StringReplace($string, ", ", ",") ;Remove any spaces after a comma $test = StringRegExpReplace($string, "(?U:(.*)),.*", "$1");Text1 $test = StringRegExpReplace($string, "(?U:(.*),(.*)),.*", "$2");Text2 $test = StringRegExpReplace($string, "(?U:(.*),(.*),(.*)),.*", "$3");Text3 $test = StringRegExpReplace($string, "(?U:(.*),(.*),(.*),(.*)),.*", "$4") ;Text4 $test = StringRegExpReplace($string, "(?U:(.*),(.*),(.*),(.*),(.*))", "$5") ;Text5 Yep I can get with this the Text I want without using an array!! Thanks and Happy New Year to you as well!
  5. #include <IE.au3> ;-------- Main AUTOIT Declarations for this script -------------------- Opt("MustDeclareVars", 1) ;0=Not Required 1=Must declare ; ------- Broswer creation varibles for simplicity only---------------- Local $oIE, $GUIActiveX Local $gTitle = "My Browser" Local $gWidth = (@DesktopWidth-6); Local $gHeight = (@DesktopHeight-39);@DesktopHeight-39) ;for normal Local $SHTML GUICreate($gTitle,$gWidth,$gHeight,0,0, _ ; Create the GUI that will hold the embedded IE Explorer shell 0x04000000 + 0x02000000 + 0x10000000); _IE_AllowActiveX(True) ; Optional values, note this will also effect your IE in your pc even though it's using the explorer shell _IE_DisplayImages(True) _IE_DisplayVideos(True) _IE_PlayBackgroundSounds(True) _IE_PlayAnimations(True) _IEErrorHandlerRegister() _IEErrorNotify(True) _CreateShellIE() ;not the same IE included in Autoit, This uses the Explorer shell ;So it works even if I have IE9 or Windows 7 installed on my pc $oIE.Navigate("www.microsoft.com","","","","") ;navigate to this page Sleep(10000) ;Must use a delay to wait for IE to get the website otherwise the code crashes Local $sHTML $sHTML = _IEDocReadHTML ($oIE) MsgBox(0, "Document Source", $sHTML) ;ConsoleWrite($s_html & @LF) ;$oIE.document.Write($s_html) ;$oIE.refresh Func _CreateShellIE() $oIE = 0 $GUIActiveX = 0 While isObj($oIE) = 0 If IsObj($oIE) = 0 Then $oIE = ObjCreate("Shell.Explorer.2") ;works with Windows 7, XP regardless of what IE version you have ;If IsObj($oIE) = 0 Then $oIE = ObjCreate("InternetExplorer.Application");Fails on some websites depending on the version of IE you have Sleep(500) WEnd If Not IsObj($oIE) = 0 Then GuiCtrlCreateObj($oIE, (0 -1),(0 -1),($gWidth - 3),($gHeight - 8)) sleep(500) With $oIE ;Optional values will not effect your IE, will only effect this session .Silent = True ;Dialog boxes are not displayed .StatusBar = True ;Hidden Status bar .ToolBar = True ;Hidden Toolbar .MenuBar = True ;Hidden .AddressBar = True ; Hidden EndWith EndFunc ;==> _CreateIE ; ----------------------------------------------------------------------------------------------- Func _IE_DisplayImages($ivState); Applies to Current User Local $svKeyPath = "HKCU\SOFTWARE\Microsoft\Internet Explorer\Main" If $ivState Then RegWrite($svKeyPath, "Display Inline Images", "REG_SZ", "yes") Else RegWrite($svKeyPath, "Display Inline Images", "REG_SZ", "no") EndIf EndFunc;==>_IE_DisplayImages ; ----------------------------------------------------------------------------------------------- Func _IE_DisplayVideos($ivState) ; Applies to Current User Local $svKeyPath = "HKCU\SOFTWARE\Microsoft\Internet Explorer\Main" If $ivState Then RegWrite($svKeyPath, "Display Inline Videos", "REG_SZ", "yes") Else RegWrite($svKeyPath, "Display Inline Videos", "REG_SZ", "no") EndIf EndFunc ;==>_IE_DisplayVideos ; ----------------------------------------------------------------------------------------------- Func _IE_PlayBackgroundSounds($ivState) ; Applies to Current User Local $svKeyPath = "HKCU\SOFTWARE\Microsoft\Internet Explorer\Main" If $ivState Then RegWrite($svKeyPath, "Play_Background_Sounds", "REG_SZ", "yes") Else RegWrite($svKeyPath, "Play_Background_Sounds", "REG_SZ", "no") EndIf EndFunc ;==>_IE_PlayBackgroundSounds ; ----------------------------------------------------------------------------------------------- Func _IE_PlayAnimations($ivState) ; Applies to Current User Local $svKeyPath = "HKCU\SOFTWARE\Microsoft\Internet Explorer\Main" If $ivState Then RegWrite($svKeyPath, "Play_Animations", "REG_SZ", "yes") Else RegWrite($svKeyPath, "Play_Animations", "REG_SZ", "no") EndIf EndFunc ;==> _IE_PlayAnimations ; ----------------------------------------------------------------------------------------------- Func _IE_AllowActiveX($ivState) ; only applies to Internet Zone in Windows Local $svKeyPath = "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3" If $ivState Then RegWrite($svKeyPath, "1200", "REG_DWORD", 0) Else RegWrite($svKeyPath, "1200", "REG_DWORD", 3) EndIf EndFunc ;==> _IE_AllowActiveX Try using the Embedded Explorer shell (example provided) this is non-dependent on which version of IE you have, It worked with Windows XP, Windows 7, regardless of which IE I have. Many other options provided.. such as hiding images, disabling AciveX, disabling the address bar etc.. so the page loads faster, be warned that you need to set a Sleep of at least (5000) after every navigate, since you need the page to load before you retrieve anything from the document if the delay is too low it will fail.
  6. I tried the above and didn't get the result unless I did something wrong but then again it wasn't tested. Jury's examples did work although since he used the \d{5} in the first part if it didn't have a # there it gave me an error but I am sure that can easily be replaced with something like \w* or [a-z]{5}. Thanks for all the feedback and help. I am still not great at those 2 functions due to the "patterns" which are new to me, I have to learn those like I know the loops and arrays, I ended up just using extraction with what I know just cause I want to finish what I am currently working on faster and just finish LoL, I will spend more time learning that later, but examples do help learn a little more. Anyway here's what I did with an array, since I realized it was actually a better way to go since I could probably pull any text from any one of those places without breaking my head trying to figure out how with the patterns lol, I didn't remove the console writes so the code looks longer than it should and no error implementation. $string = "Text1, Text2, Text3, Text4, Text5" $string = StringReplace($string," ","",0,0);Trim any spaces ConsoleWrite($string & @LF);Text1,Text2,Text3,Text4,Text5 $aString = Stringsplit($string, ",",0);Split the values into an array ConsoleWrite($aString[0] & @LF) ;5 (Count of the values in the array) ConsoleWrite($aString[1] & @LF) ;Text1 ConsoleWrite($aString[2] & @LF) ;Text2 ConsoleWrite($aString[3] & @LF) ;Text3 ConsoleWrite($aString[4] & @LF) ;Text4 ConsoleWrite($aString[5] & @LF) ;Text5 $newString = $aString[1] & ", " & $aString[2] & ", " & $aString[3] ;Text1, Text2, Text3 ConsoleWrite($newString & @LF)
  7. Yeah Your above example also works even though it returns the values in the 0 & 1 part of the array. What I like though is those expressions that are 1 line coded such as the example below (which btw doesn't work for the code I was trying to use). Example: $Result = StringRegExpReplace($input, $regex, "$1") However for me to use that I have to learn how to search and how to go about replacing what I had before with my results.
  8. I think it could be a size or type of text in the file issue, If it's due to the size then I guess you might have to use some sort of buffering to do parts at a time, which I don't know how to go about doing myself but someone else might know here and know if that's the case.. The way I see it.. is watching a HD movie from a website, they send information in buffer style, same thing when you are watching a movie locally, let's pretend it's a 100GB size movie.. of course if you open the whole movie with the movie app your PC will most likely crash, so I assume some sort of buffering is used with the movie viewers as well.. however you are trying to open a huge file with no buffer so it's failing, my opinion on it anyway.. whether it's right or not.. I am sure someone with more knowledge than me or someone with a similar issue might give us more pointers on this.
  9. Great another great example, and thanks for the explanation file, I will have to take a closer look. ConsoleWrite("Results " & $result[0] & @LF) Question will the $result[0] always return the whole result string in the array? I know it does in this example, just wondering since I didn't read anything as such on the samples in Autoit, it only shows for loops combined with an array to get the result which could add more to the overall code lines. If $result at [0] assuming there is a match always returns the whole line, then this might work great for future things for me, just need to get a little more involved with the Expressions part to learn them.
  10. All values are in the same line, I see someone else did an example already, going to try that one.
  11. This works great, thanks! Maybe someone will stop by and show us the StringRegExpReplace way just to see how it's done. Even this is a bit complicated how you combine StringMid with StringInstr I can see how the StringInStr works but the StringMid I have never used cause I guess I have always thought of it being for taking from the Middle not the Right or the Left but guess I was wrong lol, guess I have to start thinking about using multiple string functions together to get what I am looking for, I guess that's been my problem I was just thinking one string function at a time.
  12. Hi everyone, I am still a newbie in the expressions area so I am looking for some help I am trying to trim a string using StringRegExpReplace but not sure how to go about it, I have seen StringTrimRight ( "string", count ) however the text I am extraction is not always going to have the same amount of text towards the right so this wont work. I have been Experimenting with StringRegExpReplace with all the various things however I have a lot to learn. $string = "text1,Text2,Text3,Text4,Text5" I want to extract "just Text1, Text2, Text3" from the string The text is coming from a file which separates values with the comma "," The file has multiple lines so I will just need to take the first 3 values of each line and move on to the next line. Text1 Will always be 5 digits followed by a comma , Text2 always varies in lenght but is always followed by a comma , Text3 Will always be 2 Characters followed by a comma , Text4 always varies in lenght but is always followed by a comma , Text5 always varies in lenght and is always at the end. So the $result would be something like $result = "Text1, Text2, Text3" I am trying to avoid arrays I can probably get it to work with an array however the file is big so I am trying to avoid an array . would just like to know how to get it from one line, don't have to go overboard in your code
  13. I use the console for my results (not into Message boxes ), don't know about the size issue you're having, would have to run a test on a huge file to see if I get the same problem and experiment with it. My Zip code file, took a while parsing it and writing it to my needs, if I had to do it manually could have taken way longer hope I never run into a file that is that big.
  14. I used the other functions to count the lines on my standard ZIP codes file I did not do any timed test I just checked the console for the time it took and here's what I get still. Not watching a movie or anything and I did run the test more than once per function just to be fair (3)times. Here's what I got from it: Total Lines : 34417 $FLN = "Zip-Codes.txt" $FLNcount = _File_CountLines($FLN) Time: 0.553, Time: 0.542, Time: 0.548 $FLNcount = _FileCountLines($FLN) Time: 0.331, Time: 0.336, Time: 0.324 $FLNcount = _File_CountLines2($FLN, 1) Time: 0.546, Time: 0.542, Time: 0.550 (about the same results if you use 0 instead of 1 as an option) Then again I have no empty lines so it wouldn't matter much. Here's a sample of what's in each line: 01001,AGAWAM,MA,HAMPDEN,STANDARD Not sure if what's in it effects the results even though there is not much of a difference I know which function I am still sticking to I also like the FileReadLine it's great I don't even have to open a file to read the text. I can just write something like $FileLine = FileReadLine($FLN, $LNum) and it gives me the text that is on the line # referred to by $LNum in the $FLN file name.
  15. Great code here, I know the post is old but it's still a great function Getting the line count for me on a list of 151671 names was almost 2 seconds(without this function), but with this Function it's less than a second only 0.334 I always like to tweak my codes as much as possible, I don't like the lazy coders out there who produce programs that eat CPU & Memory! If a program does the same thing but eats less resources or takes for ever to start, guess which one I will pick
×
×
  • Create New...