Need help with Query in VB

Need help with Query in VB

Post by doug westervel » Thu, 21 Nov 1996 04:00:00



I'm trying to query a table using the following criteria:

A string "Big Mac $1.95" needs to match a record "Big Mac"

Theoretically, I'd like to chop everything to the right of the blank
space before the $ sign on the string and then match it with the db
lookup.  However, to my knowledge, VB doesn't have a good Chop
function.  Perhaps I could feed the string into a character array or
something?

I also tried kludging something using Like, but was unsucessful.  But,
then again, I'm not a VB pro.

Any ideas?

Thanks in advance,

doug

 
 
 

Need help with Query in VB

Post by MARCH » Mon, 25 Nov 1996 04:00:00




>I'm trying to query a table using the following criteria:

>A string "Big Mac $1.95" needs to match a record "Big Mac"

>Theoretically, I'd like to chop everything to the right of the blank
>space before the $ sign on the string and then match it with the db
>lookup.  However, to my knowledge, VB doesn't have a good Chop
>function.  Perhaps I could feed the string into a character array or
>something?

>I also tried kludging something using Like, but was unsucessful.  But,
>then again, I'm not a VB pro.

>Any ideas?

>Thanks in advance,

>doug


Doug, there is an SQL operator LIKE, which is a perfect solution to
your problems. The query

SELECT * FROM sometable WHERE somefield LIKE 'Big Mac%'

will return you all Big Macs in your database with their respective
prices.
NOTE: The above query is SQL Server specific. In Access you would use
"*" instead of "%".

 
 
 

Need help with Query in VB

Post by Simon Carte » Wed, 27 Nov 1996 04:00:00


Try the following function

Function ChopBefore(ToChop) As String
On Error GoTo ChopBeforeErr
If InStr(1, ToChop, " $") > 1 Then
    ChopBefore = Left$(ToChop, InStr(1, ToChop, " $") - 1)
Else
    ChopBefore = ToChop 'No Space and Dollar so return entire string
End If

ChopBeforeEP: 'Exit Point
Exit Function

ChopBeforeErr: 'Error Handler
ChopBefore = ToChop
GoTo ChopBeforeEP
End Function

Hope it helps

Simon Carter

Author of SC4VB
http://www.geocities.com/siliconvalley/park/8079/



> I'm trying to query a table using the following criteria:

> A string "Big Mac $1.95" needs to match a record "Big Mac"

> Theoretically, I'd like to chop everything to the right of the blank
> space before the $ sign on the string and then match it with the db
> lookup.  However, to my knowledge, VB doesn't have a good Chop
> function.  Perhaps I could feed the string into a character array or
> something?

> I also tried kludging something using Like, but was unsucessful.  But,
> then again, I'm not a VB pro.

> Any ideas?

> Thanks in advance,

> doug


 
 
 

Need help with Query in VB

Post by Nick Mali » Thu, 28 Nov 1996 04:00:00




Quote:> I'm trying to query a table using the following criteria:

> A string "Big Mac $1.95" needs to match a record "Big Mac"

> Theoretically, I'd like to chop everything to the right of the blank
> space before the $ sign on the string and then match it with the db
> lookup.  

You can use the SQL Like operator, or you can parse the string.  VB has
fairly good string handling capabilities.

Dim sMystring as String
Dim sMatchstring as String
Dim iloc as integer

sMystring = "Big Mac $1.95"
iloc = Instr(sMystring,"$")   ' get the location of the '$' sign
if iloc > 1 then
   sMatchstring = left$(sMystring, iloc-1)
else
    sMatchstring = sMystring
end if
Debug.print sMatchstring    ' will print Big Mac

Hope this helps,
--- Nick Malik
VB MVP
www.malikinfo.com

 
 
 

1. HELP NEEDED - ACCESS / VB - CROSS QUERY

I try to make a query similar than the one I have in Access.

In my database, I have data like the following :

REF    WEEK    QUANTITY
001    01            100
001    02            150
002    01            200
002    02            50

I want to put figures in a new table like this :

REF    WEEK01       WEEK02
001    100                150
002    200                50

I know how to do with Access, but I can't find the way to do it with VB.

I have looked for for weeks, but nothing.

Thank you for your help
Regards,

Dom W.
France

2. HELP for newbie

3. Need help executing a sql query in VB 5.0

4. Words to numbers code

5. Need Help with Update Query VB 6/SQL 7

6. Oracle Education Classes!!!

7. I need help with Union query in VB

8. Help With: AtiveX, ODBC and IIS4 and VB5

9. Need Help speeding up Foxpro file queries in VB

10. Query Access through VB - newbie needs help

11. Need Help passing Parameters to SQL query in a VB dataenviroment

12. Complex WebSite/Win CGI/VB/MS Access Query Help Needed

13. Attention Query Gurus...Help needed with a db query