what am i doing wrong [Solved] [02/03]
hello, i am trying to make a stand alone cashregister program. everything works fine exept when it askes for a tender. it is designed to be used on a touch screen so it has an onscreen keyboard with all the keys. but there is an issue. it is set up so when you hit the 'pay' key on the main form it opens up a new diolog box with the onscreen keyboard. when ever i hit the '0' key it closes the diolog box.
here is the code for when the pay key is clicked:
Code:
Private Sub btnPay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPay.Click
Dim Pay As New Pay 'diolog with keypad
Dim responce As MsgBoxResult
Pay.total = total ' transfer the total to the diolog box
Pay.ShowDialog() 'show the diolog box
responce = Pay.DialogResult 'if payment compleate
If responce = MsgBoxResult.OK Then 'if payment is accepted
till = till + total 'add the order to the till
clear_transaction() ' start new transaction
End If
End Sub
here is the code that is ran when a user hits the 0 key
Code:
Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click
amtentered = amtentered & "0" 'add 0 to the end of the tender
format() ' format it in currency style
End Sub
Private Sub format()
'an amount of $12.00 is stored as 1200, the next line of code will put the decmial point in the right place.
itemamt.Text = FormatCurrency(amtentered / 100)
End Sub
i am new to programing any help is apprecated. if you need more information please let me know, thanks!
Re: what am i doing wrong [02/03]
format is a keyword in VB.... try changing it to something else.
Or use Me.Format instead.
Lastly, check your option settings and make sure OPTION STRICT and OPTION EXPLICIT are set.
-tg
Re: what am i doing wrong [02/03]
as i said i am new to programing, how do i use the option strict and option explicit? and what does it do?
Re: what am i doing wrong [02/03]
Put on the very top of your code page:
Option Strict On
Option Explicit On
It helps reducing errors and speeds up code execution.
Re: what am i doing wrong [02/03]
option explicit ensures the you explicitly define your variables and objects before you actually use them.
Option strict prevents you from doing implicit conversion ie: numbers to strings or strings to numbers.
They would be under Tools -> Options... you may have to dig around a little for it. Where it's located inVS2002 (which I don't have) is different from VS2005 (which I have)
-tg
Re: what am i doing wrong [02/03]
so far nothing seems to work, any other ideas?
Re: what am i doing wrong [02/03]
What's the problem? If you want to close the form when btn0 is clicked, then you should set the returned dialogresult value in the click evewnt handler, then close the form
Code:
Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click
amtentered = amtentered & "0" 'add 0 to the end of the tender
format() ' format it in currency style
Me.DialogResult = Windows.Forms.DialogResult.OK
Me.Close()
End Sub
Re: what am i doing wrong [02/03]
Stan - I think you have it backwards.... currently it IS shutting down, when it shouldn't....
Tony - put a breakpoint on the first line of the code for the 0 button..... when it stops, right click, select Toggle->Break on all Errors.... then step thorugh using F10..... at some point it should either break or you'll see where it's going..
Ah, wait, try this too.... in design mode..... select the form, then show the properties for the form (F4).... look for a property that reads "Default Button"... or close to it.... make sure it isn't set to your 0 button. In fact make sure it reads "None".
-tg
Re: what am i doing wrong [02/03]
Can't remember quite right, but isn't there a AcceptButton and CancelButton property for a form in 02/03, or is that just in 05? If those form properties exist, make sure that neither of them is set to your zero button, as well.
Re: what am i doing wrong [02/03]
ok after doing a steping though the code it goes though all the code first the code for the 0 key then the format code then it finishes off the 0 code then it goes back to the pay sub on the frist form finshes all the lines of that. then after that that is when the form closes.
if that makes sense?
yes VB 03 does have a defalt button setting.
Re: what am i doing wrong [02/03]
It goes through the first button, THEN it goes through a totally different button handler? That's impressive!! I assume that you don't explicitly call the second button handler. Is there any chance that the other button managed to get located under the 0 button?
Re: what am i doing wrong [02/03]
i wish i knew more about programing so i could explane it better...
when ever a user presses a number it updates a text box. when i want to type in $20.75 they would type 2075, as you press the keys it turns it into the correct format:
$.02, .20, 2.07, 20.75
this is what the format() sub is for
Code:
Private Sub formatcur()
itemamt.Text = FormatCurrency(amtentered / 100)
End Sub
Re: what am i doing wrong [02/03]
You say the dialog box with the onscreen keybord closes when hitting the 0 key, so it doesn't close on other keys, could you show us the code for such a key?
Re: what am i doing wrong [02/03]
here is the code for the 0 key
Code:
Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click
amtentered = amtentered & "0" 'add 0 to the end of the tender
formatcur() ' format it in currency style
End Sub
This is the code for the Formatcur() sub
Code:
Private Sub formatcur()
itemamt.Text = FormatCurrency(amtentered / 100)
End Sub
Re: what am i doing wrong [02/03]
I was asking for the code of another key, not the one for "0"!!!!
Re: what am i doing wrong [02/03]
Try adding anohter button that does the same thing as the zero, but call it "zero" and see if it does the same thing.
Re: what am i doing wrong [02/03]
here is the code for the 9 key
Code:
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
amtentered = amtentered & "9"
formatcur()
End Sub
Re: what am i doing wrong [02/03]
i figgered it out, the dialog result setting was set to cancel