sql problem

N

nokia3650

i have an update querry that should pull number out of a string.the strings
are standardized(same). i thought it would be good to pull out the start
position of the nummber and the end position of the number.

here is the code for start position:

Public Function isPocetakBroja(ByVal IngFactor As String) As Long

Dim pocetakBroja, krajBroja, drugipocetakBroja As Long
'assumes that the FactorSum value is a number, and is a Long Integer.
Select Case Left(IngFactor, 8)
Case Is = "dov. zal"
pocetakBroja = InStr(10, IngFactor, "dana (", vbTextCompare) + 6
drugipocetakBroja = InStr(10, IngFactor, "dana (>", vbTextCompare) + 7
If drugipocetakBroja > pocetakBroja Then
isPocetakBroja = Right(Left(IngFactor, krajBroja), drugipocetakBroja)
Else
isPocetakBroja = Right(Left(IngFactor, krajBroja), pocetakBroja)
End If
Case Is = "dovoljno"
pocetakBroja = InStr(5, IngFactor, "no (", vbTextCompare) + 4
drugipocetakBroja = InStr(5, IngFactor, "no (>", vbTextCompare) + 5
If drugipocetakBroja > pocetakBroja Then
isPocetakBroja = Right(Left(IngFactor, krajBroja), drugipocetakBroja)
Else
isPocetakBroja = Right(Left(IngFactor, krajBroja), pocetakBroja)
'...here is type mismatch
End If
Case Is = "sti¾e da"
isPocetakBroja = 5
Case Else 'use this if you need a default for records outside of all
isPocetakBroja = 999
End Select

End Function

the strings look like:

dovoljno (4 kom), poslije vi¹e ne.
sti¾e za 14 dana
dovoljno (11 kom)
dovoljno (>100 kom)

but i get a erron saying :
run time error 13

type mismatch

in line 20

where is the problem

how to solve it?

thx
 
J

John Nurick

Your code is much less difficult to read if you indent it properly.
Other comments below refer to the lines marked with <<<<

Public Function isPocetakBroja(ByVal IngFactor As String) As Long
Dim pocetakBroja, krajBroja, drugipocetakBroja As Long '<<<<1
'assumes that the FactorSum value is a number, and is a Long Integer.

Select Case Left(IngFactor, 8)
Case Is = "dov. zal"
pocetakBroja = InStr(10, IngFactor, "dana (", vbTextCompare) + 6
drugipocetakBroja = InStr(10, IngFactor, _
"dana (>", vbTextCompare) + 7
If drugipocetakBroja > pocetakBroja Then
isPocetakBroja = Right(Left(IngFactor, krajBroja), _
drugipocetakBroja) '<<<<2
Else
isPocetakBroja = Right(Left(IngFactor, krajBroja), pocetakBroja)
End If
Case Is = "dovoljno"
pocetakBroja = InStr(5, IngFactor, "no (", vbTextCompare) + 4
drugipocetakBroja = InStr(5, IngFactor, _
"no (>", vbTextCompare) + 5
If drugipocetakBroja > pocetakBroja Then
isPocetakBroja = Right(Left(IngFactor, krajBroja), _
drugipocetakBroja)
Else
isPocetakBroja = Right(Left(IngFactor, krajBroja), pocetakBroja)
'...here is type mismatch
End If
Case Is = "sti¾e da"
isPocetakBroja = 5
Case Else 'use this if you need a default for records outside of all
isPocetakBroja = 999
End Select
End Function


1) This line
Dim pocetakBroja, krajBroja, drugipocetakBroja As Long
declares pocetakBroja and krajBroja as Variants and only
drugipocetakBroja as a Long, which is probably not what you intend.

2) In this line and several others, the assignment to isPocetakBroja
requires a Long but you are are using Right(), which is a
string-handling function. So the first thing to do is exclude the
possibility that the "Right(Left())" expression is returning a string
that does not represent a number. When the code breaks, click Debug,
open the Immediate pane, type
? Right(Left(IngFactor, krajBroja), pocetakBroja)
and hit Enter. If the result is not a valid number, either your code
isn't quite right or your data isn't quite as you expect.
 
Y

yong362

nokia3650 said:
i have an update querry that should pull number out of a string.the strings
are standardized(same). i thought it would be good to pull out the start
position of the nummber and the end position of the number.

here is the code for start position:

Public Function isPocetakBroja(ByVal IngFactor As String) As Long

Dim pocetakBroja, krajBroja, drugipocetakBroja As Long
'assumes that the FactorSum value is a number, and is a Long Integer.
Select Case Left(IngFactor, 8)
Case Is = "dov. zal"
pocetakBroja = InStr(10, IngFactor, "dana (", vbTextCompare) + 6
drugipocetakBroja = InStr(10, IngFactor, "dana (>", vbTextCompare) + 7
If drugipocetakBroja > pocetakBroja Then
isPocetakBroja = Right(Left(IngFactor, krajBroja), drugipocetakBroja)
Else
isPocetakBroja = Right(Left(IngFactor, krajBroja), pocetakBroja)
End If
Case Is = "dovoljno"
pocetakBroja = InStr(5, IngFactor, "no (", vbTextCompare) + 4
drugipocetakBroja = InStr(5, IngFactor, "no (>", vbTextCompare) + 5
If drugipocetakBroja > pocetakBroja Then
isPocetakBroja = Right(Left(IngFactor, krajBroja), drugipocetakBroja)
Else
isPocetakBroja = Right(Left(IngFactor, krajBroja), pocetakBroja)
'...here is type mismatch
End If
Case Is = "sti¾e da"
isPocetakBroja = 5
Case Else 'use this if you need a default for records outside of all
isPocetakBroja = 999
End Select

End Function

the strings look like:

dovoljno (4 kom), poslije vi¹e ne.
sti¾e za 14 dana
dovoljno (11 kom)
dovoljno (>100 kom)

but i get a erron saying :
run time error 13

type mismatch

in line 20

where is the problem

how to solve it?

thx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top