Hi

I have an if statement which checks if a value has been entered and if it hasnt it pops up with a message box and tells the user.

Now if the if statement is in the same Sub as the code that is executing it works fine, but if i put it into a seperate sub and call it from within the original sub it still executes the original code:

If AppVariables.CustName = "" Then
            MsgBox("You have to configure this report before it can be run." & (Chr(13)) & (Chr(10)) & "Go to Configuration > Configure to resolve this", MsgBoxStyle.Critical)
            Return
        End If

Now since i have put it into the seperate sub and the ok/cancel button is pressed it still continues with the rest of the code and of course fails as not all information has been entered.

I wondered if anyone could help

Regards

Hey maybe u could try running a select case?
or u could try making a function procedure?
BTW I think "Go to Configuration > Configure to resolve > should be changed to an underscore _
from what I understand in vb.net so far > is greater than sighn

hi

the problem isnt with the logic of the if statement, its the stopping of the code if the the string is empty when it is being called from a different procedure e.g

Public Sub CheckValues()

        If AppVariables.CustName = "" Then
            MsgBox("You have to configure this report before it can be run." & (Chr(13)) & (Chr(10)) & "Go to Configuration > Configure to resolve this", MsgBoxStyle.Critical)
            Return
        End If

    End Sub



Public sub maincode()

call checkvalues()  ' Check to see if text has been entered into the variables


*****Run main code here


End Sub

now if the string is empty in 'checkvalues' it does return but by returning it still continues with the originating sub, how can i get it to stop doing that?

many thanks

u want after error message shown and button ok pressed the task will stopped?
try this code :

If AppVariables.CustName = "" Then
      If (MsgBox("You have to configure this report before it can be run." & (Chr(13)) & (Chr(10)) & "Go to Configuration > Configure to resolve this", MsgBoxStyle.Critical)) = MsgBoxResult.OK Then
                ' do what ever to stop...
      End If
End If

sorry i dont really follow - the checking code is called by the main procedure. so i have got the logic working fine in the check but how do i get it to stop running the procedure that called it?

kind regards

Public sub maincode()

call checkvalues() ' Check to see if text has been entered into the variables

*****Run main code here

End Sub

you mean other code below it (procedure calling) not executed?
just modified it :

Public sub maincode()

If AppVariables.CustName = "" Then
     MsgBox("You have to configure this report before it can be run." & (Chr(13)) & (Chr(10)) & "Go to Configuration > Configure to resolve this", MsgBoxStyle.Critical)
Else   
      *****Run main code here
End If

End Sub

so you don't have to call Check procedure...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.