Results 1 to 10 of 10

Thread: Text Box Calculations

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    123

    Text Box Calculations

    Ok I have 3 text boxed
    Text1
    Text2
    Text3

    In each Text box I have numbers

    Text1.Text = 30
    Text2.Text = 8
    Text3.Text = 25

    I have dimmed Solution to hold the calculation. I also have dimmed Text1, 2, & 3 but in this example Im just trying to point out my problem.

    My formula is set like this
    If Text2 < Text3 then
    Solution = Text3 - Text2 - 1

    The only time that the solution comes out correct, is when Im using double digits.

    This comes out correct-
    Text1.Text = 30
    Text2.Text = 08
    Text3.Text = 25

    This doesn't-
    Text1.Text = 30
    Text2.Text = 8
    Text3.Text = 25

    Does anyone know what the problem could be? Any help is greatly appreciated.

  2. #2
    Member
    Join Date
    Oct 2008
    Posts
    34

    Re: Text Box Calculations

    If Text2 =< Text3 then

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    123

    Re: Text Box Calculations

    Doesnt work.

  4. #4
    Junior Member
    Join Date
    Mar 2008
    Posts
    31

    Re: Text Box Calculations

    vb Code:
    1. Private Sub Command1_Click()
    2. Dim txt1 As Integer
    3. Dim txt2 As Integer
    4. Dim txt3 As Integer
    5.  
    6. txt1 = text1.Text
    7. txt2 = text2.Text
    8. txt3 = text3.Text
    9.  
    10. If txt2 < txt3 Then
    11.     Label1.Caption = txt3 - txt2 - 1
    12. End If
    13.  
    14. End Sub

    Here this worked. I allready tried it hope it helps.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    123

    Re: Text Box Calculations

    I need to have the information stored in memory because it is called in multiple places and having it stored in a label can sometimes cause errors. Here is my code-

    vb Code:
    1. Private Sub cmdcalculate_Click()
    2.  
    3. 'The Paremeters set for each value Dimmed on Form Load
    4. ArrearsDNM = txtarrearsdnm.Text
    5. ArrearsBC = txtarrearsbc.Text
    6. ArrearsDate = txtarrearsdate.Text
    7. ArrearsORP = txtarrearsorp.Text
    8. ArrearsOF = txtarrearsof.Text
    9. ArrearsNRP = txtarrearsnrp.Text
    10. ArrearsNF = txtarrearsnf.Text
    Last edited by UnKnOwNCoDe; Dec 2nd, 2008 at 12:16 PM.

  6. #6
    Junior Member
    Join Date
    Mar 2008
    Posts
    31

    Re: Text Box Calculations

    i just used the label to verify the calculation. thats just how i got it to work.

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Text Box Calculations

    You have to conver the text to a number in order to perform any math functions.
    Code:
    If Val(Text2.Text) =< Val(Text3.Text Then

  8. #8
    Hyperactive Member jp26198926's Avatar
    Join Date
    Sep 2008
    Location
    General Santos City, Philippines
    Posts
    310

    Re: Text Box Calculations

    Quote Originally Posted by UnKnOwNCoDe
    Ok I have 3 text boxed
    Text1
    Text2
    Text3

    In each Text box I have numbers

    Text1.Text = 30
    Text2.Text = 8
    Text3.Text = 25

    I have dimmed Solution to hold the calculation. I also have dimmed Text1, 2, & 3 but in this example Im just trying to point out my problem.

    My formula is set like this
    If Text2 < Text3 then
    Solution = Text3 - Text2 - 1

    The only time that the solution comes out correct, is when Im using double digits.

    This comes out correct-
    Text1.Text = 30
    Text2.Text = 08
    Text3.Text = 25

    This doesn't-
    Text1.Text = 30
    Text2.Text = 8
    Text3.Text = 25

    Does anyone know what the problem could be? Any help is greatly appreciated.
    i dont know.. if this correct..
    Code:
    If Val (Text2.Text) < val (Text3.Text) then
    Solution = Val(Text2.Text) -  Val(Text3.Text) -1
    "More Heads are Better than One"

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    123

    Re: Text Box Calculations

    Ah ok. Thanks a lot!
    I updated this portion

    VbCode Code:
    1. ArrearsDNM = Val(txtarrearsdnm.Text)
    2. ArrearsBC = Val(txtarrearsbc.Text)
    3. ArrearsDate = Val(txtarrearsdate.Text)
    4. ArrearsORP = Val(txtarrearsorp.Text)
    5. ArrearsOF = Val(txtarrearsof.Text)
    6. ArrearsNRP = Val(txtarrearsnrp.Text)
    7. ArrearsNF = Val(txtarrearsnf.Text)

    I didnt change this but it appears to be working correctly.

    VbCode Code:
    1. If ArrearsBC > ArrearsDate Then

  10. #10
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Text Box Calculations

    How did you declare your variables?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width