mookie
01-22-2008, 06:21 AM
is there a way to do the following?
on success = false goto trap
success = crosscomm.setvar($robtrafo,"")
success = crosscomm.setvar($robruntime,"")
success = crosscomm.setvar($step1,"")
trap:
I just dont like continually like having to check for success being false on everyline.
tHuNd3r
01-22-2008, 06:51 AM
no ... only if your componente would "Throw" the error...
then you could "On Error Goto Trap"...
tHuNd3r
01-22-2008, 06:55 AM
Or... try this...
Private bSuccess As Boolean
Private Property Get Success() As Boolean
Success = bSuccess
End Property
Private Property Let Success(ByVal bValue As Boolean)
bSuccess = bValue
If bValue = False Then Err.Raise 1, "Success is false"
End Property
Private Sub MySub()
On Error GoTo trap
Success = crosscomm.setvar($robtrafo,"")
Success = crosscomm.setvar($robruntime,"")
Success = crosscomm.setvar($step1,"")
Exit Sub
trap:
'Do your stuff
End Sub
Why not just do a
If Success then
Success = crosscomm.setvar($robtrafo,"")
Success = crosscomm.setvar($robruntime,"")
Success = crosscomm.setvar($step1,"")
else
'Do something
End If
the master
01-22-2008, 09:08 AM
I think he wants to check the result on every line.
I would pass it to a function that automatically checks it
private function CheckIt(byval blnValue as boolean)
'Check the value here
end function
CheckIt crosscomm.setvar($robtrafo,"")
CheckIt crosscomm.setvar($robruntime,"")
CheckIt crosscomm.setvar($step1,"")
This method also allows you to add more parameters so you can tell which line you are processing
dilettante
01-22-2008, 10:42 AM
Whatever this is, it isn't VB. What's with those $ characters?
the master
01-22-2008, 11:12 AM
It is VB. Those dollar signs mean its a string aparently. I think they are normally used when the variables arnt defined. You should define all variables no matter what and "option explicit" at the top of every code module will make for a lot better programming
the master
01-22-2008, 11:16 AM
Ive just checked it out and it doesnt actually work. For what i was thinking of you need the dollar sign at the *end* of the variable name. I know it is used at the begining in PHP but the rest of the code looks more VBish than PHPish
Hugh Lerwill
01-22-2008, 03:38 PM
To do it on a Form
Have a TextBox Named Success make it invisible
Then you set your trap in
Private Sub Success_Change()
if Success etc.
end if
End Sub
the master
01-22-2008, 03:39 PM
That way would work but it involves having an extra control hanging around and the code would run slower. I doubt you would notice the speed difference though
Hugh Lerwill
01-22-2008, 04:21 PM
>would work
.....!
>the code would run slower
The price of a 'variable' with events I guess.
To guarantee a 'change' on every call though a little more is required.
Private Sub Success_Change()
If Success<>""
'do stuff
End if
Success = ""
End Sub
the master
01-22-2008, 04:24 PM
If using a textbox then you should always put text1.text instead of just text1.
Using a function would be nice and simple. You dont have any extra controls or anything, it checks the value on each line and gives you the flexibility to add extra arguments for whatever purpose (EG, what line number it is)