I have been trying to call the function left(string,n) in a small evb program but keep getting an error message when running the program which states that 'object is not a collection.' If I remove the parsing part of the code the string is returned okay. I have applied the code the same way as I did in visual basic and the help page indicates that the left function is available in EVB so what am I doing wrong. Can anybody help?
Originally posted by birdseye I have been trying to call the function left(string,n) in a small evb program but keep getting an error message when running the program which states that 'object is not a collection.' If I remove the parsing part of the code the string is returned okay. I have applied the code the same way as I did in visual basic and the help page indicates that the left function is available in EVB so what am I doing wrong. Can anybody help?
If you could post some of the relevant code I'll see what I can do. :)
Has nothing to do with your code... it's a problem with Microsoft's code. There is a well known bug in eVB where the left function will ONLY work in a module and not a form. You have two solutions:
Use the MID function instead of left.
-or-
Create a public function in a module call MyLeft and just wrap the left function.
Here is the knowledge base article explaining the issue:
On a form I have put a text box , 2 command buttons and 2 labels.
On running the code below, label2 will correctly show the contents of Text1 after clicking on command1, but on clicking on command2 the error Report
‘an error was encountered when running this program object is not a collection’ is shown
Private Sub Command1_Click()
Dim ml
ml=Cstr(text1)
Label2 = ml
End Sub
Private Sub Command2_Click()
Dim mls
ml=Cstr(text1)
Label3 = Left(ml,3)
End Sub
OMG, your answer is above in my previous post! As I said, this is a KNOWN issue. It's been known for a loooong time and the solution is to NOT use LEFT and to use MID instead. LEFT conflicts with the LEFT of a forms property, although LEFT is fine in a module.
Here is your code fixed:
Code:
Private Sub Command2_Click()
Dim mls
mls = Cstr(text1)
Label3 = Mid(mls, 1, 3)
End Sub
__________________
Ohayden,
Axim X30
Pocket PC Software:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
I am calling the funciton below. When I use it I get an error about using the 'Mid' function. This code should run just fine. I have tried it in both a form and a module.
Public Function ChkQty(vQty As String) As Boolean
Dim X As Long
Dim sQty As String
'validate a numeric value
For X = 0 To Len(vQty) - 1
sQty = Mid(vQty, X, 1)
If Asc(vQty) >= 48 And Asc(vQty) <= 57 Then
'no alpha characters
Else
MsgBox "QTY can contain numeric values only!", vbInformation, "Remote Invoice"
ChkQty = False
Exit Function
End If
I can tell you come from a "C" background ;). eVB is not zero based and strings (TCHARS) are one based. In your "for loop" you're starting at zero, you need to start at one as follows:
I optimized your function for you plus fixed a bug. You set sQty but used vQty instead :).
Code:
Public Function ChkQty(vQty As String) As Boolean
Dim X As Long
Dim sQty As String
'validate a numeric value
ChkQty = True ' DEFAULT TO TRUE
For X = 1 To Len(vQty)
sQty = Mid(vQty, X, 1)
If Asc(sQty) < 48 Or Asc(sQty) > 57 Then
MsgBox "QTY can contain numeric values only!", vbInformation, "Remote Invoice"
ChkQty = False
Exit For
End If
Next X
End Function
Regards,
__________________
Ohayden,
Axim X30
Pocket PC Software:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Can someone tell me why this recordset won't open:
Rs.Source = "SELECT InvoiceNo, CustCode, CusName FROM Invoices WHERE Void = 0 ORDER BY InvoiceNo ASC"
Rs.CursorType = adOpenForwardOnly
Rs.ActiveConnection = oConnection
Rs.Open
AND this one will:
Rs.Source = "SELECT InvoiceNo, CustCode, CusName FROM Invoices ORDER BY InvoiceNo ASC"
Rs.CursorType = adOpenForwardOnly
Rs.ActiveConnection = oConnection
Rs.Open
The difference is the Where clause VOID = 0
Void is a Yes/No field.