newb_powa' Posted September 27, 2006 Share Posted September 27, 2006 Is there a way to get two or more varible from one. There follow an exemple: $var = 18 ;what i want to do is getting this var into something like this $var[1] = 1 $var[2] = 8 ;and in more complicated it should look like that $numberofvar = 0 $var = 10384 $var[$numberofvar + 1] = 1 $var[$numberofvar + 1] = 0 $var[$numberofvar + 1] = 3 $var[$numberofvar + 1] = 8 $var[$numberofvar + 1] = 4 ;the end of my exemple I want to know if there is an existing function that can do that, is there isn't i will try to do that by myself, whit a lot of guessing, any ideo on how to do that ?? Link to comment Share on other sites More sharing options...
Skruge Posted September 27, 2006 Share Posted September 27, 2006 Try this:$array = StringSplit(String($var), "") [font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font] Link to comment Share on other sites More sharing options...
newb_powa' Posted September 27, 2006 Author Share Posted September 27, 2006 Thank you for fast reply, i will work on that Link to comment Share on other sites More sharing options...
pecloe Posted September 27, 2006 Share Posted September 27, 2006 more complicated Dim $var[1] $STR = 654321 For $x = 0 To StringLen($str) - 1 $var[$x] = StringMid ( $str, $x , 1) _ArrayAdd($var, 1) Next _ArrayDisplay($var, "") Link to comment Share on other sites More sharing options...
newb_powa' Posted September 27, 2006 Author Share Posted September 27, 2006 (edited) Thanks, your right, it's a lot more complicated, i'm not sur i will need it for the moment but i will try to understand this code, it's not a lot of code but it's too much hard for me lol I used this to make a little program working as a chronos. There is my code expandcollapse popup#include <GuiConstants.au3> Global $Hours = 0, $Mins = 0, $Secs = 0, $Hours2 = 0, $Mins2 = 0, $Secs2 = 0 While 1 ; === Create Gui === If WinExists("Beeper") Then ;;; Else GuiCreate("Beeper", 151, 81,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW,$WS_POPUPWINDOW),$WS_EX_TOOLWINDOW ) WinMove("Beeper","", 868, 665) WinSetOnTop("Beeper", "", 1) $Label_1 = GuiCtrlCreateLabel("Time until the BEEP:", 10, 10, 130, 20) $Label_2 = GuiCtrlCreateLabel($Hours&$Hours2 & ":" & $Mins&$Mins2 & ":" & $Secs&$Secs2, 95, 34, 60, 20) $Input_1 = GuiCtrlCreateInput("Hrs", 10, 30, 25, 20, $ES_NUMBER) $Input_2 = GuiCtrlCreateInput("Min", 37, 30, 25, 20, $ES_NUMBER) $Input_3 = GuiCtrlCreateInput("Sec", 64, 30, 25, 20, $ES_NUMBER) $ok = GUICtrlCreateButton("&OK", 10, 55, 60, 20) $stop = GUICtrlCreateButton("&Stop", 80, 55, 60, 20) GuiSetState() EndIf While 2 $msg = GuiGetMsg() Select Case $msg = $ok ; === Variable for the timer === ;=============================== $Input1 = GUICtrlRead($Input_1) $Input1 = StringSplit($Input1,"") $Input1[1] = $Hours $Input1[2] = $Hours2 ;=============================== $Input2 = GUICtrlRead($Input_2) $Input2 = StringSplit($Input2,"") $Input2[1] = $Mins $Input2[2] = $Mins2 ;=============================== $Input3 = GUICtrlRead($Input_3) $Input3 = StringSplit($Input3,"") $Input3[1] = $Secs $Input3[2] = $Secs2 ;=============================== ; === Loop === Do GUISetState() $Secs2 = $Secs2 - 1 GUICtrlSetData ( $Label_2, $Hours&$Hours2 & ":" & $Mins&$Mins2 & ":" & $Secs&$Secs2 ) Sleep(1000) If $Secs2 = 0 And $Secs > 0 Then $Secs2 = 9 $Secs = $Secs - 1 EndIf If $Secs = 0 And $Secs2 = 0 And $Mins2 > 0 Then $Secs = 5 $Secs2 = 9 $Mins2 = $Mins2 - 1 EndIf If $Mins2 = 0 And $Mins > 0 Then $Mins2 = 9 $Mins = $Mins - 1 EndIf If $Mins = 0 And $Mins2 = 0 And $Hours2 > 0 Then $Mins = 5 $Mins2 = 9 $Hours2 = $Hours2 - 1 EndIf If $Hours2 = 0 And $Hours > 0 Then $Hours2 = 9 $Hours = $Hours - 1 EndIf Until $Hours=0 And $Hours2=0 And $Mins=0 And $Mins2=0 And $Secs=0 And $Secs2=0 ; === The BEEP === Beep(600, 150) Sleep(50) Beep(600, 150) Sleep(50) Beep(600, 150) GUISetState() ; === Other Button [In Work] === Case $msg = $GUI_EVENT_CLOSE WinSetState("Beeper","",@SW_HIDE) Case $msg = $stop $Hours = 00 $Mins = 00 $Secs = 00 ExitLoop EndSelect WEnd WEnd I think it should work ... But i get some error cause of the stringsplit wich is the thing that i still don't know how to use properly i think... There is an other problem too ... Because there is a "sleep(1000)" in my loop ... when i press a button i don't work all of the time ... But first i want to understand my error with the StringSplit, if anyone could explain ... Thank you guys for your help Edit : I know for the if statement ... they aren't working for now, i will do that too ... Edited September 27, 2006 by newb_powa' Link to comment Share on other sites More sharing options...
Skruge Posted September 27, 2006 Share Posted September 27, 2006 more complicated Dim $var[1] $STR = 654321 For $x = 0 To StringLen($str) - 1 $var[$x] = StringMid ( $str, $x , 1) _ArrayAdd($var, 1) Next _ArrayDisplay($var, "")Indeed, it's more complicated. It also sets the last element to 1, regardless of what's in the original variable. Instead of _ArrayAdd'ing 1, you could re-dim the array to the right size before the loop. [font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font] Link to comment Share on other sites More sharing options...
Skruge Posted September 27, 2006 Share Posted September 27, 2006 I think it should work ... But i get some error cause of the stringsplit wich is the thing that i still don't know how to use properly i think...There is an other problem too ... Because there is a "sleep(1000)" in my loop ... when i press a button i don't work all of the time ... But first i want to understand my error with the StringSplit, if anyone could explain ...Thank you guys for your helpOk, several problems...You have two while loops, the first of which never ends. (I realize it's a work in progress, but this kind of thing can really get in the way of debugging.)StringSplit returns only a two-element array if the number is only a single digit. You either need to check for multiple digits, or handle it differently. I don't see anywhere in your code where you really need each digit in a separate variable. You could keep $Hours, $Mins, & $Secs as individual variables, yet display them as two-digit numbers using StringFormat("%02d", $Hours).Same deal with the math... much better using individual variables.The one-second sleep is what's slowing down the GUI response. You can get around this using a timer. I'll dig up some examples.Don't give up! [font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font] Link to comment Share on other sites More sharing options...
newb_powa' Posted September 27, 2006 Author Share Posted September 27, 2006 (edited) I have a version with only 3 var and wich one work pretty good, no error... I only want to use sting split for inan estetic way, and for my personnal learning too. If i only put $secs without the second var it will look like that: 0:45:9 0:8:51 My clock was working, i'm only doing an update if u want ... it will look like that 00:45:09 00:08:51 This is much more easy to read, i think I wish u understand me, sorry for bad english, i'm a lil' french man Edit : For the loop ... It's because I will do some other thing ... The timer is only my first step (do we say that?) there will be some other feature later Edited September 27, 2006 by newb_powa' Link to comment Share on other sites More sharing options...
newb_powa' Posted October 1, 2006 Author Share Posted October 1, 2006 (edited) Ok, I look at this yesterday and I change some little thing Now is it pretty good working expandcollapse popup#include <GuiConstants.au3> Global $Hours = 00, $Mins = 00, $Secs = 00, $zeroh = "", $zerom = "", $zeros = "" If $Hours < 10 Then $zeroh = 0 EndIf If $Mins < 10 Then $zerom = 0 EndIf If $Secs < 10 Then $zeros = 0 EndIf If $Hours > 10 Then $zeroh = "" EndIf If $Mins > 10 Then $zerom = "" EndIf If $Secs > 10 Then $zeros = "" EndIf While 1 ; === Create Gui === If WinExists("Beeper") Then ;;; Else GuiCreate("Beeper", 151, 81,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW,$WS_POPUPWINDOW),$WS_EX_TOOLWINDOW ) WinMove("Beeper","", 868, 665) WinSetOnTop("Beeper", "", 1) $Label_1 = GuiCtrlCreateLabel("Time until the BEEP:", 10, 10, 130, 20) $Label_2 = GuiCtrlCreateLabel($zeroh & $Hours & ":" & $zerom & $Mins & ":" & $zeros & $Secs, 95, 34, 60, 20) $Input_1 = GuiCtrlCreateInput("Hrs", 10, 30, 25, 20, $ES_NUMBER) $Input_2 = GuiCtrlCreateInput("Min", 37, 30, 25, 20, $ES_NUMBER) $Input_3 = GuiCtrlCreateInput("Sec", 64, 30, 25, 20, $ES_NUMBER) $ok = GUICtrlCreateButton("&OK", 10, 55, 60, 20) $stop = GUICtrlCreateButton("&Stop", 80, 55, 60, 20) GuiSetState() EndIf While 2 $msg = GuiGetMsg() Select Case $msg = $ok ; === Variable for the timer === ;=============================== $Input1 = GUICtrlRead($Input_1) If $input1 = "" Then $input1 = 0 EndIf If $input1 = "Hrs" Then $input1 = 0 EndIf $Hours = $Input1 ;=============================== $Input2 = GUICtrlRead($Input_2) If $input2 = "" Then $input2 = 0 EndIf If $input2 = "Min" Then $input2 = 0 EndIf $Mins = $Input2 ;=============================== $Input3 = GUICtrlRead($Input_3) If $input3 = "" Then $input3 = 1 EndIf If $input3 = "Sec" Then $input3 = 1 EndIf $Secs = $Input3 ;=============================== ; === Loop === Do GUISetState() $Secs = $Secs - 1 GUICtrlSetData ( $Label_2, $zeroh & $Hours & ":" & $zerom & $Mins & ":" & $zeros & $Secs ) Sleep(1000) If $Hours < 9 Then $zeroh = 0 EndIf If $Mins < 9 Then $zerom = 0 EndIf If $Secs < 9 Then $zeros = 0 EndIf If $Hours > 9 Then $zeroh = "" EndIf If $Mins > 9 Then $zerom = "" EndIf If $Secs > 9 Then $zeros = "" EndIf If $Secs = 0 And $Mins > 0 Then $Secs = 60 $Mins = $Mins - 1 EndIf If $Mins = 0 And $Hours > 0 Then $Mins = 60 $Hours = $Hours - 1 EndIf If $Secs > 60 Then $Secs = 60 If $Mins > 60 Then $Mins = 60 If $Hours > 60 Then $Hours = 60 Until $Hours=0 And $Mins=0 And $Secs=0 ; === The BEEP === GUISetState() Beep(600, 150) Sleep(50) Beep(600, 150) Sleep(50) Beep(600, 150) ; === Other Button === Case $msg = $GUI_EVENT_CLOSE WinSetState("Beeper","",@SW_HIDE) Case $msg = $stop $Hours = 00 $Mins = 00 $Secs = 00 ExitLoop EndSelect WEnd WEnd But I still need help with the stop button ... Because of the sleep in my loop it slow the button reaction. I thought of something like that It is that Sleep(1000) I will try something like that _Sleep Func _Sleep() $x = 0 Do $x = $x + 1 Sleep(10) Until $x = 100 Endfunc Do you think it will work ? i didn't test it Edit : I test it and it don't work, any idea on what should i do ? Edited October 1, 2006 by newb_powa' Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now