Skocz do zawartości

Dołącz do społeczności!

👋 Witaj na MPCForum!

Przeglądasz forum jako gość, co oznacza, że wiele świetnych funkcji jest jeszcze przed Tobą! 😎

  • ✅ Pełny dostęp do działów i ukrytych treści
  • ✅ Możliwość pisania i odpowiadania w tematach
  • ✅ System prywatnych wiadomości
  • ✅ Zbieranie reputacji i rozwijanie swojego profilu
  • ✅ Członkostwo w jednej z największych społeczności graczy

👉 Dołączenie zajmie Ci mniej niż minutę – a zyskasz znacznie więcej!

Zarejestruj się teraz

[Pytanie] Pętla While

Rekomendowane odpowiedzi

Opublikowano

Witam napisałem takie coś

 

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $Button1

$1 = 1

GUICtrlSetData($Input1,$1)

EndSwitch

WEnd

 

Tylko jak odpale program i naciśne $Button1 to wpisuje liczbę 1 ale jak już naciskam drugi raz na $Button1 to nie chce znowu wpisać liczby 1.

I moje pytanie jest takie jak zrobić żeby ciągle wpisywał liczbę 1 po naciśnięciu $Button1

Opublikowano
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
GUICtrlSetData($Input1,"1")
EndSwitch
WEnd

Nie wiem jak wygląda te Twoje GUI, ale sprawdź to :)

roomy.png

Wczoraj do ciebie nie należy. Jutro niepewne... Tylko dziś jest twoje.

Opublikowano
  • Autor

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Kalkulator By Marcin1310", 442, 141, 253, 203)
$Input1 = GUICtrlCreateInput("", 8, 8, 425, 21)
$Button1 = GUICtrlCreateButton("1", 8, 40, 75, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("2", 96, 40, 75, 25, $WS_GROUP)
$Button3 = GUICtrlCreateButton("3", 184, 40, 75, 25, $WS_GROUP)
$Button4 = GUICtrlCreateButton("4", 8, 72, 75, 25, $WS_GROUP)
$Button5 = GUICtrlCreateButton("5", 96, 72, 75, 25, $WS_GROUP)
$Button6 = GUICtrlCreateButton("6", 184, 72, 75, 25, $WS_GROUP)
$Button7 = GUICtrlCreateButton("7", 8, 104, 75, 25, $WS_GROUP)
$Button8 = GUICtrlCreateButton("8", 96, 104, 75, 25, $WS_GROUP)
$Button9 = GUICtrlCreateButton("9", 184, 104, 75, 25, $WS_GROUP)
$Button10 = GUICtrlCreateButton("+", 272, 40, 75, 25, $WS_GROUP)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
$Button11 = GUICtrlCreateButton("-", 360, 40, 75, 25, $WS_GROUP)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
$Button12 = GUICtrlCreateButton("*", 272, 72, 75, 25, $WS_GROUP)
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
$Button13 = GUICtrlCreateButton("/", 360, 72, 75, 25, $WS_GROUP)
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
$Button14 = GUICtrlCreateButton("INFO", 272, 104, 75, 25, $WS_GROUP)
$Button15 = GUICtrlCreateButton("EXIT", 360, 104, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

HotKeySet("{NUMPAD1}","a")
HotKeySet("{NUMPAD2}","b")
HotKeySet("{NUMPAD3}","c")
HotKeySet("{NUMPAD4}","d")
HotKeySet("{NUMPAD5}","e")
HotKeySet("{NUMPAD6}","f")
HotKeySet("{NUMPAD7}","g")
HotKeySet("{NUMPAD8}","h")
HotKeySet("{NUMPAD9}","i")
HotKeySet("{+}","j")
HotKeySet("{-}","k")
HotKeySet("{*}","l")
HotKeySet("{/}","m")
HotKeySet("{F1}","n")
HotKeySet("{End}","o")

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
	Case $GUI_EVENT_CLOSE
		Exit
	Case $Button1
		a()
	Case $Button2
		b()
	Case $Button3
		c()
	Case $Button4
		d()
	Case $Button5
		e()
	Case $Button6
		f()
	Case $Button7
		g()
	Case $Button8
		h()
	Case $Button9
		i()
	Case $Button10
		j()
	Case $Button11
		k()
	Case $Button12
		l()
	Case $Button13
		m()
	Case $Button14
		n()
	Case $Button15
		o()
EndSwitch
WEnd

Func a()
$1 = Send("1")
GUICtrlSetData($Input1,$1)
EndFunc

Func b()
$2 = 2
GUICtrlSetData($Input1,$2)
EndFunc

Func c()
$3 = 3
GUICtrlSetData($Input1,$3)
EndFunc

Func d()
$4 = 4
GUICtrlSetData($Input1,$4)
EndFunc

Func e()
$5 = 5
GUICtrlSetData($Input1,$5)
EndFunc

Func f()
$6 = 6
GUICtrlSetData($Input1,$6)
EndFunc

Func g()
$7 = 7
GUICtrlSetData($Input1,$7)
EndFunc

Func h()
$8 = 8
GUICtrlSetData($Input1,$8)
EndFunc

Func i()
$9 = 9
GUICtrlSetData($Input1,$9)
EndFunc

Func j()
$10 = "+"
GUICtrlSetData($Input1,$10)
EndFunc

Func k()
$11 = "-"
GUICtrlSetData($Input1,$11)
EndFunc

Func l()
$12 = "*"
GUICtrlSetData($Input1,$12)
EndFunc

Func m()
$13 = "/"
GUICtrlSetData($Input1,$13)
EndFunc

Func n()
MsgBox(64,"INFO","Dziękuje za skorzystanie z mojego programu")
EndFunc

Func o()
Exit
EndFunc

Opublikowano

A czaje :) Chcesz aby Ci dopisywało do aktualnych danych w inpucie to co klikniesz.

Po prostu będziesz musiał zmienić każdą funkcję na coś takiego:

Func a()
       $Read = GUICtrlRead($Input1)
       GUICtrlSetData($Input1,$Read&"1")
EndFunc

Ale to i tak nie będzie Ci liczyć :)

