Jump to content
Sign in to follow this  
AutID

Comparing variables

Recommended Posts

$1 = "Q"
$2 = "W"
$3 = "Y"
$4 = "U"
$5 = "S"
$6 = "Y"

$c = "Y"

$i=0
$string=$1&$2&$3&$4&$5&$6

Do
    $i+=1
    $ret=StringInStr($string,$c,1,$i)
    MsgBox(0,"",StringReplace($ret,"0","that's all"))
Until $ret=0

MsgBox(0,"",StringTrimRight("no (more)",6*($i=0))&" '"&$c&"' found.")

:thumbsup:

 

 too many conclusive msgbox ... :geek:  one would be sufficient......

Edited by Pincopanco

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

ah you make the rules .....

.

$1 = "Q"
$2 = "W"
$3 = "Y"
$4 = "U"
$5 = "S"
$6 = "Y"

$c = "Y"

$i=0
$string=$1&$2&$3&$4&$5&$6

Do
    $i+=1
    $ret=StringInStr($string,$c,1,$i)
    MsgBox(0,"",StringReplace($ret,"0","that's all"))
Until $ret=0

;MsgBox(0,"",StringTrimRight("no (more)",7*($i=0))&" '"&$c&"' found.")

[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Share this post


Link to post
Share on other sites

Wouldn't it just be easier to use the If/Endif statements instead of trying to find some stupid ways around it?

I mean stupid in the sense of this whole exercise, not the examples themselves, some of which are quite interesting.

Just do it the right way, the easiest way, and don't be anal about a few If statements in your code.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

$1 = "Q"
$2 = "W"
$3 = "Y"
$4 = "U"
$5 = "S"
$6 = "Y"

$c = "Y"

$i=0
$string=$1&$2&$3&$4&$5&$6
$ret=""

Do
    $i+=1
    $ret&=StringInStr($string,$c,1,$i)&","
Until StringRight($ret,2)="0,"

MsgBox(0,"",$c&StringTrimLeft(" not found in places ",4*($ret<>"0,"))&StringTrimRight($ret,3))

.

anal ?

Edited by Edano

[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Share this post


Link to post
Share on other sites

in fact, i am a big really big fan of avoiding if's in a script. you can spare a lot of lines by doing it.


[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Share this post


Link to post
Share on other sites

Edano, you're smart,
however, not to be anal :) , but I was just curious as to a solution found by AutID On His code on post  >#9,

....but never mind.


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

wow, is this still hot or a competition ??? ;)

.

$1 = "Q"
$2 = "W"
$3 = "Y"
$4 = "U"
$5 = "S"

$c = "Y"

$string=$1&$2&$3&$4&$5

MsgBox(0,"",StringInStr($string,$c))

.

E.

Edit: of course, using includes is cheating. you could include every au3 script you want, even self written. this is cheating

I will not even comment this.

 

Wouldn't it just be easier to use the If/Endif statements instead of trying to find some stupid ways around it?

I mean stupid in the sense of this whole exercise, not the examples themselves, some of which are quite interesting.

Just do it the right way, the easiest way, and don't be anal about a few If statements in your code.

I prefer clean projects every time I do one. If statement is the easy way but if I use the easy way everywhere my project will get 3 times bigger without reason.

This is what I am using atm.

Func _Indexreturn()
 Local $values[10] = [$1, $2, $3, $4, $5, $6, $7, $8, $9, $10]
 Local $index = _ArraySearch($values, $aKeys[$c])
 Return $index
EndFunc

I find it better than an If statement but anyway.

 

Share this post


Link to post
Share on other sites

If you use the obfuscater and just use the /so option to strip unused functions, then open the obfuscated script, you'll see that there's a lot more in your script than you think there is, and a simple if/then/endif would probably make your script much smaller in the long run rather than using the Array UDF and _ArraySearch.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

If you use the obfuscater and just use the /so option to strip unused functions, then open the obfuscated script, you'll see that there's a lot more in your script than you think there is, and a simple if/then/endif would probably make your script

I already thought about it but array udf is already included in my script so i don't have a lot to loose. Not all array functions can be replaced with if statements.

Anyway thank you, you seem to be clever ;)

Edited by AutID

Share this post


Link to post
Share on other sites

another passion of mine :.... avoid includes ...... really

I already thought about it but array udf is already included in my script so i don't have a lot to loose. Not all array functions can be replaced with if statements.
Anyway thank you, you seem to be clever ;)


[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Share this post


Link to post
Share on other sites

The only way to do what you are saying is to copy the array functions on my own udfs included in my script but come to think of it. A lot of the array functions call each other so in the end i will have to include the udfs. And please stop telling things like these because there are people who will be looking for similar things and read what you are saying

Share this post


Link to post
Share on other sites

maybe it is YOUR way to copy and paste functions, which is really stupid and senseless. but i use them to learn the logic and apply the learned to my code.

and PLEASE never ever tell me again what i have to say and what not.


[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Share this post


Link to post
Share on other sites

Please calm down Edano. AutId wasn't teaching you but was rightfully thinking that such advice you gave wasn't for beginners and needed context to not be taken at face value.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

you are right, not for beginners. and i am calm. i said what had to be said. now it's okay.


[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Share this post


Link to post
Share on other sites

Even so, advanced AutoIt programmers use Includes, I mean why have a dog and bark yourself!


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites

I was amusing myself with creating a few ways of achieving the original challenge that AutID and finding that an If Then structure (no need for any elseif) was the fastest method set, but then I found that the rules had changed. :ermm:

As a bit of an aside I am puzzled by the number of Autoit users who seem to go to great effort using all sorts of convoluted methods to make their code span as few lines as possible, usually with the result of a slower script in which the logic is harder to follow and debug. Many of the applications that I write often involve manipulating data in huge text files. Many is the number of times that I have managed to make it run ten time faster by adding a few hundred extra lines of code. This is especially true if you have some knowledge of the frequency with which data will occur and branch your code so that the most likely cases are checked first. It's not the total number of lines in your source code that affects the speed of your application, but the number of instructions that need to be executed to complete the task. The rule is where there are many possible routes eliminated the least likely as quickly as possible.


"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...