Jump to content
Sign in to follow this  
AustrianOak

Dimming a variable with subscripts

Recommended Posts

AustrianOak

How do I Dim a variable like this:

Dim $font[2] = "20"

The reason I want to pre-define this variable is because if for some reason it doesn't get set in _ChooseFont() I want it already defined a default value.

When I do the above code I get an error saying "Missing subscript dimensions in Dim statement"

Can someone please help?

Edited by nowagain

Share this post


Link to post
Share on other sites
Dampe

You need to declare the variable as an Array first

Example:

Local $font[10]
Local $font[2] = "20"

Share this post


Link to post
Share on other sites
martin

How do I Dim a variable like this:

$font[2] = "20"

The reason I want to pre-define this variable is because if for some reason it doesn't get set in _ChooseFont() I want it already defined a default value.

When I do the above code I get an error saying "Missing subscript dimensions in Dim statement"

Can someone please help?

The error message doesn't correspond to the line you posted which is not a dim statement. If you want a certain value in _ChooseFont which differs from a default then you have to specify it as one of the parameters. Look up Dim in the help.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
martin

You need to declare the variable as an Array first

Example:

Local $font[10]
Local $font[2] = "20"
No.

Try running that.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
AustrianOak

If you want a certain value in _ChooseFont which differs from a default then you have to specify it as one of the parameters.

Yes, but what you must understand is that in my code _ChooseFont() is in a Case statement so the user my not even open it up to pick one so I'll have to declare it somehow.

This line of code

Local $font_attr[10]
Local $font_attr[2] = "9"

Gives me this error: Missing subscript dimensions in "Dim" statement

Edited by nowagain

Share this post


Link to post
Share on other sites
Richard Robertson

First of all, when you try

Local $font_attr[2] = "9"

or any of the other pieces of code that you built in that fashion, you are declaring an array and then overwriting the array with a string. It's not an array anymore. Well, technically there's an array somewhere in the internal workings, but it's not a variant array exposed to the script.

Share this post


Link to post
Share on other sites
martin

First of all, when you try

Local $font_attr[2] = "9"

or any of the other pieces of code that you built in that fashion, you are declaring an array and then overwriting the array with a string. It's not an array anymore. Well, technically there's an array somewhere in the internal workings, but it's not a variant array exposed to the script.

Quite.

You first declare the array and then it is created ready for values to be set in the elements as needed

Dim $font[20];create an an array with 20 elements

OR

Global $font[20]

OR

Local $font[20]

Once it has been declared you can set an element, but don't declare it again with different dimensions.

$fon[2] = "9" ;if it should be a string

$font[2] = 9 if it should be a number

If you want to declare an array and set the initial values at the same time then

Dim $aSomething[5] = [1,2,"abc",0,89];sets $aSomething[0] = 1, $aSomething[1] = 2..

It's all in the help!!


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
FreeFry

You're Dimensioning it the wrong way.

Should(could) be:

Dim $font[2] = ["20"]

You need to initialize the array like that if you want it to have values by default. :P

This does the same thing, but perhaps is a little more understandable for a beginner. :P

Dim $font[2]
$font[0] = "20"

As so, if you'd like to set the second element in the array to some value:

Dim $font[2] = ["20", "123"]

or in the more understandable way:

Dim $font[2]
$font[0] = "20"
$font[1] = "123"

Hope it makes sense. :o

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.