![]() |
value doesn't get passed to a sub-routine, loop doesn't iterate
I have this sub called in another routine which does the page setup and sets
the page breaks and formatting for the user to print. I took out the code below called setprinter and made it into a subroutine because it is called in other scripts. The loop doesn't seem to be working. I tried to debug it and this is what happens: It goes through the first loop and sets counter to 1. Then it gets a 0 error and passes 0 to the counter variable outside this script or else it is already 0 and nothing happens because I didn't pass it out of this subroutine. The network number changes becuase it is not fixed but dynamic so I want it to loop through and get the right number. The loop should have found an error and gone and tried network 2. Question 1: why doesn't it find the error and try the 2nd iteration? Question 2: how do I pass it to the main script? tia, Public Sub setPrinter() Dim Counter As Integer ' This function loops through the number 1-9 because the _ network on the printer is not stationary _ but changes from Network 1 - 9. On Error Resume Next For Counter = 1 To 9 Err.Clear Application.ActivePrinter = "\\martinezfs1-bay\Ca-Martinez-94C on Ne0" & Counter & ":" If Err.Number = 0 Then Exit For MsgBox "Network Printer" & Counter Next If Err.Number < 0 Then MsgBox "the command to print has an error." MsgBox Err.Number End Sub |
value doesn't get passed to a sub-routine, loop doesn't iterate
Public Function GetPrinter(ByRef nError as long)
Dim Counter As Integer ' This function loops through the number 1-9 because the _ network on the printer is not stationary _ but changes from Network 1 - 9. On Error Resume Next For Counter = 1 To 9 Err.Clear Application.ActivePrinter = "\\martinezfs1-bay\Ca-Martinez-94C on Ne0" & Counter & ":" If Err.Number = 0 Then GetPrinter = i Exit For Else MsgBox "Network Printer" & Counter End If Next nError = Err.Number < 0 End Sub And use like this nPrinter = GetPrinter(nError) if nPrinter = 0 Then MsgBox "the command to print has an error." MsgBox nError Else 'use nPrinter End If End Sub -- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "Janis" wrote in message ... I have this sub called in another routine which does the page setup and sets the page breaks and formatting for the user to print. I took out the code below called setprinter and made it into a subroutine because it is called in other scripts. The loop doesn't seem to be working. I tried to debug it and this is what happens: It goes through the first loop and sets counter to 1. Then it gets a 0 error and passes 0 to the counter variable outside this script or else it is already 0 and nothing happens because I didn't pass it out of this subroutine. The network number changes becuase it is not fixed but dynamic so I want it to loop through and get the right number. The loop should have found an error and gone and tried network 2. Question 1: why doesn't it find the error and try the 2nd iteration? Question 2: how do I pass it to the main script? tia, Public Sub setPrinter() Dim Counter As Integer ' This function loops through the number 1-9 because the _ network on the printer is not stationary _ but changes from Network 1 - 9. On Error Resume Next For Counter = 1 To 9 Err.Clear Application.ActivePrinter = "\\martinezfs1-bay\Ca-Martinez-94C on Ne0" & Counter & ":" If Err.Number = 0 Then Exit For MsgBox "Network Printer" & Counter Next If Err.Number < 0 Then MsgBox "the command to print has an error." MsgBox Err.Number End Sub |
All times are GMT +1. The time now is 12:21 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com