Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB Script Outlook 98

Status
Not open for further replies.

JustNigel

Programmer
Dec 9, 2002
7
EU
Summary: Is there a alternative for the GOTO statement in vbScript for outlook 98 - if so will it fit the sketch below

I'm having to do a complex e-form in outlook. Worked out how to prepare a printout for customer (Using word) in single case but they want not line by line - I mdled it in VB6 and it goes like this

StartLineCheck:
if strPrint1 = "ready" then
str1 = ctls("Name").value
str2 = ctls("Name").value
'and so on
goto PrintForm
end if
if strPrint2 = "ready" then
str1 = ctls("Name").value
str2 = ctls("Name").value
'and so on
goto PrintForm
end if
'and so on for the ten lines

goto theend:

printform:
'code to open a word template and print out the variables in bookmarks

goto StartLineCheck

TheEnd:

I expected the code to work but it errors on the GOTO statement, It appears GOTO is not in VB script, can anyone suggest a sensible alternative
 
Public Sub StartLineCheck()
if strPrint1 = "ready" then
str1 = ctls("Name").value
str2 = ctls("Name").value
'and so on
Call PrintForm
end if

if strPrint2 = "ready" then
str1 = ctls("Name").value
str2 = ctls("Name").value
'and so on
Call PrintForm
end if

'and so on for the ten lines

Call Theend
End Sub

Public sub printform()
'code to open a word template and print out the variables in bookmarks
End Sub

Call StartLineCheck()

Public sub Theend()
Wscript.Quit
End Sub

Regards
Steve Friday
 
Public Sub StartLineCheck()
if strPrint1 = "ready" then
str1 = ctls("Name").value
str2 = ctls("Name").value
'and so on
Call PrintForm
end if

if strPrint2 = "ready" then
str1 = ctls("Name").value
str2 = ctls("Name").value
'and so on
Call PrintForm
end if

'and so on for the ten lines

Call Theend
End Sub

Public sub printform()
'code to open a word template and print out the variables in bookmarks
End Sub

Call StartLineCheck

Public sub Theend()
Wscript.Quit
End Sub

Regards
Steve Friday
 
How about something like:
Code:
Do
  If strPrint1 = "ready" Then
    str1 = ctls("Name").value
    str2 = ctls("Name").value
    'and so on
  ElseIf strPrint2 = "ready" Then
    str1 = ctls("Name").value
    str2 = ctls("Name").value
    'and so on
  ElseIf ...
  'and so on for the ten lines
  Else
    Exit Do
  End If

  'code to open a word template and print out
  'the variables in bookmarks
Loop
This mimics what you had. But I also wonder about alternatives that get rid of the repeated code you have within the loop. Something looks very wrong here. A loop should be doing more of the work for you.
 
An answer is nested Do's - there are lots of fields in my problem. Here is a model of the solution I used -you were right a loop could do more

sub cmbTest_click

'outer loop
do
'inner loop
do

n = n + 1

if n = 5 then
msgbox "Exit 1"
exit do
end if

if n = 8 then
msgbox "Exit 2"
exit do
end if

if n = 12 then
msgbox "Exit 3"
exit do
end if

if n = 21 then
msgbox "Exit 4"
exit do
end if

msgbox n

loop
msgbox "outer loop - where the print code lies"
if N > 20 then
exit do
end if
loop

end sub

Thanks everyone
 
For something like this I'd use a For loop:
Code:
For n = 1 To 21
 <stuff>
Next
There ought to be a lot more you could strip out too - this still looks pretty messy.
 
Yes I agree, but rush precluded futher thinking time, as always

Works though
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top