# Need Advice with Math Logic

## Recommended Posts

Please read my example below and then look at the code. The code will continue processing the For > Next loop and will be parsing/formatting the returned strings until the loop is done. However, I need to properly reconvert a string if it's found outside of the range before continuing with the loop. I'm looking for an easy way to accomplish this task without interfering with the parse/formatting of the for>next loop.

Any suggestions?

```; Example:
; \$aRead[0] = 28 because there are 28 strings returned from _filereadtoarray
;   of those 28 strings, only 5 are returned as working examples
;   the strings are as follows:
; "1 "Test" Example"
; "2 "Test" Example"
; "14 "Test" Example"
; "23 "Test" Example"
; "26 "Test" Example"
; \$aRead[\$i] must be within the range of 1 - 18 so if it's out of that range
;   it needs to be converted to the next available number in the current range
;   so in this example the following should hold true
;   After reading those variables it should convert the strings to something similar:
;   "1 "Test" Example"
;   "2 "Test" Example"
;   "3 "Test" Example"
;   "4 "Test" Example"
;   "5 "Test" Example"oÝ÷ Ù«­¢+ØÀÌØí¥±ôÅÕ½ÐíAÑ ÀäÈí¥±¹áÐÅÕ½Ðì)}¥±IQ½ÉÉä ÀÌØí¥±°ÀÌØíI¤)%%ÍÉÉä ÀÌØíI¤ôÄQ¡¸(\$ÀÌØíÍÕÍÌôÄ(%½ÈÀÌØí¤ôÄÑ¼ÀÌØíIlÁt´Ä(\$\$ÀÌØí½Õ¹ÐôÀ(\$\$ÀÌØíIlÀÌØí¥tôMÑÉ¥¹QÉ¥µ1Ð ÀÌØíIlÀÌØí¥t°Ø¤(\$%%MÑÉ¥¹1Ð ÀÌØíIlÀÌØí¥t°Ø¤±ÐìÐìÄØÜÜÜÈQ¡¸(\$\$\$ì¼¼%¹ÕµÈ¥ÌÄ½ÈÈ¥¥ÑÌ°ÍÑ½ÉÑ¡´¸(\$\$%%MÑÉ¥¹%Í%¹Ð¡MÑÉ¥¹1Ð ÀÌØíIlÀÌØí¥t°È¤¤ôÄQ¡¸(\$\$\$\$ÀÌØíµ9U5   HôMÑÉ¥¹1Ð ÀÌØíIlÀÌØí¥t°È¤(\$\$\$\$ÀÌØí½Õ¹ÐôÈ(\$\$%±Í(\$\$\$\$ÀÌØíµ9U5  HôMÑÉ¥¹1Ð ÀÌØíIlÀÌØí¥t°Ä¤(\$\$\$\$ÀÌØí½Õ¹ÐôÄ(\$\$%¹%(\$%¹%(%9áÐ)¹%```

My Projects: [topic="89413"]GoogleHack Search[/topic], [topic="67095"]Swiss File Knife GUI[/topic], [topic="69072"]Mouse Location Pointer[/topic], [topic="86040"]Standard Deviation Calculator[/topic]

##### Share on other sites

I'm a little lost and need some clarification.

You have a file list. Working examples are returned. What decides if it is a working examples? Then you want those working examples in another list not to exceed 18? Is this correct?

Your code seems to test if the elements have a number in the 7th and 8th position, but does not allow a 16. Then save the 7th or 7th and 8th position to a variable that will be written over in the next loop.

Not quite sure what your looking for. Please explain a little more and I'll see if I can help.

##### Share on other sites

I need to properly reconvert a string if it's found outside of the range before continuing with the loop.

What?

I didn't follow your explanation, but this seems like cleaner code to start from, using StringMid():

```\$file = "Path\file.ext"
\$success = 1
For \$i = 1 To \$aRead[0] - 1 ; Not testing the last line...?
\$count = 0
If Number(StringMid(\$aRead[\$i], 7, 6)) <> 167772 Then
; // If number is 1 or 2 digits, store them.
Else
EndIf
\$count = StringLen(\$mNUMBER)
EndIf
Next
EndIf```

