| View previous topic :: View next topic |
| Author |
Message |
michaelsamazingxx Cheater
Reputation: 0
Joined: 06 Oct 2007 Posts: 48
|
Posted: Thu Mar 06, 2008 7:32 pm Post subject: Need help with VB |
|
|
Im making my first program [ a calculator ] and i dotn know how to do the + and = sign. can anyone help me out? this is what i have. | Code: | Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
Dim Button11 As Integer
Button11 = [ what goes here?]
Laura.Text = Button11
End Sub
End Class |
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Thu Mar 06, 2008 8:20 pm Post subject: |
|
|
The idea, simply:
+ Button should get what's currently in the edit box (and use it as the first value) and set the operator.
= Button should get the value in the edit box (and use it as the second) and do whatever, depending on the operator.
Then you could get fancy and determine if an operator button has been clicked before, and if it has, do that operation since you already had a first value and would be getting a second. Once it's done move the newly calculated number into the first one and go from there.
What version of VB are you using?
On to your code, why are you trying to declare a button as an integer? You want to give the button something to do, like start setting up the calculation.
(I don't know how VB actually does type conversions, I'm pretty sure atleast the .NET version of VB will try to do it on it's own. I'll wait on Wiccaan to chime in)
|
|
| Back to top |
|
 |
Haxory' Grandmaster Cheater Supreme
Reputation: 92
Joined: 30 Jul 2007 Posts: 1900
|
Posted: Fri Mar 07, 2008 12:40 am Post subject: |
|
|
hmmm long time ago since ma first application.....
| Code: |
Private Sub Button11_Click()
Label1.Caption = Laura.Text + Text1.Text
End Sub |
_________________
you and me baby ain't nothing but mammals so lets do it like they do on the discovery channel |
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Fri Mar 07, 2008 1:18 am Post subject: |
|
|
I got bored and thanks to the power of a C# -> VB.net converter...
Hopefully this was for VB.net and not VB6... Ignore the #'s too lazy to delete them all. All you have to do is add the controls and it's functional.
| Code: | # Imports System
# Imports System.Collections.Generic
# Imports System.ComponentModel
# Imports System.Data
# Imports System.Drawing
# Imports System.Text
# Imports System.Windows.Forms
#
# Namespace WindowsFormsApplication1
# Public Partial Class Form1
# Inherits Form
# Private value1 As Single = 0
# Private value2 As Single = 0
# Private op As Integer = 0
# '1 add, 2 sub, 3 mul, 4 div
# Private used As Boolean() = New Boolean(3) {}
#
# Public Sub New()
# InitializeComponent()
# End Sub
#
# Private Sub addButton_Click(ByVal sender As Object, ByVal e As EventArgs)
# Select Case used(0)
# Case True
# value2 = Convert.ToSingle(edit.Text)
# value1 = value1 + value2
# edit.Text = Convert.ToString(value1)
# used(0) = False
# Exit Select
# Case False
#
# value1 = Convert.ToSingle(edit.Text)
# op = 1
# used(0) = True
# Exit Select
# End Select
# End Sub
#
# Private Sub subButton_Click(ByVal sender As Object, ByVal e As EventArgs)
# Select Case used(1)
# Case True
# value2 = Convert.ToSingle(edit.Text)
# value1 = value1 - value2
# edit.Text = Convert.ToString(value1)
# used(1) = False
# Exit Select
# Case False
#
# value1 = Convert.ToSingle(edit.Text)
# op = 2
# used(1) = True
# Exit Select
# End Select
# End Sub
#
# Private Sub mulButton_Click(ByVal sender As Object, ByVal e As EventArgs)
# Select Case used(2)
# Case True
# value2 = Convert.ToSingle(edit.Text)
# value1 = value1 * value2
# edit.Text = Convert.ToString(value1)
# used(2) = False
# Exit Select
# Case False
#
# value1 = Convert.ToSingle(edit.Text)
# op = 3
# used(2) = True
# Exit Select
# End Select
# End Sub
#
# Private Sub divButton_Click(ByVal sender As Object, ByVal e As EventArgs)
# Select Case used(3)
# Case True
# value2 = Convert.ToSingle(edit.Text)
# value1 = value1 / value2
# edit.Text = Convert.ToString(value1)
# used(3) = False
# Exit Select
# Case False
#
# value1 = Convert.ToSingle(edit.Text)
# op = 4
# used(3) = True
# Exit Select
# End Select
# End Sub
#
# Private Sub equButton_Click(ByVal sender As Object, ByVal e As EventArgs)
# Dim i As Integer
# For i = 0 To 3
# used(i) = False
# Next
# If op <> 0 Then
# value2 = Convert.ToSingle(edit.Text)
# Select Case op
# Case 1
# value1 = value1 + value2
# edit.Text = Convert.ToString(value1)
# Exit Select
# Case 2
# value1 = value1 - value2
# edit.Text = Convert.ToString(value1)
# Exit Select
# Case 3
# value1 = value1 * value2
# edit.Text = Convert.ToString(value1)
# Exit Select
# Case 4
# value1 = value1 / value2
# edit.Text = Convert.ToString(value1)
# Exit Select
# Case Else
# 'this should never happen.
# MessageBox.Show("Oh my sweet christ what did you do?")
# Exit Select
# End Select
# End If
# End Sub
# End Class
# End Namespace |
|
|
| Back to top |
|
 |
coder sal Master Cheater
Reputation: 0
Joined: 11 May 2007 Posts: 304
|
Posted: Sat Mar 08, 2008 11:15 am Post subject: Re: Need help with VB |
|
|
| michaelsamazingxx wrote: | Im making my first program [ a calculator ] and i dotn know how to do the + and = sign. can anyone help me out? this is what i have. | Code: | Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
Dim Button11 As Integer
Button11 = [ what goes here?]
Laura.Text = Button11
End Sub
End Class |
|
Try
| Code: |
Dim Button11 as String |
|
|
| Back to top |
|
 |
|