Calculator help?
Blitz3D Forums/Blitz3D Beginners Area/Calculator help?
| ||
Hi all. I'm having a slight problem getting the numbers on my calculator (which i simulated w/ text instead of a button) to look like this: 1 2 3 4 5 6 7 8 9 0 * / + - ^ etc.. i can position them correctly in all graphics modes, but i cant split them into rows of 3. code: thanks! yes it's 3d, because i plan to add 3d support to it soon. |
| ||
Your X Spacing is currently:((percentwidth * width) + (spacingwidth# * width * x) + (origx#) + (pos_x#) )-StringWidth(buttons$(y))+5 Really seems pretty complicated. Maybe you could sort out some of the formatting into functions so you're left with a simpler imx=MyFunction(x) or something? |
| ||
I think the best approach, is to first define a unit size. unit% = GraphicsWidth() / 100 After that, base everything on this unit size, both object width/height and spaces. Ie: Button1Width = unit * 4 Button1Height = unit * 3 |
| ||
well the thing is. its not the size of the button i need. its the spacing inbetween the buttons. and i need to reorder them to look like this: 1 2 3 4 5 6 7 8 9 0 / * + - ^ |
| ||
besides. i just tried the unit thing. and that doesnt solve the problem of how the buttons are ordered. |
| ||
besides. i just tried the unit thing. and that doesnt solve the problem of how the buttons are ordered. Why doesnt it? Unless your buttons are all different sizes or something it should work fine... for n = 1 to TotalButtons x=n Mod 3 y=(n Shr 2)-n drawimage Button(n),x*width,y*height next f |
| ||
my code: |
| ||
I thik you're getting confused about how to incorporate some of the suggestions here. My advice is to go through your program, perhaps with a notepad or calculator handy, and try to see what's happening step-by-step. Blitz' built-in Debuglog and break points (Stop function) can be really handy for this. That way, you will be able to concentrate on one thing at a time (for example, getting the buttons to line up horizontally first, then work on the vertical.) Otherwise, you can easily make your code too messy with old bits of code and multiple declarations or variables with different relevances and 'meanings' throughout the code. I think part of the problem is the "0" key. Since according to computers, it is essentially the FIRST number, yet n real world calculators, 0 is separate from the 1 - 9 keys. Anyway, try this for starters and see how you get on: |
| ||
thats all fine, but for some reason when i compile it, the eight has weird text.. :S and another number. |
| ||
Ah yeah - That's 8 and 4 presumably "+" should be affected too. It's to do with (y / 4 ) giving real numbers at 4,6,12.... I think. |
| ||
i have NO idea what u just said. how can i change it to fix this? |
| ||
also, u got 0 backwards. lol, its supposed to go: 1 2 3 4 5 6 7 8 9 0 * / + - ^ not: 0 1 2 3 4 5 6 7 8 9 + * / - ^ |
| ||
|
| ||
malice, could u fix the numbers so i can learn the difference between the mess up and the fix? |
| ||
This should be cleaner :) If you use the values suggested by Warner above, you can position the numbers within the boxes drawn on screen. |
| ||
um. this made it WORSE. now ALL text is in the middle together... |
| ||
Check these lines... I I had edited shortly after posting, Const GHeight%=600, GWidth%=800 Graphics3D GWidth%,GHeight%,0,6 Function GetX(x%) Return (x% * (GWidth% * 0.01)*xspace%)+startX% End Function Function GetY(y%) Return (y%*(GHeight% * 0.01)*yspace%)+startY% End Function |
| ||
works perfect now. except for the numbers arent always in the middle. but its perfect other than that! ^^ |
| ||
You need to assign the values for StartX, StartY, xpace and yspace yourself. as well as the ratio to the Gheight and Gwidth. I have no idea how you want them set up ;) |
| ||
would the values of startx be startx=graphicswidth()/2-textwidth(buttons(n)) ? |
| ||
It's up to you where you want them positined. startX = number of pixels from the left of screen where the first digit is placed startY = numebr of pixels friom the top of screen where the uppermost digit is displayed xspace and yspace are the respective 'gaps' between digits horizontal (xsapace) and vertical (yspace). in the Get(x) and Get(y) functions, the GWidth*0.01 etc. scale the values of x and y according to the screen resolution. |
| ||
how would i set the text of the devilgui edit box, using a devilgui command? |
| ||
Local MyGadget.gad; This should be the gadget object type Local MyEditBox.GUI_Edit=MyGadget\GUI_Edit.GUI_Edit gad\txt$="blahblahblah" |
| ||
um, i used blitzbasic's, not blitzmax's here's what i have: it doesnt want to work.... |
| ||
That was in B3D code. Essentially it's the same thing, although you're code assumes that a message was passed to the UI system to change the test, while mine sets it before UI_UpdateWindow From the Devil UI code, I don't see any case control, so, using your code, you might wish to try with "settext" instead. Also, there's no return value on GUI_Message(), so the a= is useless. I assume you have created the edit and button gadgets? [code] Select GUI_AppEvent() Case btn1: GUI_Message(edt1, "settext", "1") Default: a=GUI_Message(edt1, "settext", "E") End Select |
| ||
didnt work. what i want to do is when the btn1 is clicked, i wanted it to return the value of that button to the edt1 box. |
| ||
ok. it worked ALMOST. i fgt. to global edt1. now the problem is if i click any button other than 0, and the math signs, it doesnt allow for multiple numbers of the same number. for example i click 1 twice, and i get "11". so here's the whole code: |
| ||
i really need it to work. ive worked so hard on it.. |
| ||
*sigh* i still cant figure out how to do this. |
| ||
Something like:Select GUI_AppEvent() Case btn1: GUI_Message(edt1, "settext", edt1\txt$+"1") Case btn2: GUI_Message(edt2, "settext", edt2\txt$+"2") Case btn3: GUI_Message(edt3, "settext", edt3\txt$+"3") ;... and so on... Default: GUI_Message(edt1, "settext", "E") End Select |
| ||
i still dont get it. plus. edt2, and so on should be edt1. im only using 1 input box |
| ||
Then it should just be something like:Case btn1: GUI_Message(edt1, "settext", edt1\txt$+"1") Case btn2: GUI_Message(edt1, "settext", edt1\txt$+"2") Case btn3: GUI_Message(edt1, "settext", edt1\txt$+"3") ; ...etc... It's not too hard to figure out, you might wanna read theough the Help / tutorials and learn hw the language syntax works. |
| ||
no. i know that. what im saying is where did the edt1\txt$ come from? what type do i use to use this? |
| ||
how do i make it allow more than 1 number if i clicked the button more than once? |
| ||
here's what i have: now. how can i make this allow for more than 1 number? |
| ||
You used Edt1 in your earlier post relating to DevilUI. I assumed that would be the edit box you were using... If not, change the Global Edt1 in here for your 'gad1' ;Globs Global fnt = LoadFont("Courier New", 20, True, False, False) Global cmbSkin, OldSkin$ = "WinXP" Global sld1, sld2, lblSld1, lblSld2 Global prg1, prg2, lblPrg1, lblPrg2 Global scr1, lblScr1, btnLst1, lst1 Global btnDlg1, btnDlg2, btnDlg3, btnDlg4 Global btn1,btn2,btn3,btn4,btn5,btn6,btn7,btn8,btn9,btn0 Global edt1 Global btnmult,btnplus,btnsubt,btndiv,btnpw Global lblFPS, lblEvent Your code would just set the multiple edit boxes to '1' if button 1 was pressed, regardless of how many times it is pressed,and nothing if any other buttons are pressed. Why do you need Each if you only have one edit box? You should only need one type object reference if there's only one object. Select GUI_AppEvent() Local g.gad1 = First gad1 Case btn1 GUI_Message(g, "settext", g/txt$+"1") Case btn2 GUI_Message(g, "settext", g/txt$+"2") Case btn3 GUI_Message(g, "settext", g/txt$+"3") Case btn4 GUI_Message(g, "settext", g/txt$+"4") ;...etc... Default:(g,"settext",g\txt$="E") End Select |
| ||
great, now im getting arithmetic operator cannot be applied to custom type objects. |
| ||
g/txt$ Should be g\txt$ sorry, fairly common typo that one! |
| ||
EDIT: now im getting object does not exist with GUI_Message() when i click the buttons 1,2,3, or 4. and yes, im using edt1 as the input box. |
| ||
Why are you now using g1, gad1 AND edt1 ????? Which is your edit box and why are you making new type objects each press???? Whichever one it is, just use the code I posted. No need for new instances and if you only have one edit box, you'll only need one type object. |
| ||
cuz the g variable was apparently used in another included file. so i changed the variable to g1. |
| ||
But why use edt1 again and create new type instances? I'm trying to help, but it's difficult unless you at least explain why you make other changes. |
| ||
my edit box is edt1. |
| ||
heres my code, its saying illegal type conversion. i dont know whether to use g1 in GUI_Message() as the 1st parameter, or edt1.. |
| ||
You sill have the line: edt1 = GUI_CreateEdit(grp1, 10, 190, 100, blah)???? If so then great. Just use edt1 Like I suggested way back.... Case btn1: GUI_Message(edt1, "settext", edt1\txt$+"1") Case btn2: GUI_Message(edt1, "settext", edt1\txt$+"2") Case btn3: GUI_Message(edt1, "settext", edt1\txt$+"3") ; ...etc... Default: GUI_Message(edt1,"settext",edt1\txt$="E") And if you DO change the types, make sure you change all the references throughout your code. |
| ||
i tried. heres the code, it didnt work.. |
| ||
this is so frusterating when something you want to make fails. can u explain how i can use edt1\txt$ as a type? this would help GREATLY if all numbers but 0 and the signs allows for more than 1 number |
| ||
anyone? :/ |
| ||
What is gad1? Is it declared and created? What 'doesn't work' about it? Does it not compile, crash, give an error or an unexpeced result? Post your entire code as it is so that it's possibe to see where you may be going wrong. Also, read up on Types so you yourself have a greater understanding of how they work. |
| ||
here's my whole code: code thats having a problem: edt1\txt$ is returning the error illegal type conversion. |
| ||
I still don't understand why you are using different objects. Make your mind up which you are using, and then ensure the fields are declared correctly. Look at these lines and see if you can figure out what is wrong: Type gad1 ; This should be the gadget object type Field txt$ End Type Global edt1 edt1 = GUI_CreateEdit(grp1, 10, 190, 100, blah) Local edt1.gad1 = First gad1 |
| ||
now im getting 'object doesnt exist' and i KNOW i did this right. if i didnt, correct me if im wrong, but i did what i think i should do: |
| ||
hi you never, created one instance of the edt1 type variable, so no one exist i don't read the thread, (my fault), but you have a Global edt1 and a type edt1, what for? as i saw in the previous post of malice you had an edt1 variable to hold the type wiht the same name? these are 3 diferent beasts! you need a global variable for the gadget, ok, name it as you want but never name a variable the same as a type name. you need a variable of "bla" type, name it as you want but not "bla". and if you want to use a type varible you have to create an instance of one (at least) with the new operator. "Local edt11.edt1 = First edt1" results in adt11 = Null because you have none edt1 variable created with new. you may not use types or read carefully about them Juan |
| ||
no offense, but i don't understand you. |
| ||
I think it's clear you're trying something a bit beyond your ability and understanding right now. DevilGUI uses a lot of types, and if you don't fully grasp how to use them, then you're making things even harder for yourself. I sincerely suggest you read up and get to grips with Types, or try something simpler for the time being. Here's a working version of your calculator, but please take the time to look through and understand the differences. |
| ||
ok. i see. now im having a small problem. if i hit 0 more than once, it would add more than one 0 to edt1. so i came up w/ a solution. i set edt1 to automatically be 0 when it loads. the PROBLEM im having is that it allows any other number to be used more than once AFTER the 0. it doesnt DELETE the 0, and THEN change to the number, like it should. it also doesnt allow for 0 to be used more than once ONLY IF the 1st number used is NOT 0. here's what i have so far: |
| ||
I already foreasaw you would wanyt to do something like this, that's why I kept the ButtonPress function restricted to between 1 and 9. To set the initial value of edt1 as "0", just change this line to: edt1 = GUI_CreateEdit(grp1, 10, 190, 100,"0") Now to make sure your box doesn't contain values such as "0010" you need to know that if ANY "0"'s preceed other digits, they ought to be removed. GUI_Message(edt1,"gettext") will give you the current string for edt1. you can check the first digits with Left$() Here's a hint: If (Len(GUI_Message(edt1,"gettext")) While ((Left$(GUI_Message(edt1,"gettext"),1)="0") And (Len(GUI_Message(edt1,"gettext"))>1)) GUI_Message(edt1,"settext",Right$(GUI_Message(edt1,"gettext"),Len(GUI_Message(edt1,"gettext"))-1)) Wend End If |
| ||
? |
| ||
As it stands, what you have posted there, you have commented out the very code that adds the numbers that you click... Which you just spent the last 10 posts or so trying to achieve. Think a little for yourself, please. Instead of simply copying and pasting in code, look at what you have and understand how it works. If you don't know how your own code works, of course you are never going to be able to incorporate suggestions without running into errors. If it's too much to understand what you are doing (i.e. working with Types, DevilGUI ec.) then learn how to use them, how they work first, OR just quit for now and try something SIMPLE. I hve lost count of how many times this advice has been given to you, but still you continue to ignore adice, fail to even answer simple questions and continue on your attempts revolving around just coping and pasting in other people's code without a clue what's going on. Seriously. Just take your time and TRY. Don't expect everyone else to write code for you if you're not making any effort yourself. It's been said before, but I see it didn't have any effect. |
| ||
hey! thanks alot man! after thinking about it, it worked! =D |
| ||
That's more like it :) EVERYBODY has bugs in their code, and everyone finds that what they try to do doesn't always work as intended. I don't mind helping out, and I will try to where possible, but most of the time, before jumping straight back here with a problem, if you just look closely and carefully at your code, keeping in mind all that it IS DOING as well as what it SHOULD BE DOING, you will have a much better grasp of finding the problem! |
| ||
ok. now how do i make it so i can use calculator signs such as plus, minus, etc... ? it also has to repeat like this: 0+1+1+1+1+4-8*9/9 also, if there is a default 0 in 1st position, and u press a sign, it allows u to add, subtract, etc... that number from 0 like so and remember, it MUST be the DEFAULT 0: 0+1*2/3-4 code: teach me how to do it EXACTLY like u taught me to fix the 0 problem. that seems to be the best way i learn. i learn by example. u showed me an example and gave me an easy hint. thats how i learn ^^ that way, ur not doing it for me, and i learn something new! ^^ |
| ||
Okay, well I would keep thiose extra buttons separate from the ButtonPress function. That way theyu can be dealt with in the ordinary AppEvent() function. i.e. (This is just pseudo-code as a kind of examnplke) Select (GUI_AppEvent()) Case btn0: ButtonPress(0) Case btn1: ButtonPress(1) Case btn2: ButtonPress(2) Case btn3: ButtonPress(3) Case btn4: ButtonPress(4) Case btn5: ButtonPress(5) Case btn6: ButtonPress(6) Case btn7: ButtonPress(7) Case btn8: ButtonPress(8) Case btn9: ButtonPress(9) Case btnplus: ;Do stuff for Plus Case btnequals: ;Do stuff for Equals Because it wont matter if there's the initial "0" there or not for the button presses, then the "Do Stuff For ...." sections will just need to add the "+", "/", "*" etc. symbols. HOWEVER- You may consider some restrictions, such as only allowing one symbol at a time or you may end up with: "13*+4^*3" doesn't make any sense! Simply then, taking "+" as an example, our "Do Stuff For Plus..." section will first check to ensure the last digit so far is a number and NOT a symbol. Then, if so, it will add the symbol. Using the Right$() command, you can quickly check what the last digit is. Forotunately, as we're only using a single digit, numerical values 0 - 9 share the same values as when working with integers. So the hole expression can be done with one line: If ((Right$(GUI_Message(edt1,"gettext"),1)>=0) And ((Right$(GUI_Message(edt1,"gettext"),1)<=9)) Then GUI_Message(edt1,"settext","+") For the other buttons (I'm gonna leave "=" for later, because that's gonna be a different story altogether.), the same technique is applied identiaclly: If ((Right$(GUI_Message(edt1,"gettext"),1)>=0) And ((Right$(GUI_Message(edt1,"gettext"),1)<=9)) Then GUI_Message(edt1,"settext","-") If ((Right$(GUI_Message(edt1,"gettext"),1)>=0) And ((Right$(GUI_Message(edt1,"gettext"),1)<=9)) Then GUI_Message(edt1,"settext","*") If ((Right$(GUI_Message(edt1,"gettext"),1)>=0) And ((Right$(GUI_Message(edt1,"gettext"),1)<=9)) Then GUI_Message(edt1,"settext","/") If ((Right$(GUI_Message(edt1,"gettext"),1)>=0) And ((Right$(GUI_Message(edt1,"gettext"),1)<=9)) Then GUI_Message(edt1,"settext","^") |
| ||
um, do i have this right? |