You keep overwriting the variables \$mNUMBER and \$count, so you only get the last result. Is that what you intended?

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

##### Share on other sites

Here is the full portion of this function:

```Func _importgeneral()
GUISetState(@SW_HIDE, \$parent)
\$account = IniRead(\$defaultini, "file", "acctpath", "")
\$macrosgendir = \$macrosdir & "stub." & \$account & "\"
\$yesno = MsgBox(4100,"Entering Import Mode!", _
"Do you want to Import General Macros" & _
@CRLF & "to your " & \$mynameis & " account?" & _
@CRLF & @CRLF & "This will overwrite and replace any " & _
@CRLF & "General Macros numbered the same!")
Local \$success = 0
If \$yesno = 6 Then
\$file = FileOpenDialog("Choose a macros-cache.txt file...", \$macrosdir, "General (macros-cache.txt)")
; // Read the file to an array
\$success = 1
For \$i = 1 to \$aRead[0]-1
\$count = 0
; // If the string contains MACRO then we need to parse it
; // Trim MACRO from the string and store the new variable
; // If number is 1 or 2 digits, store them.
\$count = 2
Else
\$count = 1
EndIf
; // Trim the number from the string and store the new variable
; // Split the remainder of the string (separating name and icons)
;_ArrayDisplay(\$aPARSE)
\$mNAME = \$aPARSE[2]
\$mICON = \$aPARSE[3]
\$gfile = FileOpen(\$macrosgendir & "G" & \$mNUMBER & ".txt",2)
IniWrite(\$defaultacctini,"G" & \$mNUMBER,"number",\$mNUMBER)
IniWrite(\$defaultacctini,"G" & \$mNUMBER,"icon",\$mICON & ".bmp")
IniWrite(\$defaultacctini,"G" & \$mNUMBER,"abilityname",\$mICON)
IniWrite(\$defaultacctini,"G" & \$mNUMBER,"macroname",\$mNAME)
IniWrite(\$defaultacctini,"G" & \$mNUMBER,"macrocontents","G" & \$mNUMBER)
Else
\$success = 0
EndIf
Else
; close the file
FileClose(\$gfile)
Else
; write to the file
EndIf
EndIf
Next
If \$success = 0 Then
MsgBox(48,"Error","This macros-cache.txt file does not " & _
@CRLF & "fit the normal General Macros file." & _
@CRLF & "It does not contain the right numbering format.")
EndIf
Else
MsgBox(48,"Error","You need to select a macros-cache.txt file in order" & _
@CRLF & "to successfully import macros to your account.")
\$success = 0
EndIf
Else
MsgBox(48,"Exiting Import Mode","You are now exiting Import Mode!")
EndIf
If \$success = 1 Then
MsgBox(64,"Import Successful!","Your General Macros Import was successful.")
_deletebuttons()
_showbuttons()
EndIf
GUISetState(@SW_SHOW, \$parent)
EndFunc```

Basically, it parses out a file and the file contains the following:

MACRO 1 "Name" AbilityName

.. any number of lines can follow...

END

MACRO 2 "Name2" AbilityName

.. any number of lines can follow...

END

I pull the information, parse it, and rewrite it so it's usable in my program. It works fine with the exception of this:

The first file should support 1-18 macros numbered in a consecutive manner. However, over the lifetime of the file, occassionally it changes so it may appear as:

MACRO 1

MACRO 3

MACRO 10

MACRO 17

MACRO 23

MACRO 24

MACRO 26

..etc.

Even though there are only 18 spots. If I find one that is out of sequence, I want to re-sequence it correctly.

As an additional mention: there are two types of files both with duplicate names. One lists macro numbers like the following:

MACRO 16777217

MACRO 16777218

etc.

Up to an additional 18 spots. So, there are two sets of 18 to work with. What I'm checking against is making sure the file the user chose does not have the 167772.. etc in them and if not to continue processing.

I'd basically like to create something that takes:

MACRO 1

MACRO 3

