v1 -> v2 Script Converter

Post your working scripts, libraries and tools for AHK v1.1 and older
guest3456
Posts: 3454
Joined: 09 Oct 2013, 10:31

Re: v1 -> v2 Script Converter

05 Aug 2021, 01:51

AHK_user wrote:
04 Aug 2021, 23:41
My idea is not to parse the v1 script string, but to put it in an global object and a global index so we can easily check temporary the following lines or the previous lines. This way you could also handle continuation section better and probably also the errorlevel variable.
sounds like a big change. do all the existing tests pass with your update?
AHK_user wrote:
04 Aug 2021, 23:41
REQUEST:
I am currently looking for a way to split or parse a string with "," but I want to keep into account the ahk syntax. Does this already exists?

Example:
stringtosplit := "var1, `"va,r2`", function(jkllksd,"")"",`"((`"),'ssdfsdf'"
=>
array[1] := "var1"
array[2] := "`"va,r2`""
array[3] := "function(jkllksd,"")"",`"((`")"
array[4] := "'ssdfsdf'"
not that i know of. what do you need this for?

AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: v1 -> v2 Script Converter

05 Aug 2021, 05:32

guest3456 wrote:
05 Aug 2021, 01:51
AHK_user wrote:
04 Aug 2021, 23:41
My idea is not to parse the v1 script string, but to put it in an global object and a global index so we can easily check temporary the following lines or the previous lines. This way you could also handle continuation section better and probably also the errorlevel variable.
sounds like a big change. do all the existing tests pass with your update?
AHK_user wrote:
04 Aug 2021, 23:41
REQUEST:
I am currently looking for a way to split or parse a string with "," but I want to keep into account the ahk syntax. Does this already exists?

Example:
stringtosplit := "var1, `"va,r2`", function(jkllksd,"")"",`"((`"),'ssdfsdf'"
=>
array[1] := "var1"
array[2] := "`"va,r2`""
array[3] := "function(jkllksd,"")"",`"((`")"
array[4] := "'ssdfsdf'"
not that i know of. what do you need this for?
Most of the functions seemed ok, but I will redo my changes one by one and test them to see if it has any impact. Maybe It could give some trouble with the AutoTrim, guess we will need to disable it. I`ve done some tests and it seems to be useful to gather extra parameters if you encounter a continuation section (although most people do not use them, It would be nice to include this).

I need the parser as sometimes the parameters are containing commas, and the normal loop parse, "," or SplitStr will not return the correct parameter array. I guess that I will create it by looping over the characters one by one and keeping track of the ",',...
guest3456
Posts: 3454
Joined: 09 Oct 2013, 10:31

Re: v1 -> v2 Script Converter

05 Aug 2021, 09:53

AHK_user wrote:
05 Aug 2021, 05:32
I need the parser as sometimes the parameters are containing commas, and the normal loop parse, "," or SplitStr will not return the correct parameter array. I guess that I will create it by looping over the characters one by one and keeping track of the ",',...
yeah a big limitation so far is that we are not handling functions or expressions, so unescaped commas inside a string like this:

Func("hello,world", 2ndparam)

i'm not sure if the converter can handle

AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: v1 -> v2 Script Converter

05 Aug 2021, 14:47

My excuses, my example was a confusing mix of v1 and v2 syntax: :facepalm:
lets keep it v1, as that would be the input :)

Example:
stringtosplit := "var1, ""va,r2"", function(jkllksd,"")"","" ((""),'ssdfsdf'"
=>
array[1] := "var1"
array[2] := """  va,r2"""
array[3] := "function(jkllksd,"")"","" (("")"
array[4] := "'ssdfsdf'"
guest3456
Posts: 3454
Joined: 09 Oct 2013, 10:31

Re: v1 -> v2 Script Converter

05 Aug 2021, 16:16

AHK_user wrote:
05 Aug 2021, 14:47
My excuses, my example was a confusing mix of v1 and v2 syntax: :facepalm:
lets keep it v1, as that would be the input :)

Example:
stringtosplit := "var1, ""va,r2"", function(jkllksd,"")"","" ((""),'ssdfsdf'"
=>
array[1] := "var1"
array[2] := """  va,r2"""
array[3] := "function(jkllksd,"")"","" (("")"
array[4] := "'ssdfsdf'"
as far as i know, you'd have to build that yourself. i don't believe we can handle that right now

i'm working on updating all the existing test code so that it works with v2beta. that way at least all the commands in the converter will convert properly. and then we can proceed to add new commands/conversions. however, as i work through this, i'm reminded just how tedious this work is. its just blind gruntwork, no creativity, no nothing, complete waste of time

AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: v1 -> v2 Script Converter

05 Aug 2021, 18:42

My hope is that it will save me some time to convert a huge script of mine in the future, or at least help me converting it.
I will probably give some priority to commands and syntaxes that I normally use :lol: :lol:

Ok, I have added:
- Improved MsgBox (1,3 &4-Parameter method and continuity section)
- Start of GUI
- Start of Menu
- XButton1 hotkey to convert selected text and quickly run it in both v1 and v2 code
- Functionality to check if there is a continuity section
- Changed the loop parse to a loop array, so we are able to peek forward and backward.

Comments:
- I also checked if the old test are still valid, they are :D
- My new tests seems to be always correct, but I get a lot of false positives althrough the conversion is correct, does somebody knows what the cause is? :think: :think: :think:

I am also missing some features in the tester:
- Rightclick menu on the tree to see the comparison and the possible error
- It would be nice to have a button to run the code to check if it gives the same effect
- In the comparison, it would also be usefull to be able to have acces to the V1 code

I will probably first start to create a parser that can handle the ahk syntax better, Probably all the commands and functions can use this.
And focus on msgbox handling, Gui and menu, so they can handle more complex syntax. Probably I will test it on some typically code of mine and make sure it handles it correctly.
guest3456
Posts: 3454
Joined: 09 Oct 2013, 10:31

Re: v1 -> v2 Script Converter

05 Aug 2021, 19:49

AHK_user wrote:
05 Aug 2021, 18:42
- My new tests seems to be always correct, but I get a lot of false positives althrough the conversion is correct, does somebody knows what the cause is? :think: :think: :think:
can you show an example? maybe its difference between `n and `r`n ? i've had that. the visual diff doesn't pick it up. maybe a newer version of mergely does

