Jump to content

Autoit not working properly :(


bovanshi
 Share

Recommended Posts

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

Thanks

papercut.au3

Link to comment
Share on other sites

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 by ShawnW
Link to comment
Share on other sites

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 by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

  • Moderators

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 / $x

Hardly 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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 by bovanshi
Link to comment
Share on other sites

  • Moderators

wakillon,

Do not tell me - tell him! ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

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

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

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 by bovanshi
Link to comment
Share on other sites

@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 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

Link to comment
Share on other sites

  • Moderators

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 6

Then 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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...