Jump to content

[Solved] I need my program create itself variable


Recommended Posts

Hello, I saw some thread but it didn't help me. All I want to do is to make like $v1, $v2, $v3 automatically as for exemple I say I want 10 variables the program create 10 variables $v....

The Dim command didn't help me, I think it doesnt create $v1 $v2...

I tried this but don't work:

$i = 1
$nbrv = 10
Dim $v[1]
While $i <= $nbrv - 1
   $v[$i-1] = 0
   $i = $i + 1
   ReDim $v[$i]
WEnd

If you can help me it would be nice.

Thanks for future answers

 

EDIT: The command Assign ("v"$i,0) solved my problem

Edited by Elliotest
Link to post
Share on other sites

Ok, so, for your code, it works fine, I did this:

For $i = 1 To $nbrv+1
    Assign("v" & $i-1, 0)
 Next

Because I want to start at 0 :P

And now, I need to make a certain number of checkbox, I did:

For $i = 1 To $nbrv+1
   $b&$i-1 = GUICtrlCreateCheckbox("",10,(30+$i*20))
Next

But got error "Expected a "=" operator in assignment statement.:"

I already have done the GUICreate but for some reasons it won't initialize the variable...

Link to post
Share on other sites
  • Developers

I would not recomment using assign for this but use an Array variable to hold all Control handles., much cleaner!

 

2 minutes ago, TheDcoder said:

I recommend you to ask to MODs to split the thread with the question about GUI in the AutoIt GUI Help forum, only 1 question per 1 thread :D

Not sure where this comes from but no need to suggest that.

1 minute ago, Elliotest said:

 

If I just delete half of my message it will be fine ? :D

You're fine.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites
  • Developers

Guess I don't see the 2 topics in this single thread and only see one question.
Agree it's better to open a new thread when the question is totally separate, but not per see when they are related.

Jo

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites

So you are talking about for exemple $v[1] etc... ?

If it is this I already tested it but I really don't know how it works because for exemple I created something like this

$i = 1
Dim $b[1]
While $i <= $nbrv - 1
$b[$i-1] = GUICtrlCreateCheckbox("",10,(30+$i*20))
$i = $i + 1
ReDim $b[$i]
WEnd

But got value like 9 for $b[0] and 10 for $b[1] so it wont save their state in a ini file like I would want to...

Link to post
Share on other sites
  • Developers

I have troubles trying to intepret what you are trying to do.
What is the content of $nbrv?  
Why not Dim the array with the correct size in stead of doing a redim all the time?
Simply do a for...Next loop for the number of CheckBoxes you need to create to keep it simple.
What is the issue with the 9 and 10 as you likely have defined 8 other Controls before this? (Show the whole code so we understand what you are doing!)

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites

This is my code before I change the Dim for For:

#include <File.au3>
#include <FileConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <Array.au3>
$nbrv = 10
For $i = 1 To $nbrv+1
    Assign("v" & $i-1, 0)
 Next
Example()

Func Example()
$hGUI = GUICreate("Example", 1800, 900)
$idClose1 = GUICtrlCreateButton("Close", 1750,850)
$i = 1
Dim $b[1]
Dim $bs[1]
While $i <= $nbrv - 1
   $b[$i-1] = GUICtrlCreateCheckbox("",10,(30+$i*20))
   $bs[$i-1] = IniRead("C:\Users\Elliotest\Desktop\Config.txt","Section1","sec"&$i-1,"")
   $i = $i + 1
   ReDim $b[$i]
   ReDim $bs[$i]
WEnd
GUISetState(@SW_SHOW, $hGUI)
    $idMsg = GUIGetMsg()
    $i = 1
    Dim $v[1]
    While ($idMsg <> $GUI_EVENT_CLOSE) And ($idMsg <> $idClose1)
       If GUICtrlRead($b&$i-1) = $GUI_CHECKED Then $v[$i-1] = 2
          $i = $i + 1
          ReDim $v[$i]
          If $i > $nbrv Then $i = 0
          $idMsg = GUIGetMsg()
     WEnd
$i = 1
While $i <= $nbrv - 1
$bs[$i-1] = GUICtrlRead($b&$i-1)
IniWrite("C:\Users\Elliotest\Desktop\Config.txt","Section1","sec"&$i-1,$bs[$i-1])
   $i = $i + 1
   ReDim $b[$i]
   ReDim $bs[$i]
WEnd
    GUIDelete($hGUI)
    $hGUIClosed = 1
 EndFunc

 

Link to post
Share on other sites
  • Developers

Here is a re-worked version of your script (untested) to give you an idea how I would do this:

#include <File.au3>
#include <FileConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <Array.au3>
Global $nbrv = 10
Global $b[$nbrv]
Global $bs[$nbrv]
Example()

Func Example()
    $hGUI = GUICreate("Example", 1800, 900)
    $idClose1 = GUICtrlCreateButton("Close", 1750, 850)
    $i = 1
    Dim $b[1]
    Dim $bs[1]
    For $i = 0 to $nbrv-1
        $b[$i] = GUICtrlCreateCheckbox("", 10, (30 + $i * 20))
        $bs[$i] = IniRead("C:\Users\Elliotest\Desktop\Config.txt", "Section1", "sec" & $i - 1, "")
    Next
    GUISetState(@SW_SHOW, $hGUI)
    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idClose1
                ExitLoop
        EndSwitch
        For $i = 0 to $nbrv-1
            if $b[$i] = $msg Then
                if GUICtrlRead($b[$i]) = $GUI_CHECKED Then
                ; don't understand what you want to do when the checkbox is clinked
                EndIf
            EndIf
        Next
    Wend
    GUIDelete($hGUI)
    $hGUIClosed = 1
EndFunc   ;==>Example

You still have to add the code to perform when a checkbox is checked/un-checked.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to post
Share on other sites

Thanks for the help, but now it doesn't work, I just want the checkboxes states to be saved in a ini file, I already managed to do this without those array things and did manually, but I need to do this with like I set $nbrv = 10 and then it creates 10 checkboxes, and save their states in a ini file.

Thanks again for your help :D

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

    No registered users viewing this page.

×
×
  • Create New...