AHK_user wrote:
05 Aug 2021, 18:42
I am also missing some features in the tester:
- Rightclick menu on the tree to see the comparison and the possible error
the tree is part of the Yunit unit testing project and not part of the converter
AHK_user wrote:
05 Aug 2021, 18:42
- It would be nice to have a button to run the code to check if it gives the same effect
so at the top of the Tests.ahk file, there is a bool toggle which will also add execution tests to check that the code gives the same effect. you can turn that to true and then all tests will also add the execution tests. this can be cumbersome when you have a lot of errors because you get a ton of msg boxes. alternatively, each individual test has an if-statement which checks that bool switch. you can simply comment it out to test that code by itself. thats what i do all the time. keep in mind, i'm just about finished. matter of fact, i'm going to upload to github right now most of the changes. go look

i just noticed now that you opened some new pull requests. there will likely be conflicts with the new code i just pushed right now. do you know how to git rebase? if not, i'll take a look at your stuff tomorrow
AHK_user wrote:
05 Aug 2021, 18:42
- In the comparison, it would also be usefull to be able to have acces to the V1 code
unfortunately the "mergely" library that i used to do the diff only supports 2 files

User avatar
JoeSchmoe
Posts: 129
Joined: 08 Dec 2014, 08:58

Re: v1 -> v2 Script Converter

05 Aug 2021, 20:11

AHK_user wrote:
04 Aug 2021, 23:41
My idea is not to parse the v1 script string, but to put it in an global object and a global index so we can easily check temporary the following lines or the previous lines. This way you could also handle continuation section better and probably also the errorlevel variable.
That's a bold approach and would certainly allow for more complex conversions. Do you think it would scale for larger files from a memory standpoint? To be honest, text files are so small, I could imagine it working. It seems like upgrading to this approach would be doable from a coding time perspective. Perhaps just give it a try? You could import the code into your object and then, with minimal changes, have the script iterate through the lines of the object rather than doing a main "Loop, Parse" loop like it does now.

