Results 1 to 6 of 6

Thread: Division with remainders

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2007
    Posts
    44

    Division with remainders


    I made this for my mom to check my sisters math homework
    Code:
    Option Explicit
    Dim a As Double
    Dim sd As Double
    Dim sc As Double
    
    Private Function RoundOff(ByVal value As Double, ByVal digits As Integer) As Double
    Dim move As Double
    
        move = 10 ^ digits
        RoundOff = CInt(value * move) / move
    End Functiona
    
    Private Sub Command1_Click()
    On Error Resume Next
    
    sc = Text1.Text / Text2.Text
    sd = RoundOff(CSng(sc), CInt(0))
    
    If sd > sc Then
    sd = sd - 1
    End If
    
    a = Text1.Text Mod Text2.Text
    Label1.Caption = sd & " r " & a
    Command2.Enabled = True
    net:
    Resume Next
    End Sub
    
    Private Sub Command2_Click()
    On Error Resume Next
    Text3.Text = sd & " * " & Text2.Text & " = " & Val(Text2.Text * sd)
    Text3.SetFocus
    SendKeys Text3.Text & "{Enter}"
    Text3.Text = Val(Text2.Text * sd) & " + " & a & " = " & Val(Text2.Text * sd + a)
    End Sub
    
    
    Private Sub Text1_Click()
    Text1.Text = ""
    End Sub
    
    
    Private Sub Text2_Click()
    Text2.Text = ""
    End Sub
    Project files

    Also: i would like someone to tell me how to use the enter key with text1.text = "Enter"?
    Attached Files Attached Files

  2. #2
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Division with remainders

    Quote Originally Posted by Snowfox
    Also: i would like someone to tell me how to use the enter key with text1.text = "Enter"?

    Use the Textbox's KeyUp Event:

    vb Code:
    1. Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
    2.     If KeyCode = 13 Then 'Check if return Key was pressed
    3.         Call Command1_Click
    4.     End If
    5. End Sub


    But you will have to build in some sort of error tapping just in case the user does enter a value in either of the Textboxes. Otherwise a nice piece of code.
    Last edited by Mark Gambo; Aug 26th, 2007 at 02:13 PM.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2007
    Posts
    44

    Re: Division with remainders

    Thats not what i meant, i mean like in a multi line enabled textbox how do i use Text1.text = "{enter}" Which would skip a line.

  4. #4
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Division with remainders

    Quote Originally Posted by Snowfox
    Thats not what i meant, i mean like in a multi line enabled textbox how do i use Text1.text = "{enter}" Which would skip a line.

    I don't understand? If you hold down the Control Key and Press the Return key the cursor will then go to the next line in the textbox provided that the Multiline property is set to True.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  5. #5
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Division with remainders

    Text1.Text = Text1.Text & vbCrLf

    this? To add a line change to the textbox?


    Has someone helped you? Then you can Rate their helpful post.

  6. #6
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Division with remainders

    This seems overcoded to me. Much simpler would be:
    Code:
    Private Sub Command1_Click()
        Dim lngDividend As Long
        Dim lngDivisor As Long
        Dim lngQuotient As Long
        Dim lngRemainder As Long
    
        lngDividend = Val(Text1.Text)
        lngDivisor = Val(Text2.Text)
        lngQuotient = lngDividend \ lngDivisor
        lngRemainder = lngDividend Mod lngDivisor
        Label1.Caption = lngQuotient & " r " & lngRemainder
        Text3.Text = lngQuotient & " * " & lngDivisor & " = " & lngQuotient * lngDivisor & vbNewLine & _
            lngQuotient * lngDivisor & " + " & lngRemainder & " = " & lngQuotient * lngDivisor + lngRemainder
    End Sub

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