Themabewertung:
  • 0 Bewertung(en) - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
Detecting a MuiCycle event and its selected option
#11
Excellent, glad it's working for you Smile It takes a little bit of getting used to, and often I was wondering if it was my code or a bug that stopped some things from working. Good luck with the rest of the project Smile
Zitieren
#12
Hi,

does anyone knows why, in the code below, the string gadgets objects 10,11 and 12 only accept the keys ipahlcC instead of numbers (0123456789) as it is supposed to?

Code:
WBStartup

Dim PageName$(2)

PageName$(0)="Function"
PageName$(1)="Scheme"

#CyTimerOscil=11
#CyOption=22

MUIApplicationTitle       "ChipCalc 555"
MUIApplicationVersion     "$VER: ChipCalc 555 0.1 (10.08.2015)"
MUIApplicationCopyright   "(c)2015 Carlos.D."
MUIApplicationAuthor      "Carlos D."
MUIApplicationDescription "555 calculator"
MUIApplicationBase        "CHIPCALC"

MUILabel 0,"    Chip 555 as ",#MUIO_Label_DoubleFrame
MUILabel 1,"    Calculate the",#MUIO_Label_DoubleFrame
MUICycle 2,"Timer","Oscilator"
MUICycle 3,"Resistor value","Capacitor value","Time periode"
MUICycle 4,"Resistor 1 value","Resistor 2 value","Frequency"

MUILabel 5,"  Resistor 1 in Ohms> ",#MUIO_Label_DoubleFrame
MUILabel 6,"  Capacitor  in  uF >    ",#MUIO_Label_DoubleFrame
MUILabel 7,"  Time periode in sec>",#MUIO_Label_DoubleFrame
MUILabel 8,"  Resistor 2 in Ohms> ",#MUIO_Label_DoubleFrame
MUILabel 9,"  Frequency in Hz>",#MUIO_Label_DoubleFrame

MUIString 10,"",9
MUISet 10,#MUIA_String_Accept,"0123456789"
MUIString 11,"",10
MUISet 11,#MUIA_String_Accept,"0123456789"
MUIString 12,"",6
MUISet 12,#MUIA_String_Accept,"0123456789"

MUIAddObjsHGroup 13,5,10  ;value of Resistor 1
MUICreateHGroup 13
MUIAddObjsHGroup 14,6,11  ;value of Capacitor
MUICreateHGroup 14
MUIAddObjsHGroup 15,7,12  ;Value of Time periode
MUICreateHGroup 15
MUIAddObjsHGroup 16,8,11  ;value of Resistor 2
MUIAddObjsHGroup 17,9,12  ;value of Frequency

MUIAddObjsHGroup 18,0,2   ;555 as timer / oscilator choice
MUICreateHGroup 18

MUIAddObjsHGroup 19,1,3   ;555 as timer
MUICreateHGroup 19
MUIAddObjsHGroup 20,1,4   ;555 as oscilator

MUIVSpace 21,20
MUIVSpace 22,5

MUIAddObjsVGroup 23,19,21,13,14,15  ;All group of Timer
MUIAddObjsVGroup 24,22,20,21,13,16,17  ;All group of Oscilator
MUICreateVGroup 23

MUIAddObjsPage 25,23
MUICreatePage 25,"Function","Scheme"

MUIMakeObject 26,#MUIO_HBar,20

MUIAddObjsVGroup 27,18,26,25
MUICreateVGroup 27

MUICreateWindow 28,"ChipCalc","PAGE",27
MUIAddSubWindow 28

If MUICreateApplication <> True Then End
MUINotifyApp 28,#MUIA_Window_CloseRequest,1,-11
MUINotifyApp 2,#MUIA_Cycle_Active,#MUIV_EveryTime,#CyTimerOscil
MUINotifyApp 3,#MUIA_Cycle_Active,#MUIV_EveryTime,#CyOption

success=MUIOpenWindow (28)

Repeat
  ev.l=MUIWaitEvent
  Select ev
    Case #CyTimerOscil
      cy2=MUIGetCycle (2)
      If cy2=0 Then Gosub _Timer
      If cy2=1 Then NPrint "Oscilator"
    Case #CyOption
      cy3=MUIGetCycle (3)
      Gosub _Timer
  End Select
