Converting a VB Function to VBScript

M

Mark Milliman

I need to convert a function borrowed from Sue to VBScript but I am far from
a VB expert. I know that it should be a simple job, but FrontPage says that
there is a syntax error. The problem is that the line numbers do not match
where the error is located. The VB function runs fine in the VBE but not in
a web page in Outlook.

The subroutine that calls the function works well without the function so I
know that the problem has to lie in the function. Here is my hacked version
of the code.

Function Set_Account(AccountName, M)
Dim OLI 'As Outlook.Inspector
Dim strAccountBtnName 'As String
Dim intLoc 'As Integer
' Const ID_ACCOUNTS = 31224

Dim CBs 'As Office.CommandBars
Dim CBP 'As Office.CommandBarPopup
Dim MC 'As Office.CommandBarControl

Set OLI = M.GetInspector
If Not OLI Is Nothing Then
Set CBs = OLI.CommandBars
Set CBP = CBs.FindControl(, 31224)
If Not CBP Is Nothing Then
For Each MC In CBP.Controls
intLoc = InStr(MC.Caption, " ")
If intLoc > 0 Then
strAccountBtnName = Mid(MC.Caption, intLoc + 1)
Else
strAccountBtnName = MC.Caption
End If
If strAccountBtnName = AccountName Then
MC.Execute
Set_Account = AccountName
GoTo Exit_Function
End If
Next
End If
End If
Set_Account = ""

Exit_Function:
Set MC = Nothing
Set CBP = Nothing
Set CBs = Nothing
Set OLI = Nothing
End Function


I hate to keep bugging Sue because she has already provided so much help on
this minor front-end of the project. I hope that someone can tell me where
I have gone wrong.

Thanks,


________________________________


Mark Milliman
Longmont, Colorado E-mail: (e-mail address removed)
________________________________
 
S

Sue Mosher [MVP-Outlook]

Try taking out the Exit_Function: statement and replacing GoTo Exit_Function with Exit For. VBScript doesn't support that kind of branching.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
M

Mark Milliman

Sue:

Thanks again. I was looking at the article in MSDN explaining the
differences between VBScript and VBA when I noticed what you just said. We
were always taught never to use GoTo. I also changed your logic a bit to
remove the NOTs. Here is what I have now, but the syntax error is still in
the same place. I am counting comment lines in my HTML file to see if I can
figure out where it is telling me the error may be. I'm stumped.

Function SetAccount(AccountName, MItem)
Dim OLI 'As Outlook.Inspector
Dim strAccountBtnName 'As String
Dim intLoc 'As Integer
Const ID_ACCOUNTS = 31224

Dim CBs 'As Office.CommandBars
Dim CBP 'As Office.CommandBarPopup
Dim MC 'As Office.CommandBarControl

Set OLI = MItem.GetInspector
Set CBs = OLI.CommandBars
Set CBP = CBs.FindControl(, 31224)
If CBP Is Nothing Then
Set_Account = ""
Else
For Each MC In CBP.Controls
intLoc = InStr(MC.Caption, " ")
If intLoc > 0 Then
strAccountBtnName = Mid(MC.Caption, intLoc + 1)
Else
strAccountBtnName = MC.Caption
End If
If strAccountBtnName = AccountName Then
MC.Execute
Set_Account = AccountName
End If
Next
End If

'Clean up
Set MC = Nothing
Set CBP = Nothing
Set CBs = Nothing
Set OLI = Nothing
End Function


Try taking out the Exit_Function: statement and replacing GoTo Exit_Function
with Exit For. VBScript doesn't support that kind of branching.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
M

Mark Milliman

Try taking out the Exit_Function: statement and replacing GoTo Exit_Function
with Exit For. VBScript doesn't support that kind of branching.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

Sue Mosher [MVP-Outlook]

If you can't get the script debugger to work, a sprinkling of MsgBox statements should help. I'm sorry that nothing jumps out at me.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
M

Mark Milliman

I decided to give up on the idea of a function right now because I only call
it once in the script. If I go beyond two accounts then I'll have to figure
it out. I embedded the code right in my VBScript program that opens the
message. It works fine. The problem may have to do with passing the
parameters of the function since the code executed without being a function.
Maybe by the time I need to turn it back into a function, I'll know VBScript
better or someone will have shown me the ways of my error.

Sue, thanks for your help. If I find a solution, I'll add it to your site.

Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top