Results 1 to 11 of 11

Thread: Design an algorithm to validate and store

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2006
    Posts
    7

    Angry Design an algorithm to validate and store

    Im new to VB and i have been reading alot into it.

    I have come across 4 problems in which i have had trouble completing.
    I have little idea of what is required but i dont know how to do it.

    1) Design an algorithm to validate the data controls on the form and store the values into the appropriate variables converting the data type if necessary.

    2) Design sample data sets that will test your algorithm and carry out a desk check.

    3) When the algorithm checks out OK design VB code to implement the algorithm.

    4) Add your code to the existing project code and test using the same data used to test the algorithm.

    I will post what i have done but i need help with writing the algorithm. If anyone can help me i woul dreally appreciate it and will be very grateful for your help. Iv tried asking friends but they have no clue of coding. Please.
    Attached Files Attached Files
    Last edited by bseos; Aug 10th, 2006 at 10:34 PM.

  2. #2
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Re: Design an algorithm to validate and store

    What types of data need to be entered?
    In what formats does the data need to be?
    Are there constraints for the values of the data?

    How do you think the user could enter the data wrongly?

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2006
    Posts
    7

    Re: Design an algorithm to validate and store

    Are these question directed at me? or are they simplified questions of th equestions i posted. Anyway, i still dont know how to perform that. Can u please do a sample code or something and tell me how to implement it.

  4. #4
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Re: Design an algorithm to validate and store

    The questions are directed at you.
    If you answer them you should get a bit closer to the algorithm.

    Is this homework?

  5. #5
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Design an algorithm to validate and store

    Could you possibly zip up your project instead of using rar? I can't read rar files and I don't want to install WinRAR.

  6. #6
    Fanatic Member Comintern's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    826

    Re: Design an algorithm to validate and store

    This should give you the basic idea. Command1 would be the button that gets things rolling, and it calls the validation function to see if it should proceed. The validation function checks a date field to see if it was empty, make sure it's a valid date, and makes sure the date isn't in the future.
    VB Code:
    1. Private dExample As Date        'Module level variable
    2.  
    3. Private Sub Command1_Click()
    4.  
    5.     If ValidateForm Then
    6.         dExample = CDate(Text1.Text)
    7.     End If
    8.  
    9. End Sub
    10.  
    11. Private Function ValidateForm() As Boolean
    12.  
    13.     Dim sTest As String
    14.    
    15.     sTest = Trim$(Text1.Text)
    16.     If Len(sTest) <> 0 Then
    17.         If IsDate(sTest) Then
    18.             If CDate(sTest) > Now Then
    19.                 MsgBox "Cannot use future date"
    20.             Else
    21.                 ValidateForm = True
    22.             End If
    23.         Else
    24.             MsgBox "Not a valid date"
    25.         End If
    26.     Else
    27.         MsgBox "Nothing entered"
    28.     End If
    29.  
    30. End Function

  7. #7

    Thread Starter
    New Member
    Join Date
    Aug 2006
    Posts
    7

    Re: Design an algorithm to validate and store

    Do i need to include a deskcheck (test data/table)? How woul di make the program check and compare the data entered against the test data?

  8. #8
    Fanatic Member Comintern's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    826

    Re: Design an algorithm to validate and store

    What I would do would be to create a startup sub that abuses the form. Make a public function like "Execute" on the form that you can call from your sub.
    VB Code:
    1. 'In Form1
    2. Public Sub Execute()
    3.  
    4.     Call Command1_Click
    5.  
    6. End Sub
    7.  
    8. 'Startup Sub
    9. Public Sub AbuseForm()
    10.  
    11.     Dim fTarget As Form1, sValues() As String, lIndex As Long
    12.    
    13.     sValues = Split("1/1/2006,kkkhh,,15/12/06,020205", ",")
    14.    
    15.     For lIndex = LBound(sValues) To UBound(sValues)
    16.         Set fTarget = New Form1
    17.         fTarget.Show vbModeless
    18.         fTarget.Text1 = sValues(lIndex)
    19.         fTarget.Execute
    20.         Unload fTarget
    21.     Next lIndex
    22.    
    23.     Set fTarget = Nothing
    24.  
    25. End Sub

  9. #9

    Thread Starter
    New Member
    Join Date
    Aug 2006
    Posts
    7

    Re: Design an algorithm to validate and store

    Im sorry but i dont understand the coding. I need some to go through th ecoding step by step so i know what it is achieving. Please. I know im asking for alot of asistance but it is the only way i will learn. Thankyou.

  10. #10
    Fanatic Member Comintern's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    826

    Re: Design an algorithm to validate and store

    Quote Originally Posted by bseos
    Im sorry but i dont understand the coding. I need some to go through th ecoding step by step so i know what it is achieving. Please. I know im asking for alot of asistance but it is the only way i will learn. Thankyou.
    No problem. I added comments to all of the code lines. This assumes that the form you are testing is Form1, with a textbox Text1 and a command button Command1.
    VB Code:
    1. Public Sub Execute()        'Public passthrough sub to simulate a button click.
    2.  
    3.     Call Command1_Click     'Executes the button click code.
    4.  
    5. End Sub
    6.  
    7. 'Startup Sub
    8. Public Sub AbuseForm()
    9.  
    10.     Dim fTarget As Form1, sValues() As String, lIndex As Long
    11.    
    12.     sValues = Split("1/1/2006,kkkhh,,15/12/06,020205", ",") 'Create an array of test items.
    13.    
    14.     For lIndex = LBound(sValues) To UBound(sValues)         'Loop through each item in the array.
    15.         Set fTarget = New Form1                             'Create an instance of the target form.
    16.         fTarget.Show vbModeless                             'Show it modeless (so it will run concurrently).
    17.         fTarget.Text1 = sValues(lIndex)                     'Put the current test value into the textbox.
    18.         fTarget.Execute                                     'Call the button click pass-through.
    19.         Unload fTarget                                      'Unload the form (to reset values).
    20.     Next lIndex
    21.    
    22.     Set fTarget = Nothing                                   'Release the reference.
    23.  
    24. End Sub

  11. #11

    Thread Starter
    New Member
    Join Date
    Aug 2006
    Posts
    7

    Re: Design an algorithm to validate and store

    THankyou Comintern for your help, but is that to validate the date?

    How would i get it to compare it against the data in a table(in excel)?

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