Results 1 to 5 of 5

Thread: Make sure one input is always bigger than the other

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2009
    Posts
    3

    Make sure one input is always bigger than the other

    Hi

    Please help me with this code

    I would like to know how to make my l(length) always bigger than w(width).
    eg: message box "Make Length bigger than width" and the 2 inputs, and 3 outputs = [blank]

    Code:
    Public Class Form1
    Dim min, max As Integer
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim l, w, tl, r, x, rr As Integer
    
    Call numbercheck(TextBox1.Text, 1, 30)
    If numbercheck(TextBox1.Text, 1, 30) = True Then
    l = TextBox1.Text
    Else : MsgBox("Enter a number between 1 and 30 in the Length box") : TextBox1.Text = ""
    End If
    
    Call numbercheck(TextBox2.Text, 1, 20)
    If numbercheck(TextBox2.Text, 1, 20) = True Then
    w = TextBox2.Text
    Else : MsgBox("Enter a number between 1 and 20 in the Width box") : TextBox2.Text = ""
    End If
    
    If w > l Then MsgBox("Make Length greater than Width") : TextBox1.Text = "" : TextBox2.Text = ""
    
    
    
    
    
    'rolls'
    r = (w / 5)
    rr = Math.Ceiling(w / 5)
    TextBox4.Text = r
    
    
    'total length'
    tl = (r * l)
    TextBox3.Text = tl
    
    'excess carpet'
    x = (rr * 30) - tl
    TextBox5.Text = x
    
    TextBox3.Text = tl
    TextBox4.Text = r
    TextBox5.Text = x
    
    
    End Sub
    Function numbercheck(ByVal value, ByVal min, ByVal max)
    If IsNumeric(value) = True Then
    numbercheck = True
    If value > max Then numbercheck = False
    If value < min Then numbercheck = False
    Else : numbercheck = False
    End If
    
    End Function
    
    Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click
    TextBox1.Text = ""
    TextBox2.Text = ""
    TextBox3.Text = ""
    TextBox4.Text = ""
    TextBox5.Text = ""
    End Sub
    End Class
    Last edited by ilvbvm; Oct 29th, 2009 at 02:23 AM.

  2. #2
    Addicted Member
    Join Date
    Oct 2009
    Posts
    212

    Re: Make sure one input is always bigger than the other

    It helps if you use the code button when posting....
    Like So...
    Code:
    Public Class Form1
    Dim min, max As Integer
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim l, w, tl, r, x, rr As Integer
    
    Call numbercheck(TextBox1.Text, 1, 30)
    If numbercheck(TextBox1.Text, 1, 30) = True Then
    l = TextBox1.Text
    Else : MsgBox("Enter a number between 1 and 30 in the Length box") : TextBox1.Text = ""
    End If
    
    Call numbercheck(TextBox2.Text, 1, 20)
    If numbercheck(TextBox2.Text, 1, 20) = True Then
    w = TextBox2.Text
    Else : MsgBox("Enter a number between 1 and 20 in the Width box") : TextBox2.Text = ""
    End If
    
    If w > l Then MsgBox("Make Length greater than Width") : TextBox1.Text = "" : TextBox2.Text = ""
    
    
    
    
    
    'rolls'
    r = (w / 5)
    rr = Math.Ceiling(w / 5)
    TextBox4.Text = r
    
    
    'total length'
    tl = (r * l)
    TextBox3.Text = tl
    
    'excess carpet'
    x = (rr * 30) - tl
    TextBox5.Text = x
    
    TextBox3.Text = tl
    TextBox4.Text = r
    TextBox5.Text = x
    
    
    End Sub
    Function numbercheck(ByVal value, ByVal min, ByVal max)
    If IsNumeric(value) = True Then
    numbercheck = True
    If value > max Then numbercheck = False
    If value < min Then numbercheck = False
    Else : numbercheck = False
    End If
    
    End Function
    
    Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click
    TextBox1.Text = ""
    TextBox2.Text = ""
    TextBox3.Text = ""
    TextBox4.Text = ""
    TextBox5.Text = ""
    End Sub
    End Class
    Have you tried Google?

  3. #3
    Addicted Member
    Join Date
    Oct 2009
    Posts
    212

    Re: Make sure one input is always bigger than the other

    What You're asking is very simple.
    You need to create a function whos signature is basically. This code is messy AT best...
    Code:
    Private Function Test(byval L as integer, byval w as integer) as boolean
    If l > w then
    Return True
    Else
    TextBox1.Text = ""
    TextBox2.Text = ""
    TextBox3.Text = ""
    TextBox4.Text = ""
    TextBox5.Text = ""
    MessageBox.Show("Length must be greater than width")
    Return False
    End Function
    Have you tried Google?

  4. #4
    New Member
    Join Date
    Oct 2009
    Posts
    1

    Re: Make sure one input is always bigger than the other

    Quote Originally Posted by 7777 View Post
    What You're asking is very simple.
    You need to create a function whos signature is basically. This code is messy AT best...
    Code:
    Private Function Test(byval L as integer, byval w as integer) as boolean
    If l > w then
    Return True
    Else
    TextBox1.Text = ""
    TextBox2.Text = ""
    TextBox3.Text = ""
    TextBox4.Text = ""
    TextBox5.Text = ""
    MessageBox.Show("Length must be greater than width")
    Return False
    End Function
    Where abouts would you place you're example in ilvbvm's code?

  5. #5
    Addicted Member
    Join Date
    Oct 2009
    Location
    Clive, IA in America!!!!
    Posts
    204

    Re: Make sure one input is always bigger than the other

    In the Public Class Form1 and call it in the Button1_Click event...

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