|
-
Nov 9th, 2005, 12:23 PM
#1
Thread Starter
Lively Member
Need help with strings
Hi all ,
Iam trying to get info from the scanner into a textbox. when i scan a numerical value it displays it but when it is associated with AB12345678 it displays only 78. How can i display the whole string. Iam using this code:
If MSComm1.InBufferCount > 0 Then ' If theres data in comm buffer
inst = inst + MSComm1.Input ' Get the data
TextBox1.SetFocus
TextBox1.Value = inst ' Show its value
End If
need ur inputs on this.
thanks
-
Nov 9th, 2005, 12:25 PM
#2
Re: Need help with strings
Try:How is inst declared by the way?
-
Nov 9th, 2005, 12:29 PM
#3
Thread Starter
Lively Member
Re: Need help with strings
I didnt initialize inst i just used it as instring$. Even changing to text1.text didnt help
-
Nov 9th, 2005, 12:35 PM
#4
Re: Need help with strings
You should always always declare your variables before using them. Always!
Try doing a Dim inst As String and see what happens.
(PS: Always!)
-
Nov 9th, 2005, 12:42 PM
#5
Re: Need help with strings
When you do inst = inst + MSComm1.Input are you trying to add up the values or are you trying to concatenate them? If you are trying to do the latter than you should always use & and not + particularly if you neglect to Dim your variables..
-
Nov 9th, 2005, 01:39 PM
#6
Thread Starter
Lively Member
Re: Need help with strings
Hi all,
i code i wrote in Vb6 works fine where i used a timer control and the code is as follows.
VB Code:
Private Sub Timer1_Timer()
If MSComm1.PortOpen = False Then ' If comm port is not open
MSComm1.PortOpen = True ' Open it
End If
If MSComm1.InBufferCount > 0 Then ' If theres data in comm buffer
inst = inst + MSComm1.Input ' Get the data
Text1 = inst ' Show its value
End If
End Sub
Now iam using the same without using timer control as iam using one of the HMI VBA IDE. The foloowing is the code
VB Code:
Private Sub CommandButton1_Click()
If MSComm1.PortOpen = False Then ' If comm port is not open
MSComm1.PortOpen = True ' Open it
CommandButton1.Caption = "Close Port" 'Modify the caption of the button
Else
MSComm1.PortOpen = False 'If the port is open then close it
CommandButton1.Caption = "Open Port" 'Again modify the caption.
End If
End Sub
Private Sub MScomm1_OnComm()
Dim inst As String
If MSComm1.InBufferCount > 0 Then ' If theres data in comm buffer
inst = inst + MSComm1.Input ' Get the data
TextBox1.SetFocus
TextBox1.Value = inst ' Show its value
End If
End Sub
but still have the same problem when scanning data which got alphabets. need ur thoughts
Edit: Added [vbcode][/vbcode] tags for more clarity. - Hack
-
Nov 9th, 2005, 01:42 PM
#7
Re: Need help with strings
What is an HMI VBA IDE?
-
Nov 9th, 2005, 01:57 PM
#8
Thread Starter
Lively Member
Re: Need help with strings
its an automation machine interface development environment which uses VBA.
-
Nov 9th, 2005, 07:11 PM
#9
Thread Starter
Lively Member
Re: Need help with strings
While running using breakpoint at If MSComm1.InBufferCount > 0 i can see it shows its count value as 10 when scanned at AB12345678, and continue pressing F5 it displays the whole string as AB12345678. But under normal operating conditions it only displays characters 7 and 8 instead of the whole string value. Need ur inputs.
thanks
-
Nov 9th, 2005, 07:23 PM
#10
Re: Need help with strings
For starters, you could ditch the Variable and do:
VB Code:
Private Sub MScomm1_OnComm()
If MSComm1.InBufferCount > 0 Then ' If theres data in comm buffer
TextBox1.SetFocus
TextBox1.Value = TextBox1.Value & MSComm1.Input ' Get the data
End If
End Sub
And listen to what Martin said about joing Strings (and use &)
Note niether of the above may solve your problem....
And, to test the Com value add:
VB Code:
Private Sub MScomm1_OnComm()
If MSComm1.InBufferCount > 0 Then ' If theres data in comm buffer
'Debug Line
Me.Caption = MSComm1.Input
'
TextBox1.SetFocus
TextBox1.Value = TextBox1.Value & MSComm1.Input ' Get the data
End If
End Sub
-
Nov 10th, 2005, 12:20 PM
#11
Thread Starter
Lively Member
Re: Need help with strings
I tried your code it worked but when scanned another barcode its adding to the previously scanned barcode. How can I display one barcode info at a time.
For example :given two barcodes ABCD and 1234 it should display it seperately, but it adds it as ABCD1234
need ur inputs
-
Nov 10th, 2005, 12:25 PM
#12
Re: Need help with strings
Set the MultiLine property of the Textbox to True and then do
VB Code:
TextBox1.Value = TextBox1.Value & vbCrLf & MSComm1.Input ' Get the data
-
Nov 10th, 2005, 12:30 PM
#13
Thread Starter
Lively Member
Re: Need help with strings
I looking to display one barcode info at a time when scanned and replace the previous value in the textbox when scanned a different barcode.
-
Nov 10th, 2005, 12:41 PM
#14
Re: Need help with strings
Wait a second. What's this TextBox1.Value? There's no such property!
Anyhow if you just want to see the most recent barcode then do
VB Code:
TextBox1.Text= MSComm1.Input ' Get the data
-
Nov 10th, 2005, 12:48 PM
#15
Thread Starter
Lively Member
Re: Need help with strings
Iam programming in VBA, if I change the way you told me , it display like the one in my reply#9.
need ur inputs on this
-
Nov 10th, 2005, 12:52 PM
#16
Re: Need help with strings
OK, I moved the thread to the proper forum.
-
Nov 10th, 2005, 03:51 PM
#17
Re: Need help with strings
Try:
VB Code:
TextBox1.Value = Replace(MSComm1.Input, Chr(0), "") 'Remove any Null characters
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|