Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

vb looping..here we go again

  • 10-01-2003 11:35PM
    #1
    Closed Accounts Posts: 1,152 ✭✭✭


    right..after many hours pulling my hair out..i have the following problem concerning an input box and looping..

    the prob is as follows:

    i have a text box where the user must enter a telephone number, if s/he enters it wrong 3 times then the form resets..so , i check the value in the textbox using the IsNumeric function and using an if...then statement i begin the loop..however if i enter a non numeric , which results in a message box popping up and notifying the user that the date must be numeric..then if i enter numeric data into the input box the data enters the textbox but the input box pops up again..and again and again until the loop finishes and resets the form...

    :(
    as i said i really have tried everything with this..

    any help, even minimal would be greatly appreciated,

    thanks


Comments

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


    You're probably overcomplicating your nested loop logic. Keep it as simple as possible. Something like:
    Private Sub Command1_Click()
        Static iAttempt As Integer
        
        If IsNumeric(Text1.Text) Then
            'Number is Valid - Do Stuff
        Else
            iAttempt = iAttempt + 1
            MsgBox "Numeric value needed!"
        End If
        
        If iAttempt = 3 Then
            iAttempt = 0
            'Reset after 3 attemps - Do Stuff
        End If
    End Sub
    


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


    right... but if the value in the inputbox is true how do i write the code so this value is stored in the property of the textbox

    is it...
    dim intAtempt as integer

    for intAttempt = 0 to 2

    if isNumeric(txtNumber.text) = true then
    txtNumber.text = inputbox.text (i know this is wrong but i dont know what to do)
    else
    msgbox "Data must be numeric" , vbExclamation, "Incorrect Data"
    txtNumber.text = " "

    end if

    Next intAttempt


    is this correct apart from the issue concerning the inputbox?
    thanks


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


    Originally posted by sound_wave
    txtNumber.text = inputbox.text (i know this is wrong but i dont know what to do)
    You check the help files that come with VB, MSDN and Google for a tutorial to show you how, ffs.


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


    help files didnt come with the version i have of vb here at home..i only got a working edition..will do
    thanks


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


    not to worry figured it out...had to use an exit for statement is the nested if..then statement thanks for all the help Corinthian must appreciated!!:)
    thanks


  • Advertisement
Advertisement