calculator help again :(
calculator help again :(
calculator help again :(
calculator help again :(
calculator help again :(
calculator help again :( calculator help again :( calculator help again :( calculator help again :( calculator help again :( calculator help again :( calculator help again :( calculator help again :(
calculator help again :( calculator help again :(
calculator help again :(
Go Back  Xtreme Visual Basic Talk > > > calculator help again :(


Reply
 
Thread Tools Display Modes
  #1  
Old 11-16-2006, 05:43 PM
sdog sdog is offline
Freshman
 
Join Date: Oct 2006
Posts: 27
Default calculator help again :(


hey guys i was wondering if you could help me
im making a calculator and i need to set a variable to a function like
cd = addition
or
format( ad as addition)
but i get build errors.
can someone help me?
Reply With Quote
  #2  
Old 11-16-2006, 06:06 PM
MikeJ's Avatar
MikeJcalculator help again :( MikeJ is offline
Retread

Retired Moderator
* Expert *
 
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,747
Default

Quote:
Originally Posted by sdog
but i get build errors.
Could you please post the offending lines of code and the errors generated?
__________________
{ Lex Fori } { Locus Classicus } { Rutilus Scrinium }
Osculare pultem meam!
Reply With Quote
  #3  
Old 11-16-2006, 06:23 PM
sdog sdog is offline
Freshman
 
Join Date: Oct 2006
Posts: 27
Default

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = txtA.Text
txtA.Text = ""
ab = txtA.Text
bc = TextBox1.Text
function(cd as addition

End Function

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
txtA.Text = (ab) cd.function (bc)
End Sub
End Class
Reply With Quote
  #4  
Old 11-16-2006, 06:33 PM
MikeJ's Avatar
MikeJcalculator help again :( MikeJ is offline
Retread

Retired Moderator
* Expert *
 
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,747
Default

I think you've gotten a little confused about functions. They need to have their own name and procedure; and if you want to pass multiple items, you should have multiple parameters:
Code:
Public Function Addition (val1 As Integer, val2 As Integer) As Integer 'This is a proper function layout Return something End Function
something has to be an Integer.

You would then call it like this:
Code:
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click txtA.Text = Me.Addition(ab, bc) End Sub
__________________
{ Lex Fori } { Locus Classicus } { Rutilus Scrinium }
Osculare pultem meam!
Reply With Quote
  #5  
Old 11-16-2006, 06:41 PM
sdog sdog is offline
Freshman
 
Join Date: Oct 2006
Posts: 27
Default

k im confused what do i put in place of something
Reply With Quote
  #6  
Old 11-16-2006, 06:48 PM
MikeJ's Avatar
MikeJcalculator help again :( MikeJ is offline
Retread

Retired Moderator
* Expert *
 
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,747
Default

Whatever you want that function to do.
__________________
{ Lex Fori } { Locus Classicus } { Rutilus Scrinium }
Osculare pultem meam!
Reply With Quote
  #7  
Old 11-16-2006, 06:51 PM
sdog sdog is offline
Freshman
 
Join Date: Oct 2006
Posts: 27
Default

like wat addition?
Reply With Quote
  #8  
Old 11-16-2006, 06:53 PM
sdog sdog is offline
Freshman
 
Join Date: Oct 2006
Posts: 27
Default

Conversion from string "" to type 'Integer' is not valid.
comes upnow around ab = txtb.Text
Reply With Quote
  #9  
Old 11-16-2006, 07:04 PM
MikeJ's Avatar
MikeJcalculator help again :( MikeJ is offline
Retread

Retired Moderator
* Expert *
 
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,747
Default

You should use a Type Conversion function:
http://www.startvbdotnet.com/language/conversion.aspx
__________________
{ Lex Fori } { Locus Classicus } { Rutilus Scrinium }
Osculare pultem meam!
Reply With Quote
  #10  
Old 11-16-2006, 07:09 PM
sdog sdog is offline
Freshman
 
Join Date: Oct 2006
Posts: 27
Default

i give up
Reply With Quote
  #11  
Old 11-16-2006, 07:20 PM
Roger_Wgnr's Avatar
Roger_Wgnr Roger_Wgnr is offline
CodeASaurus Hex

Forum Leader
* Expert *
 
Join Date: Jul 2006
Location: San Antonio TX
Posts: 2,427
Default

The error
Quote:
Conversion from string "" to type 'Integer' is not valid.
comes upnow around ab = txtb.Text
is handled by
Quote:
You should use a Type Conversion function
such as this example
Code:
ab = Cint(txtb.Text)
does this explain it if not tell us what you don't understand and we will be happy to explain it.
__________________
Code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. ~Martin Golding
The user is a peripheral that types when you issue a read request. ~Peter Williams
MSDN Visual Basic .NET General FAQ
Reply With Quote
  #12  
Old 11-16-2006, 07:32 PM
sdog sdog is offline
Freshman
 
Join Date: Oct 2006
Posts: 27
Default

Conversion from string "" to type 'Integer' is not valid.
ab = CInt(txtb.Text)
Reply With Quote
  #13  
Old 11-16-2006, 07:39 PM
MikeJ's Avatar
MikeJcalculator help again :( MikeJ is offline
Retread

Retired Moderator
* Expert *
 
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,747
Default

Is there nothing inside of txtB? It makes no sense to try and add a blank value to something. You should check to make sure the textboxes contain data before calling your math functions.
__________________
{ Lex Fori } { Locus Classicus } { Rutilus Scrinium }
Osculare pultem meam!
Reply With Quote
  #14  
Old 11-16-2006, 07:40 PM
jwakeman's Avatar
jwakeman jwakeman is offline
Contributor
 
Join Date: Jul 2005
Posts: 420
Default

the string is empty
Reply With Quote
  #15  
Old 11-16-2006, 07:43 PM
sdog sdog is offline
Freshman
 
Join Date: Oct 2006
Posts: 27
Default

ok lets start from the beginning
deleted most of my code to start over
i have 1-9and zero buttons (have code and works with single and double digits)
they are named a-j
a being one and j being zero
i have one text box (txtA.text)
i have a plus button which is button1(has no code)
i have a minus button which is button 2(has no code)
i have a * button which is button 3 (has no code)
i have a / button which is button 4(has no code)
and a clr button (button 5)(has code and works)
and an equals button (button 6) (has no code)
ok where do i go from here please
Reply With Quote
  #16  
Old 11-16-2006, 07:45 PM
MikeJ's Avatar
MikeJcalculator help again :( MikeJ is offline
Retread

Retired Moderator
* Expert *
 
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,747
Default

Is txtA where the results go? What happened to txtB from your earlier posts?
__________________
{ Lex Fori } { Locus Classicus } { Rutilus Scrinium }
Osculare pultem meam!
Reply With Quote
  #17  
Old 11-16-2006, 07:46 PM
sdog sdog is offline
Freshman
 
Join Date: Oct 2006
Posts: 27
Default

ok i got rid of txt b
i dont really think need it
and yes txtA is where the results go and the numbers go as you type them in
now the function buttons have to clear txtA first of all right but once they clr it how do i store what was in them?
Reply With Quote
  #18  
Old 11-16-2006, 07:51 PM
MikeJ's Avatar
MikeJcalculator help again :( MikeJ is offline
Retread

Retired Moderator
* Expert *
 
Join Date: Sep 2002
Location: Austin, Texas
Posts: 6,747
Default

Code:
Dim someNum As Integer = CInt(txtA.Text) txtA.Clear()
__________________
{ Lex Fori } { Locus Classicus } { Rutilus Scrinium }
Osculare pultem meam!
Reply With Quote
  #19  
Old 11-16-2006, 07:55 PM
sdog sdog is offline
Freshman
 
Join Date: Oct 2006
Posts: 27
Default

where do i put that at the top?
Reply With Quote
  #20  
Old 11-16-2006, 07:59 PM
sdog sdog is offline
Freshman
 
Join Date: Oct 2006
Posts: 27
Default

wait dumb question i know it goes under the addition button
Better quetion:
how do i put that under the equals button and have the button still work for the other functions?
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
calculator help again :(
calculator help again :(
calculator help again :( calculator help again :(
calculator help again :(
calculator help again :(
calculator help again :( calculator help again :( calculator help again :( calculator help again :( calculator help again :( calculator help again :( calculator help again :(
calculator help again :(
calculator help again :(
 
calculator help again :(
calculator help again :(
 
-->