2 Attachment(s)
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.
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?
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.
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?
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.
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:
Private dExample As Date 'Module level variable
Private Sub Command1_Click()
If ValidateForm Then
dExample = CDate(Text1.Text)
End If
End Sub
Private Function ValidateForm() As Boolean
Dim sTest As String
sTest = Trim$(Text1.Text)
If Len(sTest) <> 0 Then
If IsDate(sTest) Then
If CDate(sTest) > Now Then
MsgBox "Cannot use future date"
Else
ValidateForm = True
End If
Else
MsgBox "Not a valid date"
End If
Else
MsgBox "Nothing entered"
End If
End Function
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?
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:
'In Form1
Public Sub Execute()
Call Command1_Click
End Sub
'Startup Sub
Public Sub AbuseForm()
Dim fTarget As Form1, sValues() As String, lIndex As Long
sValues = Split("1/1/2006,kkkhh,,15/12/06,020205", ",")
For lIndex = LBound(sValues) To UBound(sValues)
Set fTarget = New Form1
fTarget.Show vbModeless
fTarget.Text1 = sValues(lIndex)
fTarget.Execute
Unload fTarget
Next lIndex
Set fTarget = Nothing
End Sub
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.
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:
Public Sub Execute() 'Public passthrough sub to simulate a button click.
Call Command1_Click 'Executes the button click code.
End Sub
'Startup Sub
Public Sub AbuseForm()
Dim fTarget As Form1, sValues() As String, lIndex As Long
sValues = Split("1/1/2006,kkkhh,,15/12/06,020205", ",") 'Create an array of test items.
For lIndex = LBound(sValues) To UBound(sValues) 'Loop through each item in the array.
Set fTarget = New Form1 'Create an instance of the target form.
fTarget.Show vbModeless 'Show it modeless (so it will run concurrently).
fTarget.Text1 = sValues(lIndex) 'Put the current test value into the textbox.
fTarget.Execute 'Call the button click pass-through.
Unload fTarget 'Unload the form (to reset values).
Next lIndex
Set fTarget = Nothing 'Release the reference.
End Sub
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)?