Hey there! Sign in to join this conversationNew here? Join for free

AQA COMP1 - Possible Question problem - June 3rd 2013 - Skeleton Program Watch

    • Thread Starter
    Offline

    0
    ReputationRep:
    Hi I am having issues with trying to add validation so that it checks if the user has entered an integer and is also NOT negative for the Steganography (start and end positions).


    The Question I was given:

    Add validation to the program so that the start and end positions used in the Steganography are checked to ensure that both are numeric and that the start is non-negative and is less than the end.
    (GetPositionsToUse)



    Program Code:

    Sub GetPositionsToUse(ByRef StartPosition As Integer, ByRef EndPosition As Integer)

    Console.Write("Please enter the start position to use in the file: ")
    StartPosition = Console.ReadLine

    Console.Write("Please enter the end position to use in the file: ")
    EndPosition = Console.ReadLine

    End Sub
    Offline

    14
    ReputationRep:
    You can check if a number is negative by comparing it to zero, and you can check it's an integer by rounding it to the nearest integer and checking the two numbers are the same, or by using Integer.TryParse. (I think that's what it's called )
    • Thread Starter
    Offline

    0
    ReputationRep:
    I tried using 'IsNumeric' with a If Statement but it crashes when its at this stage:
    StartPosition = Console.ReadLine

    I'm guessing its because the data type for StartPosition that was declared is an Integer.

    So I'll change it to string and see if it works this time.
 
 
 
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • Poll
    What's your favourite Christmas sweets?
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

    Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

    Quick reply
    Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.