View Single Post
  #4  
Old 10-12-2016, 10:36 AM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 950
Post

Quote:
I've had to throw in a lot of 'End If' statements at the end to stop to script erroring but I can't understand why as everywhere I have an 'If' statement there is a corresponding 'End If' - Unless of course I'm missing something?
I won't be able to allocate resources to analyze and fix all the places in your code where you're making VBScript syntax mistakes. However, I'll provide you with a few tips that you can use to learn and move forward with your project.

Part of the problem is that you're using an editor that is combining tabs with spaces for indentation. It's easier to read if you stick with either one or the other. Some editors can be configured to always use 4 spaces instead of inserting a tab character when performing indentation.

Proper indentation will help you see where you've missed End If statements.

Here's just one example:

Quote:
I've tried to tidy up the telnet attempts later on but they're still quite long, I've tried taking bits out/ changing bits to shorten in but I'm having no luck - Is there perhaps a way of making the first 'paste clipboard contents bit so that I can reuse it later to cut down on the length?
Not clear what you're trying to accomplish with all that code. If you want access to what's in the clipboard, and you simply want to parse out the IP that's there and check it to see if it's valid, you'd do something like this:

Code:
strAddress = crt.Clipboard.Text
' Remove all spaces, CRs, LFs, and TAB characters that might be in the clipboard
strAddress = Replace(strAddress, " ", "")
strAddress = Replace(strAddress, vbcr, "")
strAddress = Replace(strAddress, vblf, "")
strAddress = Replace(strAddress, vbtab, "")

' Now check it against our regexp pattern.
Set re = New RegExp
' Set the pattern to match only an IPv4 address
re.Pattern = _
     "^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}" & _
     "(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$"

' This loop allows us to continue prompting for valid
' input until either the user cancels, or provides a
' valid IP address.
Do
    If re.Test(strAddress) Then
        Exit Do
    Else
        strAddress = crt.Dialog.Prompt(_
            "Please specify a valid IPv4 address", _
            "Enter IP Address", _
            strAddress)
        If strAddress = "" Then
            Exit Sub
        End If
    End If
Loop
Put that block first thing inside of your Sub Main. Then you'll always have the strAddress variable to use when referencing what was originally in the clipboard.

Additionally, you're sending 'ssh user@' before you even test the input... you should consider instead building up your entire command *before* sending anything to the remote. For example.
Code:
strCmd = "ssh user@" & strAddress
crt.Screen.Send strCmd & vbcr
This should help simplify things as you won't have to Ctrl+C to clear your command line... perhaps.

--Jake
Attached Images
File Type: png If..Then_missingEndIf_t=12505.r4.png (32.1 KB, 1929 views)
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote