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
 All Forums
 Origin Forum
 Origin Forum
 finding row #'s by matching dates

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
daveblaw Posted - 06/01/2006 : 3:59:34 PM
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
1   L A T E S T    R E P L I E S    (Newest First)
Deanna Posted - 06/01/2006 : 9:54:20 PM
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

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000