MACRO 10

MACRO 17

MACRO 23

MACRO 24

MACRO 26

..etc.

and stores it into variables for:

MACRO 1

MACRO 2

MACRO 3

MACRO 4

MACRO 5

MACRO 6

MACRO 7

..etc.

The last line is not checked because it contains an empty array row. I checked it with _ArrayDisplay and the last row is completely empty. I'm not sure why it's pulling an empty row but more than likely is finding some type of @CRLF at the end of these built in files.

Edited by Ealric

My Projects: [topic="89413"]GoogleHack Search[/topic], [topic="67095"]Swiss File Knife GUI[/topic], [topic="69072"]Mouse Location Pointer[/topic], [topic="86040"]Standard Deviation Calculator[/topic]

##### Share on other sites

If you just want to sort the Ini then take a look at my INI UDF

Ini.zip

You may have to pad the single digit numbers with a leading 0 to get the proper sort. The sort function that you will want is

_IniSortSectionByValue()

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

##### Share on other sites

If you just want to sort the Ini then take a look at my INI UDF

Ini.zip

You may have to pad the single digit numbers with a leading 0 to get the proper sort. The sort function that you will want is

_IniSortSectionByValue()

Thanks GEOSoft, I'll take a look at it later and follow-up.

Appreciate the input.

My Projects: [topic="89413"]GoogleHack Search[/topic], [topic="67095"]Swiss File Knife GUI[/topic], [topic="69072"]Mouse Location Pointer[/topic], [topic="86040"]Standard Deviation Calculator[/topic]

##### Share on other sites

First of all, thanks for the feedback and assistance, and more importantly, some of the ideas.

Here's what I decided to do:

