Results 1 to 17 of 17

Thread: Need help with strings

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2005
    Posts
    122

    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

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Need help with strings

    Try:
    VB Code:
    1. Text1.Text = inst
    How is inst declared by the way?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2005
    Posts
    122

    Re: Need help with strings

    I didnt initialize inst i just used it as instring$. Even changing to text1.text didnt help

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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!)

  5. #5
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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..

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Mar 2005
    Posts
    122

    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:
    1. Private Sub Timer1_Timer()
    2.     If MSComm1.PortOpen = False Then ' If comm port is not open
    3.        MSComm1.PortOpen = True ' Open it
    4.     End If
    5.      
    6.     If MSComm1.InBufferCount > 0 Then ' If theres data in comm buffer
    7.         inst = inst + MSComm1.Input ' Get the data
    8.         Text1 = inst ' Show its value
    9.     End If
    10. 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:
    1. Private Sub CommandButton1_Click()
    2. If MSComm1.PortOpen = False Then ' If comm port is not open
    3. MSComm1.PortOpen = True ' Open it
    4. CommandButton1.Caption = "Close Port" 'Modify the caption of the button
    5. Else
    6. MSComm1.PortOpen = False 'If the port is open then close it
    7. CommandButton1.Caption = "Open Port" 'Again modify the caption.
    8. End If
    9. End Sub
    10.  
    11. Private Sub MScomm1_OnComm()
    12. Dim inst As String
    13. If MSComm1.InBufferCount > 0 Then ' If theres data in comm buffer
    14. inst = inst + MSComm1.Input ' Get the data
    15. TextBox1.SetFocus
    16. TextBox1.Value = inst ' Show its value
    17. End If
    18. 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

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Need help with strings

    What is an HMI VBA IDE?

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Mar 2005
    Posts
    122

    Re: Need help with strings

    its an automation machine interface development environment which uses VBA.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Mar 2005
    Posts
    122

    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

  10. #10
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: Need help with strings

    For starters, you could ditch the Variable and do:
    VB Code:
    1. Private Sub MScomm1_OnComm()
    2.     If MSComm1.InBufferCount > 0 Then ' If theres data in comm buffer
    3.         TextBox1.SetFocus
    4.         TextBox1.Value = TextBox1.Value & MSComm1.Input ' Get the data
    5.     End If
    6. 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:
    1. Private Sub MScomm1_OnComm()
    2.     If MSComm1.InBufferCount > 0 Then ' If theres data in comm buffer
    3.        
    4.         'Debug Line
    5.         Me.Caption = MSComm1.Input
    6.         '
    7.         TextBox1.SetFocus        
    8.         TextBox1.Value = TextBox1.Value & MSComm1.Input ' Get the data
    9.     End If
    10. End Sub

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Mar 2005
    Posts
    122

    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

  12. #12

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Mar 2005
    Posts
    122

    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.

  14. #14
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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:
    1. TextBox1.Text= MSComm1.Input ' Get the data

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Mar 2005
    Posts
    122

    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

  16. #16

  17. #17
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: Need help with strings

    Try:
    VB Code:
    1. 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
  •  



Click Here to Expand Forum to Full Width