The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum
 Origin Forum
 finding row #'s by matching dates
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

daveblaw

USA
Posts

Posted - 06/01/2006 :  3:59:34 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): OriginPro 7 SR4
Operating System:Windows XP

Hi,
I have a large worksheet with months of data in it. I need a way to take the user input date range and find that in the database. for example the user would input, "mm/dd/yy", and I need to match this to the timestamp in the first column of the worksheet, which is also in the date format. The output would be the index # of the rows which also have the same date.
thanks,
dave

Deanna

China
Posts

Posted - 06/01/2006 :  9:54:20 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Dave.

I have written a simple OC function for you. I think it should help you finding the row numbers.


/**
Find the beginning and ending row index with the corresponding date in the first column.
Note that the worksheet has been sorted according to the first column.

Example:
void TestFindDataRange()
{
int iBegin, iEnd;
FindDateRange("data1", "06/05/08", iBegin, iEnd);

printf("Beginning index: %d\n", iBegin);
printf("Ending index: %d\n", iEnd);
}

Parameters:
lpcszWksName = The name of the worksheet
lpcszDate = The user-input date
iBeginning = the beginning index of the rows whose first column values are equal to the user input
iEnding = the ending index of the rows whose first column values are equal to the user input
*/

bool FindDateRange(LPCSTR lpcszWksName, LPCSTR lpcszDate, int &iBeginning, int &iEnding)
{
bool bRet=false;
bool bFound=false;

Worksheet wks(lpcszWksName);
if (!wks)
{
out_str("Cannot find the worksheet!");
return bRet;
}
bRet = true;

double dDate;
string strScript;
strScript.Format("dd=date(%s)",lpcszDate);

LT_execute(strScript);
LT_get_var("dd", &dDate); // Get LabTalk variable value

int ii;
double temp;

for (ii=0; ii<wks.Columns(0).GetNumRows(); ii++)
{
if ((wks.Cell(ii, 0)==dDate)&&(!bFound)) //Find the beginning row
{
bFound=true;
iEnding=iBeginning=ii;
}

if ((wks.Cell(ii, 0)!=dDate)&&(bFound)) //Find the ending row
{
bFound=true;
iEnding=ii-1;
break;
}

}


return bRet;
}




Note that the worksheet are assumed to be sorted according to the first column. You may try the example function, TestFindDataRange(), to see if it works.

Deanna
OriginLab GZ Office

Edited by - Deanna on 06/01/2006 11:35:54 PM
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000