Musisz zastosować

GUICtrlRead(...)

I różne operacje na stringach by kalkulator fajnie funkcjonował. Takie coś jak Ty robisz (tzn. za co się zabierasz) nie jest takie proste jak się wydaje :P

 

@EDIT: już myślałem, że mi / nie działa a jednak zapomniałem wyłączyć Twój kalkulator - nad tym też popracuj i może ustaw hotkeye tylko na klawisze z klawiatury numerycznej :)

roomy.png

Wczoraj do ciebie nie należy. Jutro niepewne... Tylko dziś jest twoje.

Opublikowano

GUICtrlSetData ustawia wartość na taką jaką wpiszesz.

Zrób tak:

GUICtrlSetData($Input1,guictrlread($input1) & $1)

 

#EDIT

Ooo, spóźniłem się :(

Opublikowano

Troszkę zoptymalizowałem ten Twój programik:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Kalkulator By Marcin1310", 442, 141, 253, 203)
$Input1 = GUICtrlCreateInput("", 8, 8, 257, 21, BitOR($ES_AUTOHSCROLL,$ES_READONLY))
$Label1 = GUICtrlCreateLabel("=", 272, 8, 10, 17, BitOR($SS_CENTER,$SS_CENTERIMAGE))
$Input2 = GUICtrlCreateInput("", 288, 8, 145, 21, BitOR($ES_AUTOHSCROLL,$ES_READONLY))
$Button1 = GUICtrlCreateButton("1", 8, 40, 75, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("2", 96, 40, 75, 25, $WS_GROUP)
$Button3 = GUICtrlCreateButton("3", 184, 40, 75, 25, $WS_GROUP)
$Button4 = GUICtrlCreateButton("4", 8, 72, 75, 25, $WS_GROUP)
$Button5 = GUICtrlCreateButton("5", 96, 72, 75, 25, $WS_GROUP)
$Button6 = GUICtrlCreateButton("6", 184, 72, 75, 25, $WS_GROUP)
$Button7 = GUICtrlCreateButton("7", 8, 104, 75, 25, $WS_GROUP)
$Button8 = GUICtrlCreateButton("8", 96, 104, 75, 25, $WS_GROUP)
$Button9 = GUICtrlCreateButton("9", 184, 104, 75, 25, $WS_GROUP)
$Button10 = GUICtrlCreateButton("+", 272, 40, 75, 25, $WS_GROUP)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
$Button11 = GUICtrlCreateButton("-", 360, 40, 75, 25, $WS_GROUP)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
$Button12 = GUICtrlCreateButton("*", 272, 72, 75, 25, $WS_GROUP)
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
$Button13 = GUICtrlCreateButton("/", 360, 72, 75, 25, $WS_GROUP)
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
$Button14 = GUICtrlCreateButton("INFO", 272, 104, 75, 25, $WS_GROUP)
$Button15 = GUICtrlCreateButton("EXIT", 360, 104, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $Read
HotKeySet("{NUMPAD1}","a")
HotKeySet("{NUMPAD2}","b")
HotKeySet("{NUMPAD3}","c")
HotKeySet("{NUMPAD4}","d")
HotKeySet("{NUMPAD5}","e")
HotKeySet("{NUMPAD6}","f")
HotKeySet("{NUMPAD7}","g")
HotKeySet("{NUMPAD8}","h")
HotKeySet("{NUMPAD9}","i")
HotKeySet("{+}","j")
HotKeySet("{-}","k")
HotKeySet("{*}","l")
HotKeySet("{/}","m")
HotKeySet("{F1}","n")
HotKeySet("{End}","o")

While 1
       $nMsg = GUIGetMsg()
       Switch $nMsg
               Case $GUI_EVENT_CLOSE
                       Exit
               Case $Button1
                       a()
               Case $Button2
                       b()
               Case $Button3
                       c()
               Case $Button4
                       d()
               Case $Button5
                       e()
               Case $Button6
                       f()
               Case $Button7
                       g()
               Case $Button8
                       h()
               Case $Button9
                       i()
               Case $Button10
                       j()
               Case $Button11
                       k()
               Case $Button12
                       l()
               Case $Button13
                       m()
               Case $Button14
                       n()
               Case $Button15
                       o()
		EndSwitch
		$Read = GUICtrlRead($Input1)
WEnd

Func a()
       GUICtrlSetData($Input1,$Read&"1")
EndFunc

Func b()
       GUICtrlSetData($Input1,$Read&"2")
EndFunc

Func c()
       GUICtrlSetData($Input1,$Read&"3")
EndFunc

Func d()
       GUICtrlSetData($Input1,$Read&"4")
EndFunc

Func e()
       GUICtrlSetData($Input1,$Read&"5")
EndFunc

Func f()
       GUICtrlSetData($Input1,$Read&"6")
EndFunc

Func g()
       GUICtrlSetData($Input1,$Read&"7")
EndFunc

Func h()
       GUICtrlSetData($Input1,$Read&"8")
EndFunc

Func i()
       GUICtrlSetData($Input1,$Read&"9")
EndFunc

Func j()
       GUICtrlSetData($Input1,$Read&"+")
EndFunc

Func k()
       GUICtrlSetData($Input1,$Read&"-")
EndFunc

Func l()
       GUICtrlSetData($Input1,$Read&"*")
EndFunc

Func m()
       GUICtrlSetData($Input1,$Read&"/")
EndFunc

Func n()
       MsgBox(64,"INFO","Dziękuje za skorzystanie z mojego programu")
EndFunc

Func o()
       Exit
EndFunc

Zostało Ci tylko te stringi zrobić.

Czyli musisz udać się do helpa pod hasło:

String Management

Ale na tą chwilę podpowiem Ci, że bedziesz pracował głównie ze:

_StringBetween(...)
StringSplit(...)
StringReplace(...)

No i do tego musisz mieć dobrze opanowaną pętlę For.

 

@hfaua: Może i krócej, ale mi chodziło bardziej o 2 inputy - na obliczenia i wynik.

roomy.png

Wczoraj do ciebie nie należy. Jutro niepewne... Tylko dziś jest twoje.

Opublikowano

Nie lepiej tak?

 

$Form1 = GUICreate("Kalkulator By Marcin1310", 442, 141, 253, 203)
$Input1 = GUICtrlCreateInput("", 8, 8, 425, 21)
$Button1 = GUICtrlCreateButton("1", 8, 40, 75, 25)
$Button2 = GUICtrlCreateButton("2", 96, 40, 75, 25)
$Button3 = GUICtrlCreateButton("3", 184, 40, 75, 25)
$Button4 = GUICtrlCreateButton("4", 8, 72, 75, 25)
$Button5 = GUICtrlCreateButton("5", 96, 72, 75, 25)
$Button6 = GUICtrlCreateButton("6", 184, 72, 75, 25)
$Button7 = GUICtrlCreateButton("7", 8, 104, 75, 25)
$Button8 = GUICtrlCreateButton("8", 96, 104, 75, 25)
$Button9 = GUICtrlCreateButton("9", 184, 104, 75, 25)
$Button10 = GUICtrlCreateButton("+", 272, 40, 75, 25)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
$Button11 = GUICtrlCreateButton("-", 360, 40, 75, 25)
GUICtrlSetFont(-1, 20, 400, 0, "MS Sans Serif")
$Button12 = GUICtrlCreateButton("*", 272, 72, 75, 25)
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
$Button13 = GUICtrlCreateButton("/", 360, 72, 75, 25)
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
$Button14 = GUICtrlCreateButton("INFO", 272, 104, 75, 25)
$Button15 = GUICtrlCreateButton("EXIT", 360, 104, 75, 25)
GUISetState()

While 1
$nMsg = GUIGetMsg()
Select
	Case $nMsg = -3
		Exit
	Case $nMsg >= $Button1 And $nMsg <= $Button13
		a($nMsg)
EndSelect
WEnd

Func a($msg)
GUICtrlSetData($Input1, GUICtrlRead($Input1) & GUICtrlRead($msg))
EndFunc

Func n()
MsgBox(64, "INFO", "Dziękuje za skorzystanie z mojego programu")
EndFunc   ;==>n

Func o()
Exit
EndFunc   ;==>o

 

Ostatnio przeglądający 0

  • Brak zarejestrowanych użytkowników przeglądających tę stronę.

Konto

Nawigacja

Skonfiguruj powiadomienia push w przeglądarce

Chrome (Android)
  1. Stuknij ikonę kłódki obok paska adresu.
  2. Stuknij Uprawnienia → Powiadomienia.
  3. Dostosuj swoje ustawienie.
Chrome (Komputer)
  1. Kliknij ikonę kłódki na pasku adresu.
  2. Wybierz Ustawienia witryny.
  3. Znajdź Powiadomienia i dostosuj swoje ustawienie.