Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

How To Stop The Program?

Hi there, i am new to VB, just a quick question really.

If MsgBox("You have selected not to validate the data, it is advised that all data be validated. If you proceed this may result in incorrect data being stored. Do you wich do continue?", vbYesNo + vbQuestion, "Validation") = vbYes Then
Call process
Else
'How do i end the process here?
End
End If

Where i have end above i need something so that if they press No then the program comes back up so that they can edit data?

Do you understand that, sorry if it isnt very clear.
[593 byte] By [embracex2] at [2007-11-11 10:15:16]
# 1 Re: How To Stop The Program?
well when you call End, it closes the current app and unloads the form and also the Call process is ended.

End - Stops the program
bubu1234 at 2007-11-11 17:22:57 >
# 2 Re: How To Stop The Program?
yes but what i need is for it not to end it but bring the page back up for editing
embracex2 at 2007-11-11 17:23:57 >
# 3 Re: How To Stop The Program?
i am very sorry please post a larger piece of code...you don't make much sense :)
bubu1234 at 2007-11-11 17:24:52 >
# 4 Re: How To Stop The Program?
ok no problems, sorry.

Option Explicit

'Products is the name of my Global veriable in my module
Dim Orders As OrdersType
'This is the path of the file displayed in the common dialog
Dim Filename As String
'The number of records currently stored
Dim NumOfRecords As Integer
'The way you are comunicating with the file you are creating
Dim ChannelNum As Integer
'The length of the record
Dim RecordLength As Long

Private Sub cmdOpen_Click()
'Opens the Windows browser
CommonDialog1.ShowOpen
'Displys the files path in the ChannelPath text box
txtChannelPath.Text = CommonDialog1.Filename
'Declared the name of the Filename as the data in txtChannelPath
If txtChannelPath = "" Then
MsgBox "Please Select A Path To Save The Data To!"
Call cmdOpen_Click
End If
Filename = txtChannelPath.Text

'The Record Length is the Length of Products in the Global veriable module
RecordLength = Len(Orders)
ChannelNum = FreeFile

'Opens the specified file and stores the file in a random Channel(Storage location)
'Also specifies that the file length(Len) is the size of RecordLength
Open Filename For Random As ChannelNum Len = RecordLength

'This shows that the NumOfRecords is the Length os file(LOF) * ChannelNum / Lenght(Len) * Products
NumOfRecords = LOF(ChannelNum) / Len(Orders)

'Displays NumOfRecords in the lblNumOfRecords
lblNumOfRecords.Caption = NumOfRecords

Close ChannelNum
End Sub

Private Sub cmdAdd_Click()


If txtChannelPath = "" Then
MsgBox "Please Select A Path To Save The Data To!"
Call cmdOpen_Click
End If

If Check1 = Unchecked Then Call ValidationNo

If Check1 = Checked Then Call Validation




End Sub

Private Sub ValidationNo()
If MsgBox("You have selected not to validate the data, it is advised that all data be validated. If you proceed this may result in incorrect data being stored. Do you wich do continue?", vbYesNo + vbQuestion, "Validation") = vbYes Then
Call process
Else
End
End If
End Sub

Private Sub Validation()
'Checks that there is a path selected
If txtChannelPath = "" Then MsgBox "Please Select A Path"

'Checks that OrderID is an intager
If IsNumeric(txtOrderID.Text) Then Orders.OrderID = True Else MsgBox "OrderID Must Be Numeric", vbInformation, "Validation Error"

'Checks that SupplierID is an intager
If IsNumeric(txtSupplierID.Text) Then Orders.SupplierID = True Else MsgBox "SupplierID Must Be Numeric", vbInformation, "Validation Error"

'Checks that ProductID is an intager
If IsNumeric(txtProductID.Text) Then Orders.ProductID = True Else MsgBox "ProductID Must Be Numeric", vbInformation, "Validation Error"

'Checks that Quantity Ordered is an intager
If IsNumeric(txtQuantityOrdered.Text) Then Orders.QuantityOrdered = True Else MsgBox "Quantity Ordered Must Be Numeric", vbInformation, "Validation Error"

'Checks that Date Due is a date
If IsDate(txtDateDue.Text) Then Orders.DateDue = True Else MsgBox "Please enter a valid date!", vbInformation, "Validation Error"

'Checks that all data is valid before calling process
If Orders.DateDue = True And Orders.OrderID = True And Orders.SupplierID = True And Orders.ProductID = True And Orders.QuantityOrdered = True Then Call process

End Sub

Private Sub process()

