ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help with code please (https://www.excelbanter.com/excel-programming/413848-help-code-please.html)

Greg B[_13_]

Help with code please
 
I am having trouble with a piece of code, the code works with smaller
numbers but when I scan a barcode it does not recognise the number? What
have I got wrong here is the code below.
Private Sub UserForm_Activate()

TextBox1.Value = InputBox("PLEASE SCAN THE ITEM")


End Sub

Private Sub TextBox1_Change()

Dim CHECK1
Sheet5.Activate
On Error Resume Next
CHECK1 = Application.Match(CLng(TextBox1.Value), Range("A:A"), 0)
If Not IsError(CHECK1) Then
Label1.Caption = Application.Index(Range("B:B"), CHECK1)
End If
On Error GoTo 0

End Sub





Tom Ogilvy

Help with code please
 
What is a typical barcode number that is causing problems. What error
message are you getting?

--
Regards,
Tom Ogilvy


"Greg B" wrote:

I am having trouble with a piece of code, the code works with smaller
numbers but when I scan a barcode it does not recognise the number? What
have I got wrong here is the code below.
Private Sub UserForm_Activate()

TextBox1.Value = InputBox("PLEASE SCAN THE ITEM")


End Sub

Private Sub TextBox1_Change()

Dim CHECK1
Sheet5.Activate
On Error Resume Next
CHECK1 = Application.Match(CLng(TextBox1.Value), Range("A:A"), 0)
If Not IsError(CHECK1) Then
Label1.Caption = Application.Index(Range("B:B"), CHECK1)
End If
On Error GoTo 0

End Sub






Greg B[_13_]

Help with code please
 
this is the example barcode scanned 9310072020280 the code works with
smaller numbers it does not seem to recognise the 9310072020280

There is no error code as such just the caption does not change with the
larger number.

"Tom Ogilvy" wrote in message
...
What is a typical barcode number that is causing problems. What error
message are you getting?

--
Regards,
Tom Ogilvy


"Greg B" wrote:

I am having trouble with a piece of code, the code works with smaller
numbers but when I scan a barcode it does not recognise the number? What
have I got wrong here is the code below.
Private Sub UserForm_Activate()

TextBox1.Value = InputBox("PLEASE SCAN THE ITEM")


End Sub

Private Sub TextBox1_Change()

Dim CHECK1
Sheet5.Activate
On Error Resume Next
CHECK1 = Application.Match(CLng(TextBox1.Value), Range("A:A"), 0)
If Not IsError(CHECK1) Then
Label1.Caption = Application.Index(Range("B:B"), CHECK1)
End If
On Error GoTo 0

End Sub








Tom Ogilvy

Help with code please
 
Gregg,
From Help on the LONG data type:

Long (long integer) variables are stored as signed 32-bit (4-byte) numbers
ranging in value from -2,147,483,648 to 2,147,483,647. The type-declaration
character for Long is the ampersand (&).


9,310,072,020,280

is outside this range. Try converting the number to a double (cdbl) since
numbers in the excel sheet are stored as double anyway.

Demo'd from the immediate window:

? cdbl("9310072020280")
9310072020280

--
Regards,
Tom Ogilvy





"Greg B" wrote:

this is the example barcode scanned 9310072020280 the code works with
smaller numbers it does not seem to recognise the 9310072020280

There is no error code as such just the caption does not change with the
larger number.

"Tom Ogilvy" wrote in message
...
What is a typical barcode number that is causing problems. What error
message are you getting?

--
Regards,
Tom Ogilvy


"Greg B" wrote:

I am having trouble with a piece of code, the code works with smaller
numbers but when I scan a barcode it does not recognise the number? What
have I got wrong here is the code below.
Private Sub UserForm_Activate()

TextBox1.Value = InputBox("PLEASE SCAN THE ITEM")


End Sub

Private Sub TextBox1_Change()

Dim CHECK1
Sheet5.Activate
On Error Resume Next
CHECK1 = Application.Match(CLng(TextBox1.Value), Range("A:A"), 0)
If Not IsError(CHECK1) Then
Label1.Caption = Application.Index(Range("B:B"), CHECK1)
End If
On Error GoTo 0

End Sub









Rick Rothstein \(MVP - VB\)[_2287_]

Help with code please
 
Just to follow up on Tom's reply to you...

The reason you don't see anything is because the number is outside the range
of a Long, your assignment is generating an error, but your On Error Resume
Next statement is hiding that from you. Comment out that statement and you
should be able to see the error.

Rick


"Tom Ogilvy" wrote in message
...
Gregg,
From Help on the LONG data type:

Long (long integer) variables are stored as signed 32-bit (4-byte) numbers
ranging in value from -2,147,483,648 to 2,147,483,647. The
type-declaration
character for Long is the ampersand (&).


9,310,072,020,280

is outside this range. Try converting the number to a double (cdbl) since
numbers in the excel sheet are stored as double anyway.

Demo'd from the immediate window:

? cdbl("9310072020280")
9310072020280

--
Regards,
Tom Ogilvy





"Greg B" wrote:

this is the example barcode scanned 9310072020280 the code works with
smaller numbers it does not seem to recognise the 9310072020280

There is no error code as such just the caption does not change with the
larger number.

"Tom Ogilvy" wrote in message
...
What is a typical barcode number that is causing problems. What error
message are you getting?

--
Regards,
Tom Ogilvy


"Greg B" wrote:

I am having trouble with a piece of code, the code works with smaller
numbers but when I scan a barcode it does not recognise the number?
What
have I got wrong here is the code below.
Private Sub UserForm_Activate()

TextBox1.Value = InputBox("PLEASE SCAN THE ITEM")


End Sub

Private Sub TextBox1_Change()

Dim CHECK1
Sheet5.Activate
On Error Resume Next
CHECK1 = Application.Match(CLng(TextBox1.Value), Range("A:A"), 0)
If Not IsError(CHECK1) Then
Label1.Caption = Application.Index(Range("B:B"), CHECK1)
End If
On Error GoTo 0

End Sub











All times are GMT +1. The time now is 10:53 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com