vb newbie part 2 menu

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    lolicon123's Avatar Member
    Reputation
    1
    Join Date
    Oct 2008
    Posts
    31
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    vb newbie part 2

    i'm going to make a calculator. i have 4 txt boxes one for the first number a person should enter the second for if they want to use + - / etc.. third for the second number and fourth for the answer of the first and second number put together

    code:
    dim first as double
    dim second as double
    dim third as double
    dim fourth as double

    if secondbox.text = "+" then
    firstbox.text + thirdbox.text = fourthbox.text
    end if

    i've done - / the same. but as you can probably see this aint working if anyone could tell me how to write this i would be thankfull

    vb newbie part 2
  2. #2
    lolicon123's Avatar Member
    Reputation
    1
    Join Date
    Oct 2008
    Posts
    31
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just for fun want to learn some vb basic

  3. #3
    ReidE96's Avatar Archer Authenticator enabled
    Reputation
    470
    Join Date
    Dec 2006
    Posts
    1,625
    Thanks G/R
    1/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    firstbox.text + thirdbox.text = fourthbox.text

    should be

    fourthbox.text = CInt(firstbox.text) + CInt(thirdbox.text)

  4. #4
    lolicon123's Avatar Member
    Reputation
    1
    Join Date
    Oct 2008
    Posts
    31
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yea i noticed that it looks like this now

    txtFirst.Text = First
    txtSecond.Text = Second
    txtThird.Text = Third
    txtFourth.Text = Fourth

    Dim First As Double
    Dim Second As Double
    Dim Third As Double
    Dim Fourth As Double

    If Second = "+" Then
    Fourth = First + Third
    End If

    still "getting argument not optional" thought


    Edit: changed it too

    First = CDbl(txtFirst.Text)
    Third = CDbl(txtThird.Text)
    Fourth = CStr(txtFourth.Text)


    If Trim(txtSecond.Text) = "+" Then
    txtFourth = txtFirst + txtThird
    End If

    but when i write 2 + 2 i get 22 as if the variables were not declared :O


    edit2: funny thing is that if i use - or / instead of + it works :O hmm weird
    Last edited by lolicon123; 11-24-2009 at 04:35 PM.

  5. #5
    lolicon123's Avatar Member
    Reputation
    1
    Join Date
    Oct 2008
    Posts
    31
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    also i would like it to be unable to be divided by zero i tried

    "ElseIf txtFirst = "0" Or txtThird = "0" And txtSecond = "/" Then
    MsgBox "unable to divide by zero""

    not work here either i'm afraid :I

  6. #6
    ReidE96's Avatar Archer Authenticator enabled
    Reputation
    470
    Join Date
    Dec 2006
    Posts
    1,625
    Thanks G/R
    1/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, could you post your full source between [code] tags and I'll see if I can spot where you've gone wrong. Or someone else will spot it before I get to it. Either way works.

  7. #7
    lolicon123's Avatar Member
    Reputation
    1
    Join Date
    Oct 2008
    Posts
    31
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Private Sub Command1_Click()

    First = CDbl(txtFirst.Text)
    third = CDbl(txtThird.Text)
    Fourth = CStr(txtFourth.Text)

    If Trim(txtSecond.Text) = "+" Then
    txtFourth = txtFirst + txtThird

    ElseIf Trim(txtSecond.Text) = "*" Then
    txtFourth = txtFirst * txtThird

    ElseIf Trim(txtSecond.Text) = "-" Then
    txtFourth = txtFirst - txtThird

    ElseIf Trim(txtSecond.Text) = "/" Then
    txtFourth = txtFirst / txtThird

    ElseIf Trim(txtSecond.Text) = "+,*,-,/" Then
    Else: MsgBox "Felaktigt räknesätt"

    End If
    End Sub



    edit1:


    looks like this now


    Private Sub Command1_Click()

    First = CDbl(txtFirst.Text)
    third = CDbl(txtThird.Text)
    Fourth = CStr(txtFourth.Text)

    If Trim(txtSecond.Text) = "+" Then
    txtFourth = Val(txtFirst) + Val(txtThird)

    ElseIf Trim(txtSecond.Text) = "*" Then
    txtFourth = txtFirst * txtThird

    ElseIf Trim(txtSecond.Text) = "-" Then
    txtFourth = txtFirst - txtThird

    ElseIf Trim(txtSecond.Text) = "/" Then
    txtFourth = txtFirst / txtThird

    ElseIf Trim(txtSecond.Text) = "+,*,-,/" Then
    Else: MsgBox "Felaktigt räknesätt"

    End If

    End Sub

    and is working now about about divinding with zero can anyone help with that ?


    as i said tried "ElseIf txtFirst = "0" Or txtThird = "0" And txtSecond = "/" Then
    MsgBox "unable to divide by zero""

    did not work :I
    Last edited by lolicon123; 11-25-2009 at 01:53 AM.

  8. #8
    ReidE96's Avatar Archer Authenticator enabled
    Reputation
    470
    Join Date
    Dec 2006
    Posts
    1,625
    Thanks G/R
    1/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should have used those First and Third variables you defined XD And you don't need fourth.
    Code:
    txtFourth.Text = First + Third
    and so on. As to dividing by 0,
    Code:
    ElseIf Trim(txtSecond.Text) = "/" Then
    txtFourth = txtFirst / txtThird
    try changing to
    Code:
    ElseIf Trim(txtSecond.Text) = "/" Then
    If Not Third = 0 Then txtFourth.Text = First / Third Else MsgBox "Divide by 0 error message here"
    (change the message in red to something more appropriate )
    Last edited by ReidE96; 11-25-2009 at 09:31 AM. Reason: Typo

  9. #9
    lolicon123's Avatar Member
    Reputation
    1
    Join Date
    Oct 2008
    Posts
    31
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by ReidE96 View Post
    You should have used those First and Third variables you defined XD And you don't need fourth.
    lol but fourth is also defined how come i still need to write txtfourth = first + third ? why not just fourth = first + third that was what put me off to use that in the first place :O


    is it just my VB messing with me or is their something wrong with your code on divide with zero? getting error else without if :S just like i did with mine :O
    Last edited by lolicon123; 11-25-2009 at 10:33 AM.

  10. #10
    ReidE96's Avatar Archer Authenticator enabled
    Reputation
    470
    Join Date
    Dec 2006
    Posts
    1,625
    Thanks G/R
    1/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You've defined Fourth as a variable, which takes as its value the contents of txtFourth. First and Third are the same to txtFirst and txtThird. By doing txtFourth.Text = First + Third, you set the contents of txtFourth to the result of First + Third

    And if that doesn't work, replace
    Code:
    If Not Third = 0 Then txtFourth.Text = First / Third Else MsgBox "Divide by 0 error message here"
    with
    Code:
    If Not Third = 0 Then
        txtFourth.Text = First / Third
    Else
        MsgBox "Divide by 0 error message here"
    End If
    Last edited by ReidE96; 11-25-2009 at 10:52 AM. Reason: Adding colour

  11. #11
    lolicon123's Avatar Member
    Reputation
    1
    Join Date
    Oct 2008
    Posts
    31
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by ReidE96 View Post
    You've defined Fourth as a variable, which takes as its value the contents of txtFourth. First and Third are the same to txtFirst and txtThird. By doing txtFourth.Text = First + Third, you set the contents of txtFourth to the result of First + Third
    [/code]
    oh so if i remove the defention and write Fourth = txtFourth.Text then Fourth = First + Third it will work? or can't the name of fourth be changed since it containts the result of first and third? do i have to rename the txtbox name for it too work with Fourth? :I

  12. #12
    lolicon123's Avatar Member
    Reputation
    1
    Join Date
    Oct 2008
    Posts
    31
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh also the division by zero should it not be?:

    If Not txtSecond.Text = "/" And Third Or First = 0 Then
    txtFourth.Text = First / Third
    Else
    MsgBox "Divide by 0 error message here"
    End If

    in yours it looks like everytime you put a 0 in Third even if it's + * or - it will be error divided by zero still getting error else without if thought :Imy VB most really hate me


    here is full code
    Private Sub Command1_Click()

    First = CDbl(txtFirst.Text)
    Third = CDbl(txtThird.Text)

    If Trim(txtSecond.Text) = "+" Then
    txtFourth = First + Third

    ElseIf Trim(txtSecond.Text) = "*" Then
    txtFourth = First * Third

    ElseIf Trim(txtSecond.Text) = "-" Then
    txtFourth = First - Third

    If Not txtSecond.Text = "/" And Third Or First = 0 Then
    txtFourth.Text = First / Third
    Else
    MsgBox "Divide by 0 error message here"

    ElseIf Trim(txtSecond.Text) = "+,*,-,/" Then
    Else: MsgBox "Felaktigt räknesätt"

    End If

    End Sub
    Last edited by lolicon123; 11-25-2009 at 11:24 AM.

  13. #13
    ReidE96's Avatar Archer Authenticator enabled
    Reputation
    470
    Join Date
    Dec 2006
    Posts
    1,625
    Thanks G/R
    1/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The bit I added is to go inside the condition you already have for dividing

    Code:
    ElseIf Trim(txtSecond.Text) = "-" Then
    txtFourth = First - Third
     
    If Not txtSecond.Text = "/" And Third Or First = 0 Then
    txtFourth.Text = First / Third
    Else
    MsgBox "Divide by 0 error message here"
    End If
     
    ElseIf Trim(txtSecond.Text) = "+,*,-,/" Then
    Highlight in red Also, you have to do txtFourth.Text = First + Third (and so on) or it won't know what to do.

  14. #14
    lolicon123's Avatar Member
    Reputation
    1
    Join Date
    Oct 2008
    Posts
    31
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hm well that triggers my other msgbox when using /.

    ElseIf Not (txtSecond.Text) = "/,*,-,+" Then
    MsgBox "felaktigt räknesätt"
    full:



    First = CDbl(txtFirst.Text)
    Third = CDbl(txtThird.Text)


    If Trim(txtSecond.Text) = "+" Then
    txtFourth.Text = Val(txtFirst) + Val(txtThird)

    ElseIf Trim(txtSecond.Text) = "*" Then
    txtFourth.Text = txtFirst * txtThird

    ElseIf Trim(txtSecond.Text) = "-" Then
    txtFourth.Text = txtFirst - txtThird

    If Not txtSecond.Text = "/" And Third Or First = 0 Then
    txtFourth.Text = First / Third
    Else
    MsgBox "Divide by 0 error message here"
    End If

    ElseIf Not (txtSecond.Text) = "/,*,-,+" Then
    MsgBox "felaktigt räknesätt"

    End If


    i suppose you mean for it to be like this?

    man i don't get how it can trigger the second msgbox when using / it's like it's ignoring just that / of that part of the code :S gaaah
    Last edited by lolicon123; 11-25-2009 at 12:52 PM.

  15. #15
    ReidE96's Avatar Archer Authenticator enabled
    Reputation
    470
    Join Date
    Dec 2006
    Posts
    1,625
    Thanks G/R
    1/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, I mean:

    Code:
    First = CDbl(txtFirst.Text)
    Third = CDbl(txtThird.Text)
     
    If Trim(txtSecond.Text) = "+" Then
        txtFourth.Text = First + Third
     
    ElseIf Trim(txtSecond.Text) = "*" Then
        txtFourth.Text = First * Third
     
    ElseIf Trim(txtSecond.Text) = "-" Then
        txtFourth.Text = First - Third
     
    ElseIf Trim(txtSecond.Text) = "/" Then
        If Not Third = 0 Then
            txtFourth.Text = First / Third
        Else
            MsgBox "Divide by 0 error message here"
        End If
    
    ElseIf Not (txtSecond.Text) = "/,*,-,+" Then
         MsgBox "felaktigt räknesätt"
     
    End If

Page 1 of 2 12 LastLast

Similar Threads

  1. The Newbie Guide
    By Bossman4 in forum World of Warcraft Guides
    Replies: 12
    Last Post: 11-07-2006, 09:55 PM
  2. Tanking For Dummies Part 2: There's a Crowd
    By Krazzee in forum World of Warcraft Guides
    Replies: 1
    Last Post: 06-14-2006, 07:46 AM
  3. Tanking For Dummies Part 1: The Basics
    By Krazzee in forum World of Warcraft Guides
    Replies: 1
    Last Post: 06-14-2006, 07:41 AM
  4. ZG Guides (Part 2)
    By Cush in forum World of Warcraft Guides
    Replies: 0
    Last Post: 05-28-2006, 03:01 PM
  5. Jump to any height (without any 3rd part apps) MASSIVE Exploit!
    By Matt in forum World of Warcraft Exploits
    Replies: 17
    Last Post: 03-27-2006, 09:53 PM
All times are GMT -5. The time now is 04:01 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search