Level-up your programming by having a genius refactor your code!

Level-Up

While I’m making progress using objects in my code, I knew there was a more efficient way to write this but couldn’t put my finger on it. I asked Maestrith to take my code and “Maestrithize it”. (It’s humbling to watch someone do this. I feel like I had NASA do my science project) lol   You can help Maestrith out here.

Remember, we are all at different stages of our skills & abilities.  There’s nothing wrong to admit that someone is superior to you at something.  Just keep plugging-along and improve!

Level-up your programming by having a genius refactor your code!

Here’s the finished code from Level-up your programming by having a genius refactor your code!


#Include  
;**************************************
#SingleInstance,Force
SetBatchLines,-1 ;Set run w/o any sleeping between things
#MaxMem,4095 ;Increase the variable allowance to max just in case a massive file
;***********Get row count of file and display headers*******************
Path:= Explorer_GetSelected() ;Explorer Function that gets paths of selected files
If (Path="ERROR") ;Didn't get file, just stop moving forward
return
;~ Folder to use for examples "\Desktop\Header example file\"
SplitPath,Path,File_Name ;grab the file name w/o the path
Loop, read, % Path
last_line++ ;increment lines

rows:=RegExReplace(last_line,"(?:^[^1-9.]*[1-9]\d{0,2}|(?<=.)\G\d{3})(?=(?:\d{3})+(?:\D|$))", "$0,") ;Add commas to the number
MsgBox,4,, % rows " lines found in: " File_Name "`n`nDisplay headers?" ;Display rows and ask if want to see headers
IfMsgBox Yes
{
FileReadLine,Header, % Path, 1 ;read first row
;~ you have to wrap in () any Key in a Key/Value pair if it is a variable.
;~ other than that it's just creating a Key/Value pair on the Count and {Name:"Comma",Character:","}
Obj:={(StrSplit(Header,",").count() -1):{Name:"Comma",Character:","},(StrSplit(Header,"|").count() -1):{Name:"Pipe",Character:"|"},(StrSplit(Header,"`t").count() -1):{Name:"Tab",Character:"`t"}}
Item:=Obj[Obj.MaxIndex()]
MsgBox,,% "The delimmiters are probaly a " Item.Name ,% StrReplace(Header,Item.Character,"`n" Item["Character"])
return
}

Comments are closed.