PC Review


Reply
Thread Tools Rate Thread

Converting a VB Function to VBScript

 
 
Mark Milliman
Guest
Posts: n/a
 
      14th Sep 2005
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 Removed)
________________________________



 
Reply With Quote
 
 
 
 
Sue Mosher [MVP-Outlook]
Guest
Posts: n/a
 
      14th Sep 2005
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
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx


"Mark Milliman" <(E-Mail Removed)> wrote in message news:Od$(E-Mail Removed)...
>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


 
Reply With Quote
 
Mark Milliman
Guest
Posts: n/a
 
      14th Sep 2005
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


"Sue Mosher [MVP-Outlook]" <(E-Mail Removed)> wrote in message
news:eE%(E-Mail Removed)...
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
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx


"Mark Milliman" <(E-Mail Removed)> wrote in message
news:Od$(E-Mail Removed)...
>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



 
Reply With Quote
 
Mark Milliman
Guest
Posts: n/a
 
      14th Sep 2005

"Sue Mosher [MVP-Outlook]" <(E-Mail Removed)> wrote in message
news:eE%(E-Mail Removed)...
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
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx


"Mark Milliman" <(E-Mail Removed)> wrote in message
news:Od$(E-Mail Removed)...
>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



 
Reply With Quote
 
Sue Mosher [MVP-Outlook]
Guest
Posts: n/a
 
      14th Sep 2005
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
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx


"Mark Milliman" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> 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
>


 
Reply With Quote
 
Mark Milliman
Guest
Posts: n/a
 
      14th Sep 2005
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


"Mark Milliman" <(E-Mail Removed)> wrote in message
news:%23Cb%(E-Mail Removed)...
>
> "Sue Mosher [MVP-Outlook]" <(E-Mail Removed)> wrote in message
> news:eE%(E-Mail Removed)...
> 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
> http://www.turtleflock.com/olconfig/index.htm
> and Microsoft Outlook Programming - Jumpstart for
> Administrators, Power Users, and Developers
> http://www.outlookcode.com/jumpstart.aspx
>
>
> "Mark Milliman" <(E-Mail Removed)> wrote in message
> news:Od$(E-Mail Removed)...
>>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

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VbScript Function to encode into base64 compatible with .NET function System.Convert.FromBase64String abarberis@gmail.com Microsoft Dot NET Framework 1 20th Mar 2006 11:17 PM
Converting VBScript command into .NET hien_tran@ghc-hmo.com Microsoft VB .NET 0 3rd Aug 2005 04:32 PM
Converting MSSQL FTS parsing function from VBScript to C# Microsoft C# .NET 2 23rd Jun 2005 09:07 PM
Re: Converting a VBScript application to VB.NET chanmm Microsoft VB .NET 0 10th Feb 2005 01:35 PM
Problem converting VBScript to VBA Tod Microsoft Excel Programming 0 21st Aug 2003 04:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:45 AM.