Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 03-30-2017, 09:26 AM
Alfvic Alfvic is offline
Registered User
 
Join Date: Jan 2009
Posts: 8
Copy data from Excel file into array in SecureCRT 6

Hello,

Y need to get some data from a Excel file, which contain a list of IP address.

I was using this code, but Secure version 6 do not understand the expression "As Variant"
Code:
Dim data As Variant
data () = obj_Excel.ActiveSheet.UsedRange.Value

crt.Screen.Send "telnet " datos(0) & VbCr
...
In which version does SecureCRT support de definition os variables "As" something?
Is there any way to do this without and upgrade of version?

Another test i did was, but the sintaxis is not correct:

Code:
Dim data ()
ReDim data () = obj_Excel.ActiveSheet.UsedRange.Value

crt.Screen.Send "telnet " datos(0) & VbCr
...
Reply With Quote
  #2  
Old 03-30-2017, 09:34 AM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
Hi Alfvic,

We do have an example script available that demonstrates how to import data from .csv files.

Does reviewing/using this script help get your data imported?
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 03-31-2017, 05:26 AM
Alfvic Alfvic is offline
Registered User
 
Join Date: Jan 2009
Posts: 8
Hello ekoranyi,

I was trying to avoid using loops. Which is something I didn't mention. However, if you tell me it is the only way and SecureCRT doesn't not support variable definition as specific type, i will change my code.

Thanks
Reply With Quote
  #4  
Old 03-31-2017, 10:36 AM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
Hi Alfvic,

I think there is some confusion. From what I see Dim As Variant is available in VBA not VBScript. These are different languages, VBA is specific to Visual Basic for Applications and has different language constructs than VBScript. Converting from one to the other is sometimes possible but this does not guarantee all features of one are available in the other.


We do have several examples of Excel integration that may help.

For a very targeted example of accessing data without using loop please see the code below:

Code:
Set g_shell = CreateObject("WScript.Shell")
Set g_fso = CreateObject("Scripting.FileSystemObject")

Set objExcel = CreateObject("Excel.Application")
Set objWb = objExcel.Workbooks.Open(g_shell.SpecialFolders("Desktop") & "\MyBook.xlsx")
Set objWs = ObjWb.Sheets(1)
Set objUsedRange = objWs.UsedRange

' In this case, objUsedRange is not necessary.
' UsedRange is potentially necessary if you don't know where the data
' resides within the worksheet.

strValue = objUsedRange.Rows(2).Cells(1,1).Value
MsgBox strValue

strValue = objUsedRange.Rows(4).Cells(1,3).Value
MsgBox strValue

' You don't need to use the Rows() collection to
' get at data... you can reference it directly using
' the Cells collection:
strValue = objUsedRange.Cells(5,1).Value
MsgBox strValue

' You also don't need to use the UsedRange collection
' either; you can reference the cell itself in normal
' Excel nomenclature: "B1"
strValue = objWs.Range("B1").Value
MsgBox strValue

' You can also use the Cells collection referencing
' individual cells in row,col notation. For example:
strValue = objWs.Cells(6,3).Value
MsgBox strValue

objWb.Close
objExcel.Quit
I've also included a screenshot that helps demonstrate this codes use:

Attached Images
File Type: png ExcelCellReferencing(without-looping).png (53.7 KB, 492 views)
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730

Last edited by jdev; 11-09-2017 at 11:31 AM.
Reply With Quote
  #5  
Old 04-11-2017, 02:15 PM
Alfvic Alfvic is offline
Registered User
 
Join Date: Jan 2009
Posts: 8
Thank you Eric. You are right. Thanks for the example.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes 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

Forum Jump


All times are GMT -6. The time now is 08:06 PM.