Results 1 to 6 of 6

Thread: Need help with a simple code

  1. #1
    Join Date
    Jan 2005
    Posts
    252
    Rep Power
    0

    Post Need help with a simple code

    Hi guys,
    I am soliciting some help with writing a simple (pref VB or ArcObjects) code...its basically to accept a value from the user, divide that value, and then the result is added to another value - which is the output. Wit a few constraints....lemme see how best i can explain....

    Enter Length (user enters length)
    y = Length divided by 10.56 (static value)
    Enter FrL (must be odd #) or FrR (must be even #) - user enters fr right or fr left #
    add the value of y to fr right or fr left #
    result!!

    ************************************************** ******************

    let x = number entered by user
    let y = x / 10.56
    display y
    let t = frL or frR (odd (frL) or even (frR) number entered by user)
    let z = y + t
    display z



    constraints -
    1.
    if t is an odd number, then z must be odd, (rounded to closest odd number)
    else, if t is even then z must be even (round to closest even #)

    2. z must be greater than or equal to t

    Thanks to anyone who can assist!!
    JA-MEK-I-CAN

  2. #2
    Join Date
    Jan 2009
    Posts
    2,404
    Rep Power
    0

    Default

    I don't do VB, but I did QBasic back in the day. Don't even know what ArcObjects is . I do C++/C#. You'll have to change this to your code format:

    Code:
    INPUT x
    y = x / 10.56
    PRINT y
    INPUT t
    z = y + t
    
    IF ( t / 2 ) <> INT( t / 2 ) THEN   ; t is odd.
    
       IF ( z / 2 ) <> INT( z / 2 ) THEN   ; z is odd.
          PRINT INT(z)
    
       ELSE
          PRINT INT(z) + 1
       ENDIF
    
    ELSE
    
       IF ( z / 2 ) = INT( z / 2 ) THEN   ; z is even.
          PRINT INT(z)
    
       ELSE
          PRINT INT(z) + 1
       ENDIF
    ENDIF
    BTW, it looks like you may have a problem meeting your second constraint if the user enters a value under 10.56. That could be a potential bug.

    Make sure the code works with test data, and HAVE FUN!
    Last edited by Skele Drew; Mar 11, 2009 at 09:18 PM. Reason: Finished the code, I think...
    Rooted OnePlus 2 64GB Ed, Android 5.1.1 OxygenOS ; on teifin' AT&T's network; Rooted ASUS Transformer TF101 w/ dock, Android 5.1 KatKiss; Laptop: ASUS X550C, 2.0GHzx2, 8GB, 512GB SSD, Kubuntu 15.10;
    Facebook page: Skeleville Technology Solutions

  3. #3
    Join Date
    Jan 2005
    Posts
    252
    Rep Power
    0

    Default

    Quote Originally Posted by Skele Drew View Post
    I don't do VB, but I did QBasic back in the day. Don't even know what ArcObjects is . I do C++/C#. You'll have to change this to your code format:

    Code:
    INPUT x
    y = x / 10.56
    PRINT y
    I don't get the second part of your explanation. What's FrL and FrR? What are you trying to achieve? But you can use something like this to check for odd/even numbers:

    Code:
    IF ( frl / 2 ) <> INT( frl/2 ) THEN
    ;action if 'frl' is odd.
    ELSE
    ;action if even.
    ENDIF
    BTW, it looks like you may have a problem meeting your second constraint if the user enters a value under 10.56. That could be a potential bug.
    Hey, thanks for this, the second part is pretty straight forward, maybe the frL and frR confused you. All that i need is for the user to enter a whole number, and do the calculation. But the code should check whether the number entered odd or even, and the result should be the odd if odd or even if even was entered. As long as it is OO codes it should be able to work i presume, maybe a few parameter changes. In order to mitigate getting the bug, even if the number is less thn 10.56, when added to the smallest whole number (1) it should be ok....thanks for any further help.
    Last edited by angeleta; Mar 11, 2009 at 08:37 PM.
    JA-MEK-I-CAN

  4. #4
    Join Date
    Jan 2009
    Posts
    2,404
    Rep Power
    0

    Default

    Think I finished the code in the original post. I'm really rusty in QB so there may be a few issues. Ensure you thoroughly test the code. Could have this done much better (and shorter) in C#.

    PS: You could insert an input check to ensure the user doesn't enter a number under 10.56 or something.
    Last edited by Skele Drew; Mar 11, 2009 at 09:25 PM.
    Rooted OnePlus 2 64GB Ed, Android 5.1.1 OxygenOS ; on teifin' AT&T's network; Rooted ASUS Transformer TF101 w/ dock, Android 5.1 KatKiss; Laptop: ASUS X550C, 2.0GHzx2, 8GB, 512GB SSD, Kubuntu 15.10;
    Facebook page: Skeleville Technology Solutions

  5. #5
    Join Date
    Aug 2002
    Posts
    6,223
    Rep Power
    0

    Default

    This sounds very much like a homework assignment but I'll answer it anyway...
    let x = number entered by user
    let y = x / 10.56
    display y
    let t = frL or frR (odd (frL) or even (frR) number entered by user)
    let z = y + t
    display z

    constraints -
    1.
    if t is an odd number, then z must be odd, (rounded to closest odd number)
    else, if t is even then z must be even (round to closest even #)

    2. z must be greater than or equal to t

    Thanks to anyone who can assist!!
    Let's see here:

    let x = number entered by user
    let y = x / 10.56
    display y
    Code:
    Dim x as Integer
    Dim y as Integer
    
    x = InputBox("Enter first Number", "Number1")
    ' Insert check to confirm input is actually a number before passing to y!
    ' It may be best to use x as String and then convert input to a number...
    y = int(x / 10.56)
    msgbox("The result is:  " & y)
    And then
    let t = frL or frR (odd (frL) or even (frR) number entered by user)
    let z = y + t
    display z
    Code:
    Dim t as Integer
    Dim u as Integer
    Dim z as Integer
    t = Inputbox("Enter Second Number", "Number2")
    ' As above, confirm input is actually a number!
    u = t mod 2
    If (u = 0) then MsgBox("Your Number is Even")
             Else MsgBox("Your Number is Odd")
    Endif
    ' For z to be the same odd or even as t, then y must be even:
    If y mod 2 == 0 then y= y + 1
    z = t + y
    MsgBox("Your Final number is: " & z)
    I think that should be correct...
    Last edited by ramesh; Mar 11, 2009 at 11:06 PM.
    .
    PC - Ubuntu 15.04 64bit Desktop
    HP Pav G60-236US 3GB RAM Laptop, Ubuntu 15.04 64bit and Win7 Home

    "So Daddy, how come you telling me stealing not right when YOU copying DVDs? How come? How Come?"


    RIP Ramesh ...

  6. #6
    Join Date
    Jan 2005
    Posts
    252
    Rep Power
    0

    Default

    Thanks guys, your help is much appreciated....will let u kno how it goes
    JA-MEK-I-CAN

Posting Permissions

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