Jump to content

Recommended Posts

Posted

Below is some code that I am having a problem with.

I had the Select statment inside of the readini()(formatted like: readini($Loc) and it gave me the correct responses. So for fewer lines I decided to take it out and run SelectINI before ReadINI are these formatted bad?

This is in the .ini file:

[LABEL NAMES]

S1=Aiag-Non-GM.lbl

S2=GM.lbl

$Loc = 1
SelectINI($Loc,$Sector,$Key)
Readini($Sector,$Key)
$input = InputBox("Label Creation","Please input address label you would like to use:"&@CR& $list2,"0","",300,($counter*15)+150)


Func SelectINI($Loc,$Sector,$Key)
  Select
    Case $Loc = 1
      $Sector = "LABEL NAMES"
      $Key = "S"
    Case $Loc = 2
      $Sector = "Printer Paths"
      $Key = "P"
  EndSelect
EndFunc

func readini($Sector,$Key)
  $list=""
  $list2=@crlf
  $counter=0
  $badnum="|"
  For $i= 1 to 200
    $line = IniRead ( $File, $Sector, $Key & $i, "Error" )
    if $line="Error" then continueloop
    $list=$list & $line & @cr
    $list2=$list2 &$i &" - "& $line & @crlf
    $counter=$counter+1
    $badnum=$badnum & $i &"|" 
  next
endfunc
INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...
Posted

Your functions are not returning anything. If you want SelectINI to return $Sector and key then make them ByRef.

*** Matt @ MPCS

Posted

the other option is to Dim all your variables before hand, that way valuse changed will be global.

Dim $Loc

Dim $Sector

Dim $Key

Dim $line

Dim $list

Dim $list2

Dim $counter

Dim $badnum

Not that this is best, but an option

AutoIt3, the MACGYVER Pocket Knife for computers.

Guest Py7|-|[]/\/
Posted (edited)

If you declare all of them as global. Then you cannot reassign them:

This you cannont do if it is global:

Dim $hello =1

$Hello = 5

Edited by Py7|-|[]/\/
Posted

You are wrong, that works just fine. The global scope isn't what he was talking about. His source defined the variables in the scope of the module. Even if he had done as you are saying it would still work. Try it!

*** Matt @ MPCS

Posted

Dim $hello =1
$Hello = 5
msgbox(1,"See hello is 5",$hello)

Global doesn't make it a permanent value that you can't change, it only sets the scope.

The difference between Dim/Local/Global is the scope in which they are created:

Dim = Local scope if the variable name doesn't already exist globally (in which case it reuses the global variable!)

Global = Forces creation of the variable in the Global scope

Local = Forces creation of the variable in the Local/Function scope

When using variables the local scope is checked first and then the global scope second.

AutoIt3, the MACGYVER Pocket Knife for computers.

Guest Py7|-|[]/\/
Posted

Sorry for my mistake! I am very used to global with Java. EX:

final int x = 123;

x = 5; <-- error cannot reassign a constant

Posted (edited)

That only doesn't work in java because you defined it as final not because it is global. I may be mistaken but Final is the same as const (or constant). It has nothing to do with the scope of the variable.

*** Matt @ MPCS

Edit: Fixed Typo

Edited by Matt @ MPCS
Guest Py7|-|[]/\/
Posted

You are right... But final is the equivalent of #define for C which is a global. I was therefore under the impression that final makes it a constant, otherwise known as a "global variable" which cannot be modified through a script except at its instantiation.

Posted

To avoid this I believe you can declare the variable as "public". Here is an example how to do it. Final variables may be defined in the "public" scope but they are not public variables, they are public constants.

*** Matt @ MPCS

Guest Py7|-|[]/\/
Posted

Thanks, but I already knew about public. There is also "private" declarations that can only be used in the method as well. I was under the impression that "Global" and "Final" were synonymous (spelling); but I suppose I was wrong. I stand corrected.

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
  • Recently Browsing   0 members

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