What I love about @guest3456's code is that it is easy to understand, making changes like this possible.

Guest3456, I love to see your commits today. How would you feel about that idea? How would you feel about him creating a little github "mini-fork" to explore things like this? Sometimes it's nice to have your own repo so you can pursue changes immediately as you think of them.
AHK_user wrote:
04 Aug 2021, 23:41
REQUEST:
I am currently looking for a way to split or parse a string with "," but I want to keep into account the ahk syntax. Does this already exists?

Example:
stringtosplit := "var1, `"va,r2`", function(jkllksd,"")"",`"((`"),'ssdfsdf'"
=>
array[1] := "var1"
array[2] := "`"va,r2`""
array[3] := "function(jkllksd,"")"",`"((`")"
array[4] := "'ssdfsdf'"
I'm not the most advanced coder, but I did notice that @MrDoge got some great help from some big guns when he posted a similar question for his conversion script here: https://www.autohotkey.com/boards/viewtopic.php?p=413329#p413329

I'd bet that there are a lot of v2-loving people who would love to see this project thrive, but they may not be reading this thread, especially since it's in the v1 scripts subforum. Perhaps post your question in the v2 help subforum?
https://www.autohotkey.com/boards/viewforum.php?f=82
I've gotten great responses quickly when I've posted there. Lexikos even answered me one time.

Speaking of the location of this thread, given that it is written in v2, might it be worth moving it to the v2 scripts subforum? There, it would get more attention from people who are excited about v2 or attempting to learn about it.
guest3456
Posts: 3454
Joined: 09 Oct 2013, 10:31

Re: v1 -> v2 Script Converter

06 Aug 2021, 00:53

JoeSchmoe wrote:
05 Aug 2021, 20:11
Guest3456, I love to see your commits today. How would you feel about that idea? How would you feel about him creating a little github "mini-fork" to explore things like this? Sometimes it's nice to have your own repo so you can pursue changes immediately as you think of them.
bro its open source, he can do whatever he wants, doesnt need permission. his PRs today look good on first glance
JoeSchmoe wrote:
05 Aug 2021, 20:11
AHK_user wrote:
04 Aug 2021, 23:41
REQUEST:
I am currently looking for a way to split or parse a string with "," but I want to keep into account the ahk syntax. Does this already exists?
I'm not the most advanced coder, but I did notice that @MrDoge got some great help from some big guns when he posted a similar question for his conversion script here: https://www.autohotkey.com/boards/viewtopic.php?p=413329#p413329
thats for parsing 'if var in matchlist' which we still need to do, so we'll likely use one of those solutions. its not exactly similar because what AHK_user is doing is one level higher than that
JoeSchmoe wrote:
05 Aug 2021, 20:11
I'd bet that there are a lot of v2-loving people who would love to see this project thrive, but they may not be reading this thread, especially since it's in the v1 scripts subforum. Perhaps post your question in the v2 help subforum?
https://www.autohotkey.com/boards/viewforum.php?f=82
I've gotten great responses quickly when I've posted there. Lexikos even answered me one time.

Speaking of the location of this thread, given that it is written in v2, might it be worth moving it to the v2 scripts subforum? There, it would get more attention from people who are excited about v2 or attempting to learn about it.
i think its fine here, but i dont really care where it goes. whats relevant is getting more people to help contribute, which for that, i think it gets more eyes here. talking goes nowhere. writing code does. its a huge project with thousands of different edge cases. so whoever wants to see it thrive can help contribute

AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: v1 -> v2 Script Converter

06 Aug 2021, 05:29

I have created a function to parse parameters better. :dance: :dance: :dance:

Could you check the test and see if I missed a syntax?
Please try to make it fail with a new test of your own so we can make it ahkv1-proof (of course this test should be a possible working ahk v1 script). :lol: :lol: :lol:
I think it works quite well, but maybe I missed some syntax situations.

