Elliotest

[Solved] I need my program create itself variable

15 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



#2 ·  Posted

You can use the Assign function in a loop :)

For $iVarNum = 1 To 10
    Assign("v" & $iVarNum, $iVarNum)
Next

 


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

#3 ·  Posted

Ok thank you I will give it a try :D

Share this post


Link to post
Share on other sites

#4 ·  Posted

Let me know if it works

1 person likes this

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

#5 ·  Posted

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

Share this post


Link to post
Share on other sites

#6 ·  Posted

Glad to know that my code works :). About your other question, 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


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

#7 ·  Posted

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

Share this post


Link to post
Share on other sites

#8 ·  Posted

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


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#9 ·  Posted

Sorry @Jos, I thought this forum followed the "one question per thread" policy. Again, many apologies


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

#10 ·  Posted

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


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#11 ·  Posted

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

Share this post


Link to post
Share on other sites

#12 ·  Posted

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


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#13 ·  Posted

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

 

Share this post


Link to post
Share on other sites

#14 ·  Posted

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


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#15 ·  Posted

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

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