Until ev=-11

MUICloseWindow 28

End

._Timer
    If cy3=0
      MUISet 10,#MUIA_Disabled,True
      MUISet 11,#MUIA_Disabled,False
      MUISet 12,#MUIA_Disabled,False

    EndIf
    If cy3=1
      MUISet 10,#MUIA_Disabled,False
      MUISet 11,#MUIA_Disabled,True
      MUISet 12,#MUIA_Disabled,False
;      cap$=MUIGetString$ (10)
      NPrint "Capacitor =",cap$
    EndIf
    If cy3=2
      MUISet 10,#MUIA_Disabled,False
      MUISet 11,#MUIA_Disabled,False
      MUISet 12,#MUIA_Disabled,True
    EndIf
Return
Zitieren
#13
It is because you are using MUISet wrong. It it wants a taglist. String literals are not valid for pointers.
You could use GetGlobalStrAddr or this:
[ab3]numericKeys.s = "01234567879"
MUISet 10,#MUIA_String_Accept, &numericKeys[/ab3]
Should work. Have not tested it though. numbericKeys must be a global string to ensure its lifetime is until you free MUI.
Zitieren
#14
I can confirm that this is the problem - it used to work the way you had it (although that might have been just an accident), but in recent versions it needs a pointer to the string. I used the new command GetGlobalStrAddr instead to fix it:
[ab3]MUISet 10, #MUIA_String_Accept, GetGlobalStrAddr("0123456789")[/ab3]
But this needs the latest snapshot of AmiBlitz as the command has been added since the 3.6.1 release was put together. Otherwise, Der Wanderer's solution will work in older versions too.
Zitieren
#15
Der Wanderer schrieb:It is because you are using MUISet wrong. It it wants a taglist.

@Der Wanderer
Thanks Der Wanderer, Dont know why I didn´t see that MUISet needed a taglist, maybe because, in my code it still accept the introduction of some few letters and maybe because the MUISet command also accept attributes. Also, all examples I had seen are from C.

Daedalus schrieb:I used the new command GetGlobalStrAddr instead to fix it:
[ab3]MUISet 10, #MUIA_String_Accept, GetGlobalStrAddr("0123456789")[/ab3]
But this needs the latest snapshot of AmiBlitz as the command has been added since the 3.6.1 release was put together.

@Daedalus
For now will use Der Wanderer solution because in my computer at work, where sometimes I use AmiBlitz too, still have version 3.5 but will update soon. Thanks for your solution, didn´t know about GetGlobalStrAddr..
Zitieren
#16
AlfaRomeo schrieb:maybe because, in my code it still accept the introduction of some few letters

Yeah, what's happening is that MUI is looking at a "string" in the address pointed to by your string, which is really a temporary buffer - effectively it will be random bytes, so by chance there are some bytes that are allowed. You might find that the accepted characters change over time, depending on what else your program does. I had the same problem with some old code of mine that worked fine with earlier versions of the compiler, but the characters it did allow were different to yours.

The reason MUISet accepts a string without giving an error is that it doesn't know what the object you're setting is going to use the parameter for. Giving a string makes it pass a pointer to a temporary string buffer, some objects might make a copy of that string which is fine, but others just access it directly which is only ok until the buffer is used for something else, then it causes all sorts of strange problems.

The GetGlobalStrAddr() function actually exists in the older versions as Null(), but you shouldn't use that as it has been replaced by the Null keyword in the later versions, and your code won't compile when you upgrade AmiBlitz. So you're probably right to use Der Wanderer's solution for now.
Zitieren
#17
Daedalus schrieb:...effectively it will be random bytes, so by chance there are some bytes that are allowed. You might find that the accepted characters change over time, depending on what else your program does.
@Daedalus

I didn´t detected that the accepted characters changed because I´ve tried and modified the code in different ways over the time and in different days so I saw that it accepted some chars but didn´t figured that they are random.

Thanks for the explanation friend, now I know what happened Smile
Zitieren


Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste