Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Help with VB looping

  • 01-01-2003 11:56pm
    #1
    Closed Accounts Posts: 1,152 ✭✭✭


    hey everyone! right my first post here at boards.ie , ive been meaning to register a lot sooner but lots of college work and the like. so anyway my problem.
    im having difficulty writing vb code.in our asignment a user has 3 chances to fill out a registration form if some data is entered incorrectly . after this if on the third attempt the data is still incorrect then the user must start over again.
    any help with this would be greatly appriciated.
    thanks
    sound_wave


Comments

  • Moderators, Music Moderators, Recreation & Hobbies Moderators Posts: 9,389 Mod ✭✭✭✭Lenny


    Sounds like tallaght it boring stuff :D


  • Closed Accounts Posts: 8,264 ✭✭✭RicardoSmith


    What exactly do need help with? Planning the code, writing it or both. All you have to do is count the number of attempts and if its 3 or more then reset the form. Its very basic VB, surely you must have a book that shows you how to do that much? I have a cheapo "Learn VB in 10mins" book (don't laugh it was handy at the time) that I got when I started and it shows you how to do most of this.


  • Closed Accounts Posts: 1,152 ✭✭✭sound_wave


    ok..well here is the vb code so far......



    Private Sub cmdContinue_Click()



    'Check length of characters in text boxes and ensures that the_
    'entered Data Is correct



    If Len(txtName.Text) = o Then
    MsgBox "Enter a Name", vbInformation, "Data Missing"
    ElseIf Len(txtName.Text) > 30 Then
    MsgBox "Name must be less than 30 characters in length", vbExclamation, "Please Enter Name"

    With txtName
    .Text = " " 'clears txtName
    .SetFocus 'resets cursor at txtName

    End With


    End If

    If Len(txtAddress.Text) = 0 Then
    MsgBox "Enter an Address", vbInformation, "Data Missing"
    ElseIf Len(txtAddress.Text) > 30 Then
    MsgBox "Address must be less than 50 characters in length", vbExclamation, " Please Enter Address"

    With txtAddress
    .Text = " " 'clears txtAddress
    SetFocus 'resets cursor to txtAddress
    End With

    End If

    If Len(txtTown.Text) = 0 Then
    MsgBox "Enter your Town", vbInformation, "Data Missing"
    ElseIf Len(txtTown.Text) > 20 Then
    MsgBox "Town Name must be less than 20 characters in length", vbExclamation, "Please enter Town Name"

    With txtTown
    .Text = " " 'clears txtTown
    SetFocus 'resets cursor at txtTown
    End With

    End If

    If Len(cboCounty.Text) = o Then
    MsgBox "Please enter County", vbInformation, "Data Missing"
    ElseIf Len(cboCounty.Text) > 10 Then
    MsgBox " County must be less than 10 characters in length", vbexclamtion, "Please Enter County"
    End If

    If Len(txtRsi.Text) = 0 Then
    MsgBox "Please enter RSI Number", vbInformation, "Data Missing"
    ElseIf Len(txtRsi.Text) > 8 Then
    MsgBox "RSI Number must be less than 8 characters in length", vbExclamation, "Please enter RSI Number"

    With txtRsi
    .Text = ""
    SetFocus
    End With

    End If

    'asks user if s/he sure of continuing
    Dim intResponse As Integer
    intResponse = MsgBox("Are you sure you want to continue?", vbYesNo, "Information")


    If intResponse = vbYes Then
    frmMarital.Show vbModal
    End If






    End Sub

    Private Sub cmdExit_Click()
    'Ends the program
    End

    End Sub


    Private Sub mnuAbout_Click()
    'displays info about the program
    MsgBox "Programmed by Patrick Crowley", vbInformation, "The Revenue Commission:Income Tax Calculator"

    End Sub

    Private Sub mnuFileClose_Click()
    'ends the program
    End

    End Sub


    Private Sub mnuFilePrint_Click()
    'prints the form
    PrintForm

    End Sub

    Private Sub txtAddress_Click()

    'displays an inputbox into which user enters address
    txtAddress.Text = InputBox("Please Enter Your Address", "Address")

    End Sub

    Private Sub txtAreaCode_Click()
    'displays an inputbos into which the user enters their area code
    txtAreaCode.Text = InputBox("Please Enter Your Area Code for your County", " Area Code ")


    End Sub

    Private Sub txtHomeNumber_Click()
    'displays an inputbox into which the user enters their telephone number
    txtHomeNumber.Text = InputBox("Please Enter Your Home Telephone Number", "Home Telephone Number")

    End Sub

    Private Sub txtMobile_Click()
    'displays an inputbox into which the user enters their mobile number
    txtMobile.Text = InputBox("Please Enter Your Mobile Number", " Mobile Phone Number")

    End Sub

    Private Sub txtName_Click()
    'displays an input box into which user enters name
    txtName.Text = InputBox("Please Enter Your Name", "Name")

    End Sub

    Private Sub txtRsi_Click()
    'displays an iputbox into which the user enters their RSI number
    txtRsi.Text = InputBox("Please Enter Your RSI Number", "RSI Number")


    End Sub

    Private Sub txtTown_Click()
    'displays an inputbox into which user enters town
    txtTown.Text = InputBox("Please Enter Town Name", "Town")


    End Sub


    so where should i put the counter? and should i use the loadMe or the frmname.show method to show the form again?
    thanks alot


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    Originally posted by sound_wave
    im having difficulty writing vb code.in our asignment a user has 3 chances to fill out a registration form if some data is entered incorrectly . after this if on the third attempt the data is still incorrect then the user must start over again.
    any help with this would be greatly appriciated.
    Help? You never told us what your problem was.

    Unless you have a specific problem, fsck off and do your own homework.


  • Moderators, Society & Culture Moderators Posts: 2,688 Mod ✭✭✭✭Morpheus


    how do u know the data is incorrect?

    can they get 3 "data missing" messages or do u have a final last command button they click once the last item is entered on the registration form? if so this last command_click is where you could increment the counter.

    do u have a data checking function? just explain how u know when the data entered is incorrect and then we can probably help u. :confused:


  • Advertisement
  • Closed Accounts Posts: 52 ✭✭jscully


    :confused: I'm not too sure if I'm picking you up correctly, but ....

    You should have a counter that you set to zero in the Form_Load() sub.

    You should have a sub rountine that validates the form. ie. that applies the rules that you need, such as checking that all required text fields contain data etc.

    When the user hits the Submit button, you should increase the counter by one, and call the validation sub rountine to check the form. If there is a problem, alert the user and return to the form.

    If the user screws up three times, reload the form so that they can start all over again!

    Hope this helps

    Joe


  • Closed Accounts Posts: 8,264 ✭✭✭RicardoSmith


    Be neater to hold all the data in an array too. Make your code thats validating the data more concise.


  • Closed Accounts Posts: 1,152 ✭✭✭sound_wave


    thanks for all the useful info ...got it to work so no more me annoying moderators or anything like that... phew...unless of course i have another question about my homework..thanks once again


  • Closed Accounts Posts: 52 ✭✭jscully


    I can't believe that I typed "rountine" twice instead of "routine"! I'll have to stop drinking vodka whilst surfing the net.;)


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    Originally posted by sound_wave
    thanks for all the useful info ...got it to work so no more me annoying moderators or anything like that... phew...unless of course i have another question about my homework..thanks once again
    You posted a project specification/assignment, not a question. In effect asking others to do the project for you. Then you posted a pile of code and expected us to debug or rewrite it for you. My response was mild in comparison to what would have been said to you on Usenet.

    In general questions that show that you’ve made an effort defining and solving your problem first (that you’ve both RTFM’ed and STFW’ed) will be treated with greater respect.

    You’ll know better next time ;)


  • Advertisement
  • Closed Accounts Posts: 1,152 ✭✭✭sound_wave


    sorry..i didnt mean for ye to pick it up like that..i was just looking for help since college wasnt open..i see now why the post could have looked like that but thats not what i had intended!

    indeed i will know better the next time! i apologise once again!

    ;)


Advertisement