473,320 Members | 1,958 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,320 software developers and data experts.

Cannot get InStr to work in VB 6 program

10
I have vb 6 32-bit running on Vista 64-bit Premium Home. I am writing a Music Library program for my collection of Music CDs. Although I have used InStr in other appications and it worked, it will not in this app. I have a string of Artists in the database. I want select one of the string that is not first and print it to the MSFlexGrid.
strArtistString = rstMusic![Artist}
iLoc = InStr(1, strArtistString, txtSeeker.Text)
where
strArtistString = Eeny, Meeny, Miny, Moe
txtSeeker.Text = Moe
For some reason, iLoc never advances. With any of the names that are NOT first, the routine passes over and produces a "Artist Not Found". If Eeny is entered, then each search will go to the MSFlexGrid. I tried creating a function to see if that would help - it did not.
Jul 21 '12 #1

✓ answered by Jim Yab

After much trial and error, it occurred to me that the solution was with my SQL statement and not using the InStr at all. For your information, this line in my SQL statement is the answer to my problem:
strSQL = strSQL & "LIKE '*" & txtSeeker.Text & "*' "
Please note the asterisks and their location. Initially, I had the one following txtSeeker.Text. Today I added the one following LIKE and the problem was history. Thank you all for taking time to work with me.

8 3107
Guido Geurs
767 Expert 512MB
is the value in "strArtistString" OK?
Because iLoc = InStr("Eeny, Meeny, Miny, Moe", "Moe")
gives me iLoc= 20
PS: no need to use the 1 in Instr(1,...) when you start at the first letter !
Jul 22 '12 #2
Have you tried

Expand|Select|Wrap|Line Numbers
  1. instr(1,strArtistString,cstr(txtSeeker))
  2.  
Jul 23 '12 #3
Jim Yab
10
@Guido Geurs
Unfortunately, that has worked in other situations but not this one. I suspect that either the database or the MSFlexGrid may have something to do with it not working.
I have tried:
iLoc = InStr(1, strArtistString, txtSeeker.Text, vbTextCompare)
iLoc = InStr(1, strArtistString, txtSeeker.Text, vbBinaryCompare)
iLoc = InStr(1, strArtistString, txtSeeker.Text, vbDataBaseCompare)
The same variations with the following variable changes:
iLoc = InStr(strArtistString, txtSeeker.Text)
iLoc = InStr(1, (rstMusic![Artist]), txtSeeker.Text, vbTextCompare)
I have used the InStr before and it worked flawlessly. For some reason it will not count the letters in the string this application. It will only work for the very first name. I am missing something and have run out of ideas.
Jul 24 '12 #4
Jim Yab
10
@Rodney Roe
That did not work either. I am still open to other suggestions.
Jul 24 '12 #5
Rabbit
12,516 Expert Mod 8TB
Try it without any dynamic values and see if that works as expected.
Jul 24 '12 #6
Have you stepped through your program line by line to see if that is the actual problem.
Jul 24 '12 #7
Jim Yab
10
This sort of worked:
Set rstMusic = frmMain.gdbMySongs.OpenRecordset(strSQL)

iIndex = 1
If rstMusic.RecordCount = 0 Then
MsgBox "No Albums found", vbOKOnly, "Search - Album"
Else
rstMusic.MoveLast
rstMusic.MoveFirst
Me.MSFlexGrid1.Rows = rstMusic.RecordCount + 1

'replace quotation (") with apostrophe (')using:
'Replace(strAlbumP, Chr$(34), Chr$(39))

Do While Not rstMusic.EOF

'### this If-Then is to test of the InStr works - so far it does NOT work
strArtistString = "Tom, Dick, Harry" '(rstMusic![Artist])
If InStr(1, strArtistString, txtSeeker.Text, vbTextCompare) > 1 Then
Debug.Print InStr(1, strArtistString, txtSeeker.Text, vbTextCompare)
Stop
End If

With MSFlexGrid1

.TextMatrix(iIndex, 1) = Format(iIndex, " 0000#")
.TextMatrix(iIndex, 2) = Format(rstMusic![SongID], " 0000#")
.TextMatrix(iIndex, 3) = Replace(RTrim(rstMusic![album]), _
Chr$(34), Chr$(39))
.TextMatrix(iIndex, 4) = Replace(RTrim(rstMusic![Artist]), _
Chr$(34), Chr$(39))
.TextMatrix(iIndex, 5) = Replace(RTrim(rstMusic![Song]), _
Chr$(34), Chr$(39))
.TextMatrix(iIndex, 6) = Format(rstMusic![SongID], " 0000#")
.TextMatrix(iIndex, 7) = " " & RTrim(rstMusic![Convert])

I entered "Harry" and got the same "No Album Found" without stopping at the debug.print.
Then I tried "Har" because I had two known artists in the DB that began with Har.
This time it stopped at the debug and printed 12 which is correct. Continuing the program resulted in the two artist names appearing in the grid. These were single names and not a series of names in the string.
Now I know the InStr is working, but something else is creating the failure. Why did the debug not stop with Harry? In the DB, I have a vocalist named "Harris" as the second name in the artist string. The code ignores that when I entered Har. That is what I want to find with this routine.
Jul 25 '12 #8
Jim Yab
10
After much trial and error, it occurred to me that the solution was with my SQL statement and not using the InStr at all. For your information, this line in my SQL statement is the answer to my problem:
strSQL = strSQL & "LIKE '*" & txtSeeker.Text & "*' "
Please note the asterisks and their location. Initially, I had the one following txtSeeker.Text. Today I added the one following LIKE and the problem was history. Thank you all for taking time to work with me.
Jul 26 '12 #9

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

Similar topics

0
by: c# newbie | last post by:
For a c# program that runs Outlook interop processes. The program can be run manually. However, in scheduler, it fails. The scheduler returns a 'Last Result' status code of 0xe043f4d
0
by: Ingo Nolden | last post by:
Me too. I have the same linker error, when I compile a module in debug_dll mode. I have set up that module the way that I have both debug and release build split into the options to generate...
4
by: Chris | last post by:
I posted this in the C# language group, then thought it might be more appropriate in this group. I would not cross-post except I want the answer so badly. I built small C# Web and Web Service...
4
by: AndrewDotHay | last post by:
Periodically, we see an ASPX page fail with this appearing in the logs. Any ideas? It happens about every 3 to 4 hours, requiring a restart of the application domain to resolve it. Is this a COM...
1
by: Mary Kerrigan | last post by:
I'm tearing out my freakin' hair on this one. Trying to deploy an ASP.NET site on a Windows 2000 Advanced Server. The framework v1.0.3705 was already installed, not by me. When I tried to get to...
0
by: Simone Chiaretta | last post by:
I'm having a problem with webservices: from times to times I get the following error (incapsulated in a SOAP Exception) It seems like each time I call a webservice, something is auto-generated...
1
by: Tom | last post by:
After completing my app, I moved it to the production server. It ran ok for two days on the production server. Then, I made a change to the login process, which forced a dynamic compile(I do...
0
by: Tom | last post by:
I have a .net v2 asp.net problem. I develop on my workstation and deploy to a production server. I use compile on demand, so no pre-compile is done. When I deploy, I first must move in my new or...
5
by: mohammaditraders | last post by:
Question # 1 Write a program which consists of a class named Student, the class should consists of three data members Name, Ob_marks, Total_marks and two member functions...
1
by: ac.c.2k7 | last post by:
Hi All, While doing the cross compilation of pkg_config for directFB for MIPS target from i86 platform, i am getting the following error. "checking for extra flags to get ANSI library...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.