Forum Discussion

ChandanD's avatar
ChandanD
Contributor
8 years ago

I want to read value from excel

Hi,

 

I want to search a value from excel sheet and enter those values in my application.

I'm writing to use "==" operator it is not working and with the below code I'm unable to find the value from excel sheet.

Excel Sheet data is

Curve12031
Curve13031
Curve1403.51
Curve15011
Curve21001
Curve22001
Curve23011
Curve24011

 

I need to search first Curve1 and enter the values in my application.

Then Curve2 and its associated data in my application.

So I'm unable to find the value using below code

Sub Temp

name=DDT.CurrentDriver.Value(0)

set curvedriver = DDT.ExcelDriver(Path&"TestData\PrjData\PrjData.xlsx", "CurveData", true)

curvedriver.Name="Curvedriver" 

do

addnew = DDT.DriverByName("Curvedriver").Value(0)

if (addnew<>name) then Exit do

msgbox(DDT.DriverByName("Curvedriver").Value(1))

msgbox(DDT.DriverByName("Curvedriver").Value(2))

msgbox(DDT.DriverByName("Curvedriver").Value(3))

Call curvedriver.Next()

loop until (curvedriver.EOF)

 

Call DDT.CloseDriver(curvedriver.Name)

End Sub

 

With below code it is giving me syntax error

ub Temp

name="Curve1"

set curvedriver = DDT.ExcelDriver(Path&"TestData\PrjData\PrjData.xlsx", "CurveData", true)

curvedriver.Name="Curvedriver" 

do

addnew = DDT.DriverByName("Curvedriver").Value(0)

if (addnew==name) then Exit do

msgbox(DDT.DriverByName("Curvedriver").Value(1))

msgbox(DDT.DriverByName("Curvedriver").Value(2))

msgbox(DDT.DriverByName("Curvedriver").Value(3))

Call curvedriver.Next()

loop until (curvedriver.EOF) 

 

Call DDT.CloseDriver(curvedriver.Name)

End Sub

 

12 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    OK, several things.

    First of all, you might have problems if the first row of your excel spreadsheet is not the column names.  By default, data drivers like this use the first row to give column names so it will probably skip your first row of data.  Technically, speaking, your first section of code should work fine for your needs.  It will return every row for Curve1... but you need to change your data table to

     

    Name Value1 Value2 Value3
    Curve1 20 3 1
    Curve1 30 3 1
    Curve1 40 3.5 1
    Curve1 50 1 1
    Curve2 10 0 1
    Curve2 20 0 1
    Curve2 30 1 1
    Curve2 40 1 1

     

    so that the driver will recognize your actual first row of data.

     

    As for your syntax error in your second routine...  for VBScript, you don't need to use the == to do a comparison.  = should be fine... but that routine will exit immediately without returning any data at all.  I'd use your first routine, but fix your excel sheet to have column headers.

    • ChandanD's avatar
      ChandanD
      Contributor

      Yes,

      Itworks for first record only.

      Actually what I need is

      If Name=Curve1 then enter the records till the name is not Curve2 in my application

      Then Create Curve2 in my application

      Search Name=Curve2 or EOF then enter the records in my application.

       

      With first code it is creating Curve1 and entering Curve 1 data

      Create Curve2 but doesn't enter Curve2 data.

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        In your first routine, do the following:

        Sub Temp
        
        set curvedriver = DDT.ExcelDriver(Path&"TestData\PrjData\PrjData.xlsx", 
        "CurveData", true)
        name=DDT.CurrentDriver.Value(0)
        curvedriver.Name="Curvedriver" 
        do
        addnew = DDT.DriverByName("Curvedriver").Value(0)
        if (addnew<>name) then name=DDT.CurrentDriver.Value(0)
        msgbox(DDT.DriverByName("Curvedriver").Value(1))
        msgbox(DDT.DriverByName("Curvedriver").Value(2))
        msgbox(DDT.DriverByName("Curvedriver").Value(3))
        Call curvedriver.Next()
        loop until (curvedriver.EOF)
         
        Call DDT.CloseDriver(curvedriver.Name)
        End Sub

        This will loop through both sections of the table, first going through Curve1.  Then, when they are different, it resets the "name" to curve 2 and goes through the data again.