bovanshi Posted September 6, 2010 Share Posted September 6, 2010 I can't find what is wrong with my code.. this single line of code is not working(51,9): $iwidth = 1969 $xseg = 103.404 $x = 21 $whidth = $iwidth / $xseg * $x this sets $width to 0 What my program does is taking the properties of an image and outputting the coordinates of cuts to make in the image to fit it to several A4 papers according to the users setting(printing an image spanning several sheets of paper and creating a very large printed image). Any idea on how to fix this?? os: win7 x64 Thankspapercut.au3 Link to comment Share on other sites More sharing options...
wakillon Posted September 6, 2010 Share Posted September 6, 2010 It works ! $whidth : 399.878147847279 +>16:13:07 AutoIT3.exe ended.rc:0 +>16:13:08 AutoIt3Wrapper Finished >Exit code: 0 Time: 1.532 AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
bovanshi Posted September 6, 2010 Author Share Posted September 6, 2010 Then it must me by system that is not working :S It sets $width to 0 Link to comment Share on other sites More sharing options...
ShawnW Posted September 6, 2010 Share Posted September 6, 2010 (edited) You need some debug steps, in your code you don't use literals for $xseg and $iwidth, they are calculated and that must be where the error is. Try outputing them either to the console or in a message box before they are used to see if you are getting the expected results. Edit: Or it could be that you just meant to type $width rather than $whidth Shawn Edited September 6, 2010 by ShawnW Link to comment Share on other sites More sharing options...
wakillon Posted September 6, 2010 Share Posted September 6, 2010 (edited) Then it must me by system that is not working :S It sets $width to 0 try #include <extprop.au3> #include <Array.au3> $filename = FileOpenDialog("PaperCut - Open file",@DesktopDir,"All (*.*)") Global $array[3] $array[1] = _GetExtProperty($filename,31) $array[2] = _GetExtProperty($filename,32) _ArrayDisplay ( $array ) $iwidth = $array[1] $iheight = $array[2] Edited September 6, 2010 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 6, 2010 Moderators Share Posted September 6, 2010 bovanshi ,Welcome to the AutoIt forum. Rather than blaming Autoit for the error, maybe you should look at your spelling..... $whidth = $iwidth / $xseg * $x$dpi = $iheight / $height * 2.54$xpaper = $width / $xHardly surprising that $width contains 0 when you have only set $whidth.A couple of suggestions:- Try to set more descriptive variable names.- Try adding Opt("MustDeclareVars", 1) at the top of your script. it helps avoid simple errors like this.Good luck with the script. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
wakillon Posted September 6, 2010 Share Posted September 6, 2010 @Melba I think it's his stringsplit who doesn't work at the beginning of his script because _GetExtProperty return 1 value, not 2 ! AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
bovanshi Posted September 6, 2010 Author Share Posted September 6, 2010 (edited) try #include <extprop.au3> #include <Array.au3> $filename = FileOpenDialog("PaperCut - Open file",@DesktopDir,"All (*.*)") dim $array[3] $array[1] = _GetExtProperty($filename,31) $array[2] = _GetExtProperty($filename,32) _ArrayDisplay ( $array ) $iwidth = $array[1] $iheight = $array[2] The array is: [0]| [1]|1969 x 1231 [2]|0 I did some debugging and it was clear that it just did not want to do the $width = $iwidth / $xseg * $x operation I put Msgbox functions around it to check values.. even divided the steps. Edit: the output of the _GetExtProperty is in the form "1969 x 1231". Thus the need of string split. Edited September 6, 2010 by bovanshi Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 6, 2010 Moderators Share Posted September 6, 2010 wakillon, Do not tell me - tell him! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
wakillon Posted September 6, 2010 Share Posted September 6, 2010 It give me : [0]|1 [1]|1680 pixels AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
bovanshi Posted September 6, 2010 Author Share Posted September 6, 2010 (edited) I don't understand. What is wrong? The $width equals 1969 and $height = 1231... I think this worked before... The only thing I can't get to work is $width = $iwidth / $xseg * $x :-/ Edited September 6, 2010 by bovanshi Link to comment Share on other sites More sharing options...
wakillon Posted September 6, 2010 Share Posted September 6, 2010 (edited) When i try like this Global $array[3] $array[1] = _GetExtProperty($filename,31) $array[2] = _GetExtProperty($filename,32) _ArrayDisplay ( $array ) $iwidth = Number ( StringReplace ( $array[1], 'pixels', '' ) ) $iheight = Number ( StringReplace ( $array[2], 'pixels', '' ) ) MsgBox(1,"", $iwidth & " X " & $iheight ) It give me 1680 X 1050 Edited September 6, 2010 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
wakillon Posted September 6, 2010 Share Posted September 6, 2010 I know why it give me different results ! Because extprop.au3 doesn't give same result for xp user and the others. I' m on xp and i suppose not you ? AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
bovanshi Posted September 6, 2010 Author Share Posted September 6, 2010 Thanks for the help, but I can't seem to make this work. It seems that it indeed is where I set the dimensions of the image the fault lies. I entered the values manually and it worked. The strange thing is I checked the values that were returned from the array and string splitting and whatnot and they were exactly the same as if I entered them manually.. Is this a bug? I first made a msgbox pop up after the resolution was set to the array and then entered exactly the same values manually through input boxes and it worked. Then I commented out the input boxes and it didn't work. #include <extprop.au3> $filename = FileOpenDialog("PaperCut - Open file",@DesktopDir,"All (*.*)") $array = StringSplit(_GetExtProperty($filename,31), ' x ', 1) $iwhidth = $array[1] $iheight = $array[2] MsgBox(1,"Papercut",$iwhidth & "<<>>" & $iheight) ;$iwhidth = InputBox("Papercut", "Input image Whidth:") ;$iheight = InputBox("Papercut", "Input image Height:") MsgBox(1,"Papercut",$iwhidth & "<<>>" & $iheight) The msgboxes both prints: "1969<<>>1231" Link to comment Share on other sites More sharing options...
bovanshi Posted September 6, 2010 Author Share Posted September 6, 2010 I know why it give me different results !Because extprop.au3 doesn't give same result for xp user and the others.I' m on xp and i suppose not you ?Precisely. I knew this but I somehow forgot to mention it, sorry. Guess I were focused on the problem. So this should only work properly on win7 (maybe vista too). Link to comment Share on other sites More sharing options...
wakillon Posted September 6, 2010 Share Posted September 6, 2010 Try this $iwhidth = Number ( $array[1] ) ConsoleWrite ( "$iwhidth : " & $iwhidth & @Crlf ) $iheight = Number ( $array[2] ) ConsoleWrite ( "$iheight : " & $iheight & @Crlf ) AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
bovanshi Posted September 6, 2010 Author Share Posted September 6, 2010 (edited) Try this $iwhidth = Number ( $array[1] ) ConsoleWrite ( "$iwhidth : " & $iwhidth & @Crlf ) $iheight = Number ( $array[2] ) ConsoleWrite ( "$iheight : " & $iheight & @Crlf ) The result is: $iwhidth : 0 $iheight : 1231 The message boxes display the right resolution for the image though :S Edit: tested converting to number in msgbox to, displayed whidth = 0. Problem with conversion? Might be treating the $iwhidth as beginning with a non-numeric char or even as a string. Edited September 6, 2010 by bovanshi Link to comment Share on other sites More sharing options...
BrewManNH Posted September 6, 2010 Share Posted September 6, 2010 @bovanshi As Melba23 said several posts back, you are misspelling your width variable as whidth in some of your examples and also spelling it as width elsewhere. You are probably getting the right results, you're just referencing them incorrectly with the wrong variable names. Start there before you try and troubleshoot ANYTHING else. Post a working(non-working) example of your code so that we can see what it is that you have EXACTLY that way we can stop chasing our tails around and figure out if it's the function that is wrong or your spelling. 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 GudeHow 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 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 6, 2010 Moderators Share Posted September 6, 2010 BrewManNH,Thank you for that. I do wish people would read what is posted and sort out the simple things in their scripts before claiming AutoIt does not work. Top Tip to all readers: Use the full version of SciTE4AutoIt3 (downloadable from here) and put this line at the top of your script:#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6Then run Tidy (Ctrl-T or <Tools - Tidy Autoit source>)Do not post your code asking for help until you have no errors left. Our lives would then be much simpler! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
bovanshi Posted September 6, 2010 Author Share Posted September 6, 2010 Sorry. Here's the current version which works when the resolution is set manually by input boxes but not with the number conversion made sure there are only "width" in the code now too.papercut.au3 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now