```Func _importgeneral()
GUISetState(@SW_HIDE, \$parent)
\$account = IniRead(\$defaultini, "file", "acctpath", "")
\$macrosgendir = \$macrosdir & "stub." & \$account & "\"
\$yesno = MsgBox(4100,"Entering Import Mode!", _
"Do you want to Import General Macros" & _
@CRLF & "to your " & \$mynameis & " account?" & _
@CRLF & @CRLF & "This will overwrite and replace any " & _
@CRLF & "General Macros numbered the same!")
Local \$success = 0
If \$yesno = 6 Then
\$file = FileOpenDialog("Choose a macros-cache.txt file...", \$macrosdir, "General (macros-cache.txt)")
; // Read the file to an array
\$success = 1
_ClearGIni() ; clear out the INI file and reformat it
For \$i = 1 to \$aRead[0]-1
\$count = 0
; // If the string contains MACRO then we need to parse it
; // Trim MACRO from the string and store the new variable
; // If number is 1 or 2 digits, store them.
\$count = 2
Else
\$count = 1
EndIf
If Number(\$mNUMBER) > 18 Then
\$mNUMBER = _IniStoreValue(\$defaultacctini, "G", \$mNUMBER)
EndIf
; END OF ADD NEW CODE
; // Trim the number from the string and store the new variable
; // Split the remainder of the string (separating name and icons)
\$mNAME = \$aPARSE[2]
\$mICON = \$aPARSE[3]
\$gfile = FileOpen(\$macrosgendir & "G" & \$mNUMBER & ".txt",2)
IniWrite(\$defaultacctini,"G" & \$mNUMBER,"number",\$mNUMBER)
IniWrite(\$defaultacctini,"G" & \$mNUMBER,"icon",\$mICON & ".bmp")
IniWrite(\$defaultacctini,"G" & \$mNUMBER,"abilityname",\$mICON)
IniWrite(\$defaultacctini,"G" & \$mNUMBER,"macroname",\$mNAME)
IniWrite(\$defaultacctini,"G" & \$mNUMBER,"macrocontents","G" & \$mNUMBER)
IniWrite(\$defaultacctini,"G" & \$mNUMBER,"import","yes")
Else
\$success = 0
EndIf
Else
; close the file
FileClose(\$gfile)
Else
; write to the file
EndIf
EndIf
Next
If \$success = 0 Then
MsgBox(48,"Error","This macros-cache.txt file does not " & _
@CRLF & "fit the normal General Macros file." & _
@CRLF & "It does not contain the right numbering format.")
EndIf
Else
MsgBox(48,"Error","You need to select a macros-cache.txt file in order" & _
@CRLF & "to successfully import macros to your account.")
\$success = 0
EndIf
Else
MsgBox(48,"Exiting Import Mode","You are now exiting Import Mode!")
EndIf
If \$success = 1 Then
MsgBox(64,"Import Successful!","Your General Macros Import was successful.")
_deletebuttons()
_showbuttons()
EndIf
GUISetState(@SW_SHOW, \$parent)
EndFuncoÝ÷ ÙhbrÚ²'«y§l¶ººÞÒ
±É%¹¤ ¤(%1½°ÀÌØí¤(%½ÈÀÌØí¤ôÄÑ¼Äà(\$%%¹¥]É¥Ñ ÀÌØíÕ±ÑÑ¥¹¤°ÅÕ½ÐíÅÕ½ÐìµÀìÀÌØí¤°ÅÕ½Ðí¹ÕµÈÅÕ½Ðì°ÅÕ½Ðí¹½ÑÍÐÅÕ½Ðì¤(\$%%¹¥]É¥Ñ ÀÌØíÕ±ÑÑ¥¹¤°ÅÕ½ÐíÅÕ½ÐìµÀìÀÌØí¤°ÅÕ½Ðí¥½¸ÅÕ½Ðì°ÅÕ½Ðí¹½ÑÍÐÅÕ½Ðì¤(\$%%¹¥]É¥Ñ ÀÌØíÕ±ÑÑ¥¹¤°ÅÕ½ÐíÅÕ½ÐìµÀìÀÌØí¤°ÅÕ½Ðí¥±¥Ñå¹µÅÕ½Ðì°ÅÕ½Ðí¹½ÑÍÐÅÕ½Ðì¤(\$%%¹¥]É¥Ñ ÀÌØíÕ±ÑÑ¥¹¤°ÅÕ½ÐíÅÕ½ÐìµÀìÀÌØí¤°ÅÕ½ÐíµÉ½¹µÅÕ½Ðì°ÅÕ½Ðí¹½ÑÍÐÅÕ½Ðì¤(\$%%¹¥]É¥Ñ ÀÌØíÕ±ÑÑ¥¹¤°ÅÕ½ÐíÅÕ½ÐìµÀìÀÌØí¤°ÅÕ½ÐíµÉ½½¹Ñ¹ÑÌÅÕ½Ðì°ÅÕ½Ðí¹½ÑÍÐÅÕ½Ðì¤(\$%%¹¥±Ñ ÀÌØíÕ±ÑÑ¥¹¤°ÅÕ½ÐíÅÕ½ÐìµÀìÀÌØí¤°ÅÕ½ÐíÁ±¡½±ÈÅÕ½Ðì¤(\$%%¹¥]É¥Ñ ÀÌØíÕ±ÑÑ¥¹¤°ÅÕ½ÐíÅÕ½ÐìµÀìÀÌØí¤°ÅÕ½Ðí¥µÁ½ÉÐÅÕ½Ðì°ÅÕ½Ðí¹½ÑÍÐÅÕ½Ðì¤(%9áÐ)¹Õ¹```

I used your number suggestion Psaltry but midstring wasn't the right way to go as I'm actively parsing out this string into chunks of data. I'm removing common areas and then using a separator value to determine the remainder of the string. It works perfectly so I'm not going to change anything with that bit of code.

GEO, your ini examples helped out a lot. I didn't need to sort but they gave me some good ideas which revolved around actively managing the .ini versus trying to calculate the math of the existing variables. Thanks for your help.

Edited by Ealric

My Projects: [topic="89413"]GoogleHack Search[/topic], [topic="67095"]Swiss File Knife GUI[/topic], [topic="69072"]Mouse Location Pointer[/topic], [topic="86040"]Standard Deviation Calculator[/topic]

## Create an account

Register a new account

×

• Wiki

• Back

• Git