Re: Another problem with my checkbook (figured it out)


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Re: Another problem with my checkbook (figured it out)

  1. #1
    Mike Guest

    Re: Another problem with my checkbook (figured it out)


    Ok I think that I found the answer, I decided to do a lostfocus sub and that
    seemed to work better.

    Private Sub Txtck_lostfocus()
    If Val(Txtck.Text) <= 100 Then
    MsgBox "Checknumber must be over 100"

    Txtck.SetFocus
    Exit Sub
    End If
    End Sub





    "Mike" <marymike33@hotmail.com> wrote:
    >
    >Hi everyone, last week I was working on my checkbook and everyone here was
    >very helpful and I learned a great deal from your ideas. Well for this weeks
    >class I am stuck again.In my checkbook I have a field that requires the

    user
    >to enter the type of transaction that he is doing for instance...DA or debit
    >adjustment CA credit adjustment CK check etc...well heres my problem. In
    >the app If the user enters in a CK for check the user is than required to
    >enter a check number over 100. This part of my app works fine the only problem
    >is if they enter anything other than CK than the app is still looking for
    >the check number. I set the app up so that when a CK is entered in it than
    >enables the CKtextbox and a ck is required. Ive tried many diffrent things
    >just to come up with the same error. I posted the code below if anyone has
    >any ideas, Im not looking for the answers and any constructive critsism

    is
    >welcome.
    >
    >
    >Private Sub Cmdcalculate_Click()
    >If Txtamt.Text = "" Or Val(Txtamt.Text) <= 0.99 Or Val(Txtamt.Text) >= 100000
    >Then
    > MsgBox "The Transaction Amount is not an acceptable amount"
    > Txtamt.SetFocus
    > Exit Sub
    > End If
    >
    > curamt = Val(Txtamt)
    > If Txttype.Text = "ck" Or Txttype.Text = "da" Then
    > curtotal = curtotal - curamt
    > Else: curtotal = curtotal + curamt
    > End If
    > If Txtck.Text < 100 Then
    >MsgBox "Checknumber must be over 100"
    >Txtck.Text = ""
    >Txtck.SetFocus
    >Exit Sub
    >End If
    > Lbltot.Caption = "$" & curtotal
    > Txtdate.SetFocus
    >End Sub
    >
    >



  2. #2
    Sue Harsevoort Guest

    Re: Another problem with my checkbook (figured it out)

    You should be careful when you use the lostfocus to validate entries. In
    your case were you only have one textbox that you are validating at this
    time you should not have any problems, but if you have more than one you
    could end up in an infinate loop. For example put two text boxes on a form
    and put this code in

    Private Sub Text1_Lostfocus()
    if not isdate(text1.text) then
    msgbox "Please enter valid date"
    Text1.setfocus
    end if
    end sub

    Private Sub Text2_Lostfocus()
    if not isnumeric(text2.text) then
    msgbox "Please enter valid number"
    Text2.setfocus
    end if
    end sub

    If you run this program and tab out of text1 when it doesn't have a valid
    date and text2 doesn't have a valid number you will just get message boxes
    forever until you end the task (assuming I didn't make any typos).

    I don't remember what version of VB it was first in but there is an event in
    VB6 called Validate that you should use to validate data if you do it at the
    textbox level. Check out the Validate event in the help.

    You could also have changed your orginal code to only check the check number
    if txtType.text = "ck"

    Sue

    "Mike" <marymike33@hotmail.com> wrote in message
    news:3ae70f9d$1@news.devx.com...
    >
    > Ok I think that I found the answer, I decided to do a lostfocus sub and

    that
    > seemed to work better.
    >
    > Private Sub Txtck_lostfocus()
    > If Val(Txtck.Text) <= 100 Then
    > MsgBox "Checknumber must be over 100"
    >
    > Txtck.SetFocus
    > Exit Sub
    > End If
    > End Sub
    >
    >
    >
    >
    >
    > "Mike" <marymike33@hotmail.com> wrote:
    > >
    > >Hi everyone, last week I was working on my checkbook and everyone here

    was
    > >very helpful and I learned a great deal from your ideas. Well for this

    weeks
    > >class I am stuck again.In my checkbook I have a field that requires the

    > user
    > >to enter the type of transaction that he is doing for instance...DA or

    debit
    > >adjustment CA credit adjustment CK check etc...well heres my problem. In
    > >the app If the user enters in a CK for check the user is than required to
    > >enter a check number over 100. This part of my app works fine the only

    problem
    > >is if they enter anything other than CK than the app is still looking for
    > >the check number. I set the app up so that when a CK is entered in it

    than
    > >enables the CKtextbox and a ck is required. Ive tried many diffrent

    things
    > >just to come up with the same error. I posted the code below if anyone

    has
    > >any ideas, Im not looking for the answers and any constructive critsism

    > is
    > >welcome.
    > >
    > >
    > >Private Sub Cmdcalculate_Click()
    > >If Txtamt.Text = "" Or Val(Txtamt.Text) <= 0.99 Or Val(Txtamt.Text) >=

    100000
    > >Then
    > > MsgBox "The Transaction Amount is not an acceptable amount"
    > > Txtamt.SetFocus
    > > Exit Sub
    > > End If
    > >
    > > curamt = Val(Txtamt)
    > > If Txttype.Text = "ck" Or Txttype.Text = "da" Then
    > > curtotal = curtotal - curamt
    > > Else: curtotal = curtotal + curamt
    > > End If
    > > If Txtck.Text < 100 Then
    > >MsgBox "Checknumber must be over 100"
    > >Txtck.Text = ""
    > >Txtck.SetFocus
    > >Exit Sub
    > >End If
    > > Lbltot.Caption = "$" & curtotal
    > > Txtdate.SetFocus
    > >End Sub
    > >
    > >

    >




  3. #3
    Mike Guest

    Re: Another problem with my checkbook (figured it out)


    Sue
    Thanks for the response. I am a beginner as you might be able to see. I do
    appreciate your advice. The only reason that I chose the lostfocus as because
    I couldnt figure out ho to have it only check if TxtType.text = "ck" and
    than check it if it as another choice than skip over the validation and move
    to the next line. I kept getting errors during it. But I wil definitly look
    into it and see if there is a better was to accomplish this
    Mike




    "Sue Harsevoort" <SusannaH67@hotmail.com> wrote:
    >You should be careful when you use the lostfocus to validate entries. In
    >your case were you only have one textbox that you are validating at this
    >time you should not have any problems, but if you have more than one you
    >could end up in an infinate loop. For example put two text boxes on a form
    >and put this code in
    >
    >Private Sub Text1_Lostfocus()
    > if not isdate(text1.text) then
    > msgbox "Please enter valid date"
    > Text1.setfocus
    > end if
    >end sub
    >
    >Private Sub Text2_Lostfocus()
    > if not isnumeric(text2.text) then
    > msgbox "Please enter valid number"
    > Text2.setfocus
    > end if
    >end sub
    >
    >If you run this program and tab out of text1 when it doesn't have a valid
    >date and text2 doesn't have a valid number you will just get message boxes
    >forever until you end the task (assuming I didn't make any typos).
    >
    >I don't remember what version of VB it was first in but there is an event

    in
    >VB6 called Validate that you should use to validate data if you do it at

    the
    >textbox level. Check out the Validate event in the help.
    >
    >You could also have changed your orginal code to only check the check number
    >if txtType.text = "ck"
    >
    >Sue
    >
    >"Mike" <marymike33@hotmail.com> wrote in message
    >news:3ae70f9d$1@news.devx.com...
    >>
    >> Ok I think that I found the answer, I decided to do a lostfocus sub and

    >that
    >> seemed to work better.
    >>
    >> Private Sub Txtck_lostfocus()
    >> If Val(Txtck.Text) <= 100 Then
    >> MsgBox "Checknumber must be over 100"
    >>
    >> Txtck.SetFocus
    >> Exit Sub
    >> End If
    >> End Sub
    >>
    >>
    >>
    >>
    >>
    >> "Mike" <marymike33@hotmail.com> wrote:
    >> >
    >> >Hi everyone, last week I was working on my checkbook and everyone here

    >was
    >> >very helpful and I learned a great deal from your ideas. Well for this

    >weeks
    >> >class I am stuck again.In my checkbook I have a field that requires the

    >> user
    >> >to enter the type of transaction that he is doing for instance...DA or

    >debit
    >> >adjustment CA credit adjustment CK check etc...well heres my problem.

    In
    >> >the app If the user enters in a CK for check the user is than required

    to
    >> >enter a check number over 100. This part of my app works fine the only

    >problem
    >> >is if they enter anything other than CK than the app is still looking

    for
    >> >the check number. I set the app up so that when a CK is entered in it

    >than
    >> >enables the CKtextbox and a ck is required. Ive tried many diffrent

    >things
    >> >just to come up with the same error. I posted the code below if anyone

    >has
    >> >any ideas, Im not looking for the answers and any constructive critsism

    >> is
    >> >welcome.
    >> >
    >> >
    >> >Private Sub Cmdcalculate_Click()
    >> >If Txtamt.Text = "" Or Val(Txtamt.Text) <= 0.99 Or Val(Txtamt.Text) >=

    >100000
    >> >Then
    >> > MsgBox "The Transaction Amount is not an acceptable amount"
    >> > Txtamt.SetFocus
    >> > Exit Sub
    >> > End If
    >> >
    >> > curamt = Val(Txtamt)
    >> > If Txttype.Text = "ck" Or Txttype.Text = "da" Then
    >> > curtotal = curtotal - curamt
    >> > Else: curtotal = curtotal + curamt
    >> > End If
    >> > If Txtck.Text < 100 Then
    >> >MsgBox "Checknumber must be over 100"
    >> >Txtck.Text = ""
    >> >Txtck.SetFocus
    >> >Exit Sub
    >> >End If
    >> > Lbltot.Caption = "$" & curtotal
    >> > Txtdate.SetFocus
    >> >End Sub
    >> >
    >> >

    >>

    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center