If IsNumeric(txtOrderID.Text) Then Orders.OrderID = txtOrderID.Text Else Orders.OrderID = 0
If IsNumeric(txtSupplierID.Text) Then Orders.SupplierID = txtSupplierID.Text Else Orders.SupplierID = 0
If IsNumeric(txtProductID.Text) Then Orders.ProductID = txtProductID.Text Else Orders.ProductID = 0
If IsDate(txtDateDue.Text) Then Orders.DateDue = txtDateDue.Text Else Orders.DateDue = 1 / 1 / 1
If IsNumeric(txtQuantityOrdered.Text) Then Orders.QuantityOrdered = txtQuantityOrdered.Text Else Orders.QuantityOrdered = 0

Open Filename For Random As ChannelNum Len = RecordLength
Put ChannelNum, NumOfRecords + 1, Orders
Close ChannelNum
NumOfRecords = NumOfRecords + 1
lblNumOfRecords = NumOfRecords
'Resets the text boxes so they are empty
txtOrderID.Text = ""
txtSupplierID.Text = ""
txtProductID.Text = ""
txtDateDue.Text = ""
txtQuantityOrdered.Text = ""
End Sub

Private Sub EntryFalse()
'Resets the text boxes so they are empty
txtOrderID.Text = ""
txtSupplierID.Text = ""
txtProductID.Text = ""
txtDateDue.Text = ""
txtQuantityOrdered.Text = ""
End Sub

Private Sub cmdQuit_Click()
'Ends the program
End
End Sub

Private Sub cmdBack_Click()
'Hides the current form
Me.Hide
'Shows frmAdminSelect
frmAdminSelect.Show
End Sub

If the user presses no on the msgbox it still does process however i need it so that when no is pressed it aborts so the user can edit the data.
embracex2 at 2007-11-11 17:25:58 >
# 5 Re: How To Stop The Program?
Private Sub ValidationNo()
If MsgBox("You have selected not to validate the data, it is advised that all data be validated. If you proceed this may result in incorrect data being stored. Do you wich do continue?", vbYesNo + vbQuestion, "Validation") = vbYes Then
Call process
Else
End (here is your problem)
End If
End Sub

if the response from the message box is yes you call the process ok, but if the response is no you should leave it empty or load the form where you have the edit
bubu1234 at 2007-11-11 17:26:56 >
# 6 Re: How To Stop The Program?
Mwha done it, thats

Private Sub ValidationNo()
If MsgBox("You have selected not to validate the data, it is advised that all data be validated. If you proceed this may result in incorrect data being stored. Do you wich do continue?", vbYesNo + vbQuestion, "Validation") = vbYes Then
Call process
Else
Me.Refresh
End If
End Sub

That was it! Thanks
embracex2 at 2007-11-11 17:27:55 >
# 7 Re: How To Stop The Program?
onemore quick question.

When i have the msgbox's display the errors in validation as shown below

Private Sub Validation()
'Checks that there is a path selected
If txtChannelPath = "" Then MsgBox "Please Select A Path"

'Checks that OrderID is an intager
If IsNumeric(txtOrderID.Text) Then Orders.OrderID = True Else MsgBox "OrderID Must Be Numeric", vbInformation, "Validation Error"

'Checks that SupplierID is an intager
If IsNumeric(txtSupplierID.Text) Then Orders.SupplierID = True Else MsgBox "SupplierID Must Be Numeric", vbInformation, "Validation Error"

'Checks that ProductID is an intager
If IsNumeric(txtProductID.Text) Then Orders.ProductID = True Else MsgBox "ProductID Must Be Numeric", vbInformation, "Validation Error"

'Checks that Quantity Ordered is an intager
If IsNumeric(txtQuantityOrdered.Text) Then Orders.QuantityOrdered = True Else MsgBox "Quantity Ordered Must Be Numeric", vbInformation, "Validation Error"

'Checks that Date Due is a date
If IsDate(txtDateDue.Text) Then Orders.DateDue = True Else MsgBox "Please enter a valid date!", vbInformation, "Validation Error"

'Checks that all data is valid before calling process
If Orders.DateDue = True And Orders.OrderID = True And Orders.SupplierID = True And Orders.ProductID = True And Orders.QuantityOrdered = True Then Call Process

End Sub

Is there anyway to get it so that the errors are displayed in the same msgbox trather than have 5 msgbox's if there is an error on each check?
embracex2 at 2007-11-11 17:29:00 >
# 8 Re: How To Stop The Program?
well it should be like this

dim rsp as string

sub check()
rsp=""
if t=1 then rsp=rsp+" Check the field"

if t=2 then rsp=rsp+" Check the checkbox"

if t=3 then rsp=rsp+" Check the form"

if len(ras)>0 then msgbox rsp

end sub
bubu1234 at 2007-11-11 17:30:04 >
# 9 Re: How To Stop The Program?
ok thanks i have them all in the same msgbox, is there anyway to get each message on a new line?
embracex2 at 2007-11-11 17:30:58 >
# 10 Re: How To Stop The Program?
its ok done it now, thank you
embracex2 at 2007-11-11 17:31:59 >