473,403 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

InStrRev Not Giving Correct Results

20
Hello,

I have an Access database where I'm importing book/journal publication data from JabRef in a CSV format.
When I import the data to Access one of the odd things that happens is that the page numbers are given two hyphens in between them, so the data in the "pages" column in Access would look something like "200--213"

I need to be able to count the number of pages that are referenced.

Expand|Select|Wrap|Line Numbers
  1. In order to do this I do the following in unbound text boxes on the form:
  2.  
  3. I find the length of the string in the "pages" column (have to rename the pages variable as it's a reserved name to pagesset):  PLen = Len([pagesset])
  4. I find the number of characters that happen from the left up to the "--": LPageVar = InStr([pagesset],"--")
  5. I find the number of characters that happen from the right up to the "--": RPageVar = InStrRev([pagesset],"--")
  6. I find the actual page number on the left side of the "--":  LVal = Left([pagesset],[LPageVar]-1)
  7. I find the actual page number on the right side of the "--":  RVal = Right([pagesset],[RPageVar]-1)
  8. I calculate the number of pages that appear:  Pgcnt = RVal - LVal
  9.  
Everything seems to work... except when the "InStrRev" hits an item that increments the number by the 10 or 100 spot, like this: "7--11", "7--23", or "92--101" as opposed to this: "102--123" or "103--110" (which causes no issues). When it hits these shorter pagethe RPageVar is too low by 1.

For each of these items on the right, RVal seems to drop the first character... so for "7--11" last page is reported as 1 or for "7--23" it would report the last page as 3 or "92--101" the last page is reported as 01. This causes these particular page counts to be negative.

Does anyone have an idea as to why I'm getting this behavior?

Thank you in advance.
Jan 17 '14 #1

✓ answered by Rabbit

Given your data, InStr and InStrRev returns the same number. You misunderstand what InStrRev does, it does the exact same thing InStr does except it finds the last occurrence of the given string rather than the first occurrence.

In your case, you only have one occurrence of the double dash, that means both functions are going to return the same value.

You just need the index of the first one anyways. You want to take the right x characters, where x is the length minus one minus the index of the occurrence of the double dash.

3 8767
Rabbit
12,516 Expert Mod 8TB
Given your data, InStr and InStrRev returns the same number. You misunderstand what InStrRev does, it does the exact same thing InStr does except it finds the last occurrence of the given string rather than the first occurrence.

In your case, you only have one occurrence of the double dash, that means both functions are going to return the same value.

You just need the index of the first one anyways. You want to take the right x characters, where x is the length minus one minus the index of the occurrence of the double dash.
Jan 17 '14 #2
Vaulcul
20
Ah... I see what I was doing wrong.
Thanks Rabbit.
Jan 21 '14 #3
WannaKatana2
2 Bit
The Microsoft Access InstrRev function returns the position of the first occurrence of a string in another string, starting from the end of the string.


@Rabbit
Apr 13 '22 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Hunter Hillegas | last post by:
I have just added a third table to a query and I am no longer getting the results I am expecting. Three Tables: CUSTINVOICEJOUR (Header Table) CUSTINVOICETRANS (Line Item Table) MARKUPTRANS...
1
by: RM | last post by:
I am using DataSet's .ReadXml() method to parse an XML file that has an inline schema and Im getting "different" results on various machines using the same myDataSet.ReadXml("myExample.xml"). ...
1
by: dvorett | last post by:
I have a database that has three linked tables "Projects", "Techniques" and "Vendors". I have a query that asks for the user to input a Project. The goal of the query is to find project...
12
by: mike cox | last post by:
I'm running PostgreSQL 8.0 beta 1. I'm using the earthdistance to find the distance between two different latitude and logitude locations. Unfortunately, the result seems to be wrong. Here is...
2
by: awebguynow | last post by:
Overall, I'm pleased with phpDocumentor, but I've only been using it a day, and I'm not getting exactly what I expected. I've read the FAQ, Tutorial and Manual briefly. I'm using WinXP PHP...
45
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4. An odd thing is happening with the mcrypt_encrypt function. I am trying to encrypt a string of data (for password storage): $enc = mcrypt_encrypt(MCRYPT_XTEA,...
1
by: sunshine19992 | last post by:
Not sure if others have come acrossed this bit I have a program for a C# class I am taking and during my troubleshooting I have found that if I turn on a breakpoint and then press F5 to continue...
2
by: Leafy | last post by:
Hi Folks! I sure hope someone can guide me on this issue. Here is the XML document I'm working from (nda.xml): <?xml version="1.0" encoding="utf-8"?> <soap:Envelope...
1
Claus Mygind
by: Claus Mygind | last post by:
I am doing some work with displaying the local time. I would like to get this format: 2:18:00 pm Using the sample code from w3Schools.com below, I can get the correct results from IE and...
1
by: dfn77 | last post by:
Hi, I'm having some trouble with the following piece of code: string getAllNew = "SELECT * FROM dbo.HeaderAndDetail WHERE ProcessedToCsv = 0"; conn.Open(); ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.