PDA

View Full Version : problem in a form



eran3185
05-04-2007, 06:15 AM
i build a simple form.
i want that the user fill in "textbox1" and "textbox2" and then the total amount will appear in "textbox3"
also - i want that the button will "clear" the form to the next use,

Bob Phillips
05-04-2007, 07:10 AM
Private Sub cmdOK_Click()
With Me
If .TextBox1.Text <> "" And .TextBox2.Text <>"" Then
.TextBox3.Text = CDbl(.TextBox1.Text) + CDbl(.TextBox2.Text)
.TextBox1.Text = ""
.TextBox2.Text = ""
End If
End With

End Sub


Edit Lucas: Operators added....hope it's correct.

eran3185
05-04-2007, 07:27 AM
hey
i steal have problems ...
1-i copy the code , but it doesn't work.
2-also - textbox2 doesn't get any number in
3-and last - can u explain me what does it nean : "cdb1" ?

thanks !

Simon Lloyd
05-04-2007, 07:48 AM
I am assuming (after what the great Xid has just told me) that Cdbl means Cast Double to allow for long numbers, the code will not work if your commandbutton name is not called cmdOK

Regards,
Simon

eran3185
05-04-2007, 08:31 AM
ok
so , why can't i write anything in textbox2 ???
and why when i put something in textbox3 it copy to textbox 2 ????

many thanks from :banghead: person...

lucas
05-04-2007, 08:41 AM
Changed Bob's code a little.....may get in trouble for it but...
Private Sub CommandButton1_Click()
With Me
.TextBox3.Text = CDbl(.TextBox1.Text) + CDbl(.TextBox2.Text)
.TextBox1.Text = ""
.TextBox2.Text = ""
End With
End Sub

eran3185
05-04-2007, 09:17 AM
sorry guys :dunno
i was wrong and by mistake i wrote that i want : textbox1 + textbox2 , but it should be : textbox1 / textbox2 .
also i saw that textbox2 doesn't get any number in (before i push the button)
sorry again ...

lucas
05-04-2007, 09:22 AM
so....is this working or not?

eran3185
05-04-2007, 09:29 AM
no
i need : not +
and if there is something "/" 0 its not ok

Simon Lloyd
05-04-2007, 09:39 AM
Lucas, if you understood that your a better man than me! LOL!
i think he wants to divide TB1 by TB2 result in TB3 and cure Div#0.

or at least thats what it seems like!

Regards,
Simon

lucas
05-04-2007, 09:42 AM
so to be clear....hope I understand.
You want textbox 3 to equal textbox 1 divided by textbox 2

you also want for textbox 2 not to equal 0

correct?

lucas
05-04-2007, 09:44 AM
I think we have a slight language problem but with a little patience I think this can be fixed......hang in there Eran.

eran3185
05-04-2007, 10:08 AM
simon , almost right.
i think that could be a problem if denominator = 0
i dont know what value the user fill in textbox1 and textbox2

eran3185
05-04-2007, 11:55 AM
well - great guy's!

simon correct! i need textbox 3 to equal textbox 1 divided by textbox 2 and cure Div#0.
the users will input t.b1, t.b.2.
also - i want a button will "clear" the form to the next use.

thanks again...:doh:

lucas
05-04-2007, 12:41 PM
Hi Erin,
I cound't figure out a way around the divide by 0 problem as far as textbox change was concerned. My workaround involves a new button to calculate. Maybe someone can see a way around the problem. My attempt is attached to this post

Gert Jan
05-04-2007, 01:03 PM
Maybe like this?
Private Sub CommandButton2_Click()
If TextBox2.Value = 0 Then
MsgBox "cannot divide bij zero"
TextBox3.SetFocus
Exit Sub
End If
TextBox3.Value = TextBox1.Value / TextBox2.Value
End Sub

Bob Phillips
05-04-2007, 01:20 PM
Sorry for my code, not my fault, I seem to lose greater than and less than signs, so the test for not equal just disappeared.

lucas
05-04-2007, 01:51 PM
I think the objective was to have a textbox change on textbox 1 & 2 so that when they changed textbox3 would show the division of the 2 values. I ran into a conflict trying to do that because of the clear button which triggered the textox change event resulting in a division by zero....at least that's what I think is happening...

Simon Lloyd
05-04-2007, 01:52 PM
Poor "El Xid" will anyone please help this man out?....one of the sites great posters and cast aside like a broken toy!....was that too much Bob?

Regards,
Simon

Gert Jan
05-04-2007, 02:02 PM
I think the objective was to have a textbox change on textbox 1 & 2 so that when they changed textbox3 would show the division of the 2 values. I ran into a conflict trying to do that because of the clear button which triggered the textox change event resulting in a division by zero....at least that's what I think is happening...

Instead of using textbox_change(), use textbox_exit()?


I seem to lose greater than and less than signs
@ XLD; I found them, i have no idea how they got here but they are on my keyboard :whistle:

lucas
05-04-2007, 02:05 PM
Bob's the one I was hoping would shed some light on the problem posed in post # 18......am I missing something?

lucas
05-04-2007, 02:15 PM
Hi Gert Jan,
that works pretty good if you only use it on the second textbox.
Textbox exit. A little error handling in case they try to start by entering numbers in textbox 2 first..

Bob Phillips
05-05-2007, 09:22 AM
I think so. It's my machine that is the problem because it works fine on my desktop box.

It is wierd, I have a few problems, the less than greater than signs, I have to add all of the HTML linebreaks, and it gets confused with @ and ".

Simon Lloyd
05-05-2007, 09:41 AM
Bob i know i'm probably teaching you to suck eggs here but is it possible the keyboard has been set up for a different language?

......the words "grasping" and "straws" seem to be forming a picture for me!
LOL

Regards,
Simon

Bob Phillips
05-05-2007, 10:12 AM
No, everything is setup English (UK).

As I say, it is wierd because it won't even take anything I add without me manually inserting <br /> for every line, that is the HTML nbsp.

I have a program which outputs strings to the current input stream, and this also fails to generate CRs on this machine.

jammer6_9
05-06-2007, 06:32 AM
.

jammer6_9
05-06-2007, 06:59 AM
Start @ textbox1 or textbox2...


Private Sub TextBox1_Change()
On Error Resume Next
With Me.TextBox1
If .Value = "" Then
.Value = 0
End If
End With
TextBox3.Value = TextBox1.Value / TextBox2.Value
End Sub

Private Sub TextBox2_Change()
On Error Resume Next
With Me.TextBox2
If .Value = "" Then
.Value = 0
End If
End With
TextBox3.Value = TextBox1.Value / TextBox2.Value
End Sub

Private Sub CommandButton1_Click()
TextBox1.Value = ""
TextBox2.Value = ""
TextBox3.Value = ""
End Sub




Hi Gert Jan,
that works pretty good if you only use it on the second textbox.
Textbox exit. A little error handling in case they try to start by entering numbers in textbox 2 first..

lucas
05-06-2007, 08:16 AM
That's one way to get around it jammer...seems op is going to have to decide what works best for them..

jammer6_9
05-06-2007, 12:02 PM
:beerchug:

That's one way to get around it jammer...seems op is going to have to decide what works best for them..