Currently written in V1, but we we can easily convert it :D
Speed improvements are of course welcome, but I kept it readable for now.
Maybe I could use regex to skip all the characters that are not ",{}[]`' , I`ll have to test if this improves the speed, but the result should logically be identical.

Correction:
- Removed conditions for "[" and "(" as a function can be inside a function. (Also added to the test.)

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
test := ( "ksdjsdklfj", "dsfdfd")
DebugWindow("test:" test "`n",Clear:=0)
test := "var1 kjksdjfk ssfsf , var2 ``, variable, 3 , 'var4 ,Apostrope""fs',  ""var5 string, fd"", var6Array[tes,']',  t], {""var7"", {""test"", ""second""}, ""object}""}, var8fuction(instr(sjsdlk, sdfd),""sdk, jk"",  "")"", sdfkdj), % var9, . var10, End11"

oResult:= V1ParSplit(test)
For oIndex in oResult
{
	DebugWindow(oIndex ": [" oResult[oIndex] "]`n",Clear:=0)
	if !InStr(oResult[oIndex], oIndex){
		msgbox !!! ---------------- Error detected ----------------- %oIndex%
	}
}

return

; --------------------------------------------------------------------
; Purpose: Read a ahk v1 command line and separate the variables
; Input:
;   String - The string to parse.
; Output:
;   RETURN - array of the parsed commands.
; --------------------------------------------------------------------
V1ParSplit( String){
	; Created by Ahk_user
	; spinn-off from DeathByNukes from https://autohotkey.com/board/topic/35663-functions-to-get-the-original-command-line-and-parse-it/
	
	oResult:={} ; Array to store result
	oIndex:=1 ; index of array
	InArray := 0
	InApostrophe := false
	InFunction := 0
	InObject := 0
	InQuotes := false
	
	
	
	oString := StrSplit(String)
	
	Loop, % oString.Length()
	{
		Char := oString[A_Index]
		if ( !InQuotes && !InObject && !InArray && !InApostrophe && !InFunction){
			if (Char="," && oString[A_Index-1] !="``"){
				oIndex++
				; Set the probable/maximum size beforehand to avoid multiple resizings while assembling it.
				VarSetCapacity( oResult[oIndex], StrLen( String ) )
				Continue
			}
		}
		
		if ( Char = """" && !InApostrophe){
			InQuotes := !InQuotes
		}
		else if ( Char = "'" && !InQuotes){
			InApostrophe := !InApostrophe
		}
		else if (!InQuotes && !InApostrophe){
			if ( Char = "{"){
				InObject++
			}
			if ( Char = "}" && InObject){
				InObject--
			}
			if ( Char = "["){
				InArray--
			}
			if ( Char = "]" && InArray){
				InArray++
			}
			if ( Char = "("){
				InFunction++
			}
			if ( Char = ")" && InFunction){
				InFunction--
			}
		}
		oResult[oIndex] .= Char
	}
	return oResult
}


DebugWindow(Text,Clear:=0,LineBreak:=0,Sleep:=0,AutoHide:=0,MsgBox:=0){
	if WinExist("AHK Studio"){
		x:=ComObjActive("{DBD5A90A-A85C-11E4-B0C7-43449580656B}"),x.DebugWindow(Text,Clear,LineBreak,Sleep,AutoHide,MsgBox)
	}
	else{
		OutputDebug, %Text%
	}
}
Last edited by AHK_user on 09 Aug 2021, 05:23, edited 2 times in total.
guest3456
Posts: 3454
Joined: 09 Oct 2013, 10:31

Re: v1 -> v2 Script Converter

06 Aug 2021, 08:12

AHK_user wrote:
06 Aug 2021, 05:29
Could you check the test and see if I missed a syntax?
Please try to make it fail with a new test of your own so we can make it ahkv1-proof (of course this test should be a possible working ahk v1 script). :lol: :lol: :lol:
good job. i personally prefer readability over smaller/faster code. but if you decide to change to regex, make sure you put a comment describing what the regex does, so people don't have to try to figure out the regex themselves. regex is usually slower too

but do you have Tests to provide yourself? typically you should be writing tests alongside your code, as you write it. if you look up "test driven development" the idea is that when you write code, you are always writing it for a goal. even your first line that you write, you are writing it so that the function will output a result. so maybe you were just trying to parse a basic string like "one,two". well, that is a test case, and you should write it first, and then write the code to pass. and then do it again, and again, etc.then by the end you'd be surprised at how many tests you have, for a bunch of different cases.

i understand for most projects, writing tests are tedious work, but any time you write something like a converter or parser, the tests are absolutely crucial. because as you add new features, you need the test suite to make sure you dont add regression bugs which break older features

as it is now, we have very little tests for your new code. i guess i have the 4 lines you provided in your previous post, and the example you provided in this script.
here were the results i got:
https://imgur.com/BGmEFam

and so what is the plan for using this? what type of v1 script line are you going to use this for, to do conversion? replace the initial command parameter parser that we have originally? in that case, you can try plugging it in and running through our full test suite and see how it does

also did you see my comments on your pull requests? i want to add in your changes, but its hard to see the changes you made because you've changed all the indentiation from spaces to tabs. can you stick with the project default? most decent text editors are able to switch/convert those. if your editor can auto change based on an editorconfig file, then i could add that to the project

finally, i pushed the latest commit which now means all existing tests are v2beta1 conversion compatible

AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: v1 -> v2 Script Converter

24 Aug 2021, 16:26

I have uploaded my changes uptill now in
https://github.com/dmtr99/AHK-v2-script-converter/tree/master/tests

Because I did not liked adding tests time-consuming and manually, I have created a different test method, that just saves the tests as separate files. This makes it easy to manage them, and you can save them with a simple click. I will probably also add some extra methods to compare the final result of the code. The only disadvantage is that you end up with a lot of files.

It is still work in progress, but if somebody is curious, you can, It is getting better and better. A lot of the v1 documentation examples convert already quite good.

The best way to test it is to use [tests\TestFiles.ahk] this opens a gui that let`s you:
- Run the v1 and v2 code
- Lookup the ahk documentation of the word arround the cursor (depending on what Edit, it looks for V1 or V2) (Hotkey: F1)
- Let`s you save tests
- Convert selected text (XButton1)

I also created a small separated convertor, with the sole purpose to add brackets to the hotkeys/hotstrings. But I kept it separate for now. You can test is with the test menu in TestFiles.ahk

The more I learn about V2, the more I like it, good improvements and less change on errors.
guest3456
Posts: 3454
Joined: 09 Oct 2013, 10:31

Re: v1 -> v2 Script Converter

24 Aug 2021, 17:38

AHK_user wrote:
24 Aug 2021, 16:26
I have uploaded my changes uptill now in
https://github.com/dmtr99/AHK-v2-script-converter/tree/master/tests

Because I did not liked adding tests time-consuming and manually, I have created a different test method, that just saves the tests as separate files. This makes it easy to manage them, and you can save them with a simple click. I will probably also add some extra methods to compare the final result of the code. The only disadvantage is that you end up with a lot of files.

It is still work in progress, but if somebody is curious, you can, It is getting better and better. A lot of the v1 documentation examples convert already quite good.

The best way to test it is to use [tests\TestFiles.ahk] this opens a gui that let`s you:
- Run the v1 and v2 code
- Lookup the ahk documentation of the word arround the cursor (depending on what Edit, it looks for V1 or V2) (Hotkey: F1)
- Let`s you save tests
- Convert selected text (XButton1)

I also created a small separated convertor, with the sole purpose to add brackets to the hotkeys/hotstrings. But I kept it separate for now. You can test is with the test menu in TestFiles.ahk

The more I learn about V2, the more I like it, good improvements and less change on errors.
excellent, i will have to take a look at this when i have time

so do these changes supercede your previous gui/msgbox pull requests? it looks like you removed all the tabs and are using spaces exclusively now. can i just merge in these new changes and skip your old pull requests?

a tip for using git, you shouldnt really be making large commits with "lots of work done".. you should make small commits for one singular change. then do it again for the next change. etc. that way its easier to see each individual change. if you google "git small commits" you will get lots of information

compare your singular big commit:
https://github.com/dmtr99/AHK-v2-script-converter/commit/00ad45d765730451e36cfdc5b386075e328a7d10

to something like this:
https://github.com/mmikeww/AHK-v2-script-converter/commit/eaae04342b65e331d101a4247de00f8824134f6b

your singular commit adds a million features, which means if you mistakenly broke something, there is a lot of code to review to try to track down the changes. whereas in my example commit there, the changed code is very clear with intent and purpose. as you get better with git, you will realize the benefit of this. but yes, same as with the tests, it is time consuming to learn and put into practice. but trust me, as projects grow, it is hugely beneficial

AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: v1 -> v2 Script Converter

24 Aug 2021, 19:41

Yes, these changes include also my msgbox changes. :D

I understand that Github is great when working with multiple people at the same time, but it seems to slow the programmer down and a lot of my changes will only work in combination of the previous changes. And I should really get to know the internal VS Code functions to work with Github, but lack the time...

I kept checking the previous existing yunit tests and they did not seem to fail :thumbup: :thumbup: :thumbup: . I will probably also try to improve the saving of the test, so it also verifies the generated output when it sees a creation of a file.

For now I did not added checks for every added function, as I know that some convertions can still change. I did not checked and tested every convertion in detail, for now I focused on convertion of examples in the documentation and improve the test gui to make it easier to generating tests.

If somebody has some working v2 RighEdit script, It would be nice to add it to my TestFiles.ahk

I also created a convertion function to be able to replace specific pseudo-arrays to the new format, but this is not yet implemented.
This could be used for RegexMatch and StrSplit :dance:

Code: Select all

#Requires AutoHotkey v2.0-a
text:= "
(
    test := array%sdsfs% array%sdsfs%
    array%sdsfs%sds ; do not convert
    darray%A_index% ; do not convert
    msgbox, array1 array21456479 array%sdsfs%
)"
MsgBox(ConvertPseudoArray(text,"array"))

ConvertPseudoArray(ScriptString,ArrayName){
    Loop {
        ScriptString := RegExReplace(ScriptString, "is)(^(|.*[^\w])" ArrayName ")(%(\w+)%|(\d+))(([^\w].*|)$)", "$1[$4$5]$6",&OutputVarCount) 
          
    } Until OutputVarCount = 0
    Return ScriptString
}
guest3456
Posts: 3454
Joined: 09 Oct 2013, 10:31

Re: v1 -> v2 Script Converter

24 Aug 2021, 22:27

AHK_user wrote:
24 Aug 2021, 19:41
I understand that Github is great when working with multiple people at the same time, but it seems to slow the programmer down and a lot of my changes will only work in combination of the previous changes. And I should really get to know the internal VS Code functions to work with Github, but lack the time...
github is very convenient when working with multiple people at the same time, but git itself is useful even if you are a solo programmer. as you get more experience with trying to debug and track your changes, you will appreciate it immensely. but it requires you to start, which of course takes time for the learning curve. even for all of my personal projects, i always start a git repo and make small commits as i'm building things, even if they are throwaway projects that might never go anywhere
AHK_user wrote:
24 Aug 2021, 19:41
I kept checking the previous existing yunit tests and they did not seem to fail :thumbup: :thumbup: :thumbup: . I will probably also try to improve the saving of the test, so it also verifies the generated output when it sees a creation of a file.

For now I did not added checks for every added function, as I know that some convertions can still change. I did not checked and tested every convertion in detail, for now I focused on convertion of examples in the documentation and improve the test gui to make it easier to generating tests.
the purpose of the tests is so that we can ensure that previous things dont break as we add new features. so its great that you continue to keep checking against the existing yunit tests. thats the whole point. and even if you're just focusing on the examples in the docs, thats fine, but make tests (in the old format or your new format) so that we can keep checking them as this converter grows. there is tremendous value in keeping a large testing suite, probably just as much so as the convertor itself. but yes writing tests is tedious work

safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: v1 -> v2 Script Converter

06 Sep 2021, 01:05

Good work to those involved in this.
@AHK_user I've seen your extension on the project, and I've noticed some changes that you could consider.
I did some changes but I'm not familiar enough to know if it's the best way.
In ConvertFuncs.ahk...
Line 071 changed to: BlockInput,OptionT2E | BlockInput({1}) (it was not converting to string)
Line 269 changed to: OnClipboardChange(FuncQ2T,AddRemove) | OnClipboardChange({1},{2})
guest3456
Posts: 3454
Joined: 09 Oct 2013, 10:31

Re: v1 -> v2 Script Converter

06 Sep 2021, 09:14

his additions will be merged into the main project, i just need to get some free time. he is doing great work

AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: v1 -> v2 Script Converter

06 Sep 2021, 14:56

safetycar wrote:
06 Sep 2021, 01:05
Good work to those involved in this.
@AHK_user I've seen your extension on the project, and I've noticed some changes that you could consider.
I did some changes but I'm not familiar enough to know if it's the best way.
In ConvertFuncs.ahk...
Line 071 changed to: BlockInput,OptionT2E | BlockInput({1}) (it was not converting to string)
Line 269 changed to: OnClipboardChange(FuncQ2T,AddRemove) | OnClipboardChange({1},{2})
Thanks for the compliments :D , I am working hard to improve it.

And thanks to pointing out the changes, I went over it quite fast to get a rough working script, and now I am testing it more in detail so it is normal that some coding errors are made. Currently working on GuiControl :D

BlockInput is changed
OnClipboardChange is also done, I also added a labelToFunction convertion in it.

It is becoming to be usable, and most of the v1 examples begin to work. But at the moment I still find convertion errors.
I think this will be a great help for people who want to convert their scripts.

Possible problems:
- The use of terniary operators in commands, but even that could maybe handled if somebody uses it a lot.
- Objects are quite hard to tell if they should be an object, map or array

Code: Select all

#Persistent
return

OnClipboardChange:
ToolTip Clipboard data type: %A_EventInfo%
Sleep 1000
ToolTip  ; Turn off the tip.
return

=>

Code: Select all

OnClipboardChange(ClipChanged)
Persistent
return

ClipChanged(Type)
{ ; V1toV2: Added bracket
ToolTip("A_Clipboard data type: " Type)
Sleep(1000)
ToolTip()  ; Turn off the tip.
return
} ; V1toV2: Added bracket in the end
Currently I am improving the Gui conversion, very tricky, but this beautiful example already works.

Code: Select all

Gui, Add, Text,vTextC, First name:
Gui, Add, Edit, vFirstName hwndtest  ; The ym option starts a new column of controls.

Gui, Add, Picture, vMyPic w20 h-1, C:\Users\Dimitri\Pictures\Save24.png
Gui, Add, CheckBox, vMyCheckBox, Option1
Gui, Add, Radio, vMyRadio, Radio
Gui, Add, Radio, , Radio2
Gui, Add, DropDownList, vMyDropDownList, Black|White|Red|Green|Blue
Gui, Add, ListBox, r5 vmyListBox, Red|Green|Blue|Black|White
Gui, Add, ComboBox, vMyComboBox, Red|Green|Blue|Black|White
Gui, Add, Link, vMyLink, This is a <a href="https://www.autohotkey.com">link</a>
Gui, Add, Hotkey, vMyHotkey
Gui, Add, DateTime, vMyDateTime,


Gui, Add, Button, vMyButton default, OK  ; The label ButtonOK (if it exists) will be run when the button is pressed.

Gui, Show,, Simple Input Example
return  ; End of auto-execute section. The script is idle until the user does something.

ButtonOK:
Gui, Submit, nohide  ; Save the input from the user to each control's associated variable.
GuiControl, , TextC, test
GuiControl, , % test, test

GuiControl, , MyPic, C:\Users\Dimitri\Pictures\test.png
GuiControl, , MyCheckBox, 1
GuiControl, , MyRadio, 1
GuiControl,, MyDropDownList,test
GuiControl,,myListBox,test1|test2
GuiControl,,MyComboBox,|test1|test2
GuiControl,,MyLink, test
GuiControl,,MyHotkey, ^!c
GuiControl,,MyDataTime, 01/01/2000

GuiControl, , MyButton, test
return
GuiClose:

ExitApp
=>

Code: Select all

myGui := Gui()
myGui.OnEvent("Close", GuiClose)
ogcTextC := myGui.Add("Text", "vTextC", "First name:")
ogcEditFirstName := myGui.Add("Edit", "vFirstName")
test := ogcEditFirstName.hwnd  ; The ym option starts a new column of controls.

ogcPictureMyPic := myGui.Add("Picture", "vMyPic w20 h-1", "C:\Users\Dimitri\Pictures\Save24.png")
ogcMyCheckBox := myGui.Add("CheckBox", "vMyCheckBox", "Option1")
ogcMyRadio := myGui.Add("Radio", "vMyRadio", "Radio")
myGui.Add("Radio", , "Radio2")
ogcMyDropDownList := myGui.Add("DropDownList", "vMyDropDownList", ["Black", "White", "Red", "Green", "Blue"])
ogcmyListBox := myGui.Add("ListBox", "r5 vmyListBox", ["Red", "Green", "Blue", "Black", "White"])
ogcMyComboBox := myGui.Add("ComboBox", "vMyComboBox", ["Red", "Green", "Blue", "Black", "White"])
ogcMyLink := myGui.Add("Link", "vMyLink", "This is a <a href=`"https://www.autohotkey.com`">link</a>")
ogcMyHotkey := myGui.Add("Hotkey", "vMyHotkey")
ogcMyDateTime := myGui.Add("DateTime", "vMyDateTime")


ogcMyButton := myGui.Add("Button", "vMyButton default", "OK")
ogcMyButton.OnEvent("Click", ButtonOK)  ; The label ButtonOK (if it exists) will be run when the button is pressed.

myGui.Title := "Simple Input Example"
myGui.Show()
return  ; End of auto-execute section. The script is idle until the user does something.

ButtonOK(*)
{ ; V1toV2: Added bracket
oSaved := myGui.Submit("0")
FirstName := oSaved.FirstName
MyCheckBox := oSaved.MyCheckBox
MyRadio := oSaved.MyRadio
MyDropDownList := oSaved.MyDropDownList
myListBox := oSaved.myListBox
MyComboBox := oSaved.MyComboBox
MyHotkey := oSaved.MyHotkey
MyDateTime := oSaved.MyDateTime  ; Save the input from the user to each control's associated variable.
ogcTextC.Value := "test"
ogcEditFirstName.Value := "test"

ogcPictureMyPic.Value := "C:\Users\Dimitri\Pictures\test.png"
ogcMyCheckBox.Value := 1
ogcMyRadio.Value := 1
ogcMyDropDownList.Add(["test"])
ogcmyListBox.Add(["test1", "test2"])
ogcMyComboBox.Delete() ;Clean the list
ogcMyComboBox.Add(["test1", "test2"])
ogcMyLink.Text := "test"
ogcMyHotkey.Value := "^!c"
ogcMyDataTime.Value := "01/01/2000"

ogcMyButton.Text := "test"
return
} ; V1toV2: Added bracket before function
GuiClose(*)

{ ; V1toV2: Added bracket
ExitApp

} ; Added bracket in the end
guest3456
Posts: 3454
Joined: 09 Oct 2013, 10:31

Re: v1 -> v2 Script Converter

08 Sep 2021, 00:43

this project lives on

@AHK_user is doing amazing work, and now has write access to the repository, so he can update the converter directly himself

AHK_user
Posts: 515
Joined: 04 Dec 2015, 14:52
Location: Belgium

Re: v1 -> v2 Script Converter

08 Sep 2021, 05:41

guest3456 wrote:
08 Sep 2021, 00:43
this project lives on

@AHK_user is doing amazing work, and now has write access to the repository, so he can update the converter directly himself
Thanks,The power of the repository in the palm of my hand!!! :lol: :lol: :lol:

At the moment I started testing more in detail for the code and adding more and more tests to verify the conversion.
Currently still finding errors in it.

If I am satisfied with the result and fail to find errors, I will ask forum members to use it to find more failed conversions that can be fixed.

But it is getting better and better.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 114 guests