Link to home
Start Free TrialLog in
Avatar of tentavarious
tentavarious

asked on

convert tab keystroke to ascii value

Hello experts, I have so barcoding going on in one of my web pages.  And we want the tab keystroke to be a part of the bar code.  How can I do a conversion to make this work.  I need the ascii equivalent of a tab keystroke in vb.net.
Avatar of raterus
raterus
Flag of United States of America image

You can use the asc() function

Assuming you have a string with the tab...
Dim asciiValue as integer = asc(mytabstr)
Avatar of tentavarious
tentavarious

ASKER

Here is what I tried 009 is ascii for tab so how would i use your asc function?
The labelhold has a barcode font

  Sub getbarcodes(ByVal stringval As String, ByVal labelhold As Label, ByVal label2 As Label)
        If stringval <> "" Then
            labelhold.Text = "*" & stringval & "*" & Chr(9)
            label2.Text = stringval
        End If
    End Sub
now I'm confused, are you interested in printing the tab from "009" or taking the "009" and creating a tab?  I gave you the former.
I think i made this more complicated then need be.  I want the ascii value of a tab keystroke concatenated with a label.
 009 is ascii for tab, so if I just concatenate 009 on the end of the label I think it would work, correct?  The label has a bar code font, so our bar code scanner needs to read the ascii for tab so that it can jump to the next line.
 
 Sub getbarcodes(ByVal stringval As String, ByVal labelhold As Label, ByVal label2 As Label)
        If stringval <> "" Then
            labelhold.Text = "*" & stringval & "009" & "*"    'I am not sure if concatenating 009 will work
            label2.Text = stringval
'labelhold is the bar code label
        End If
    End Sub
ASKER CERTIFIED SOLUTION
Avatar of raterus
raterus
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
and no, concatenating 009 wouldn't have worked :-)
ok, I will run the scanner across the bar code and see if works, I will get back to you soon.
Ok, it didnt work. This inserts 5 spaces into the barcode which is not what we want. lablehold.Text = "*" & stringval & vbTab & "*"  We need the scanner to read the ascii value.  I tried this:  labelhold.Text = "*" & stringval & Asc(vbTab) & "*".  This didnt work either.
The scanner just read in 9.
vbTab will most definitely insert a tab, not 5 spaces.  I would look at what could possibly be causing it to be reformatted to 5 spaces after this code is working.
I wonder if anything like this would work
 Dim myindex As Integer
        myindex = Asc(vbTab)
        Dim myd As Char
        myd = Chr(myindex)
        If stringval <> "" Then
            labelhold.Text = "*" & stringval & myd & "*"
            label2.Text = stringval
        End If
I tried it again all of the labels used in the sub procedure have a bar code font of 3 of 9 Barcode, 40pt.

Here is my entire page code.  5 parameters are passed to the page when it is loaded.  When I use the vbtab there are 5 spaces between stringval and *.

  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        If Not Page.IsPostBack Then
            lblerror.Visible = False
             Try
                lbldate.Text = Today 'show current date
                getbarcodes(Request.QueryString("part"), lblpartbar, lblpart) 'i need to get parameter name
                getbarcodes(Request.QueryString("fm_sub"), lblsubbar, lblsub)
                getbarcodes(Request.QueryString("qty"), lblqtybar, lblqty)
                getbarcodes(Request.QueryString("to_sub"), lbltosubbar, lbltosub)
                If Not Request.QueryString("comment1") Is Nothing Then
                    lblcomment.Text = Request.QueryString("comment1")
                End If
            Catch ex As Exception
                lblerror.Text = ex.Message
                lblerror.Visible = True
            End Try
        End If
    End Sub
   
    Sub getbarcodes(ByVal stringval As String, ByVal labelhold As Label, ByVal label2 As Label)
              If stringval <> "" Then
            labelhold.Text = "*" & stringval & vbTab & "*"
            label2.Text = stringval
        End If
    End Sub
End Class
you're running this tabbed string through a label control, and who knows what that's going to do to it.

If you need a literal tab printed in the HTML, use an <asp:literal ... > control (Just tested it, a tab was printed in the HTML, a label control messed it up)
When I do something like this and step through the code the value of myindex looks like this: "      "
 Dim myindex As String
        myindex = vbTab
Ok, how do i set font properties for the literal control
I think we're getting a little off subject from the original question here,

you don't set fonts or any other formatting on the literal control as the literal control is one of the most basic controls there is.  It simply outputs the "Text" property to the HTML, no formatting is ever done.

if you want to set the font, you need to write the correct HTML to do what you want in the text property
Ok, well i am trying something like this in my code behind I gotta work with the syntax but I should get it working.
 literalval.Text = "style='FONT-WEIGHT: normal; FONT-SIZE: 40pt; FONT-FAMILY: '3 of 9 Barcode''& " * " & stringval & vbTab & " * ""
         
Well, i am trying to get this literal control to work and I got the font working, but I cant see to get the vbtab working correctly.

    labelhold.Text = "<font style='FONT-WEIGHT: normal; FONT-SIZE: 40pt; FONT-FAMILY: 3 of 9 Barcode'> vbTab </font>"
            label2.Text = stringval
Ok, this is what I got I am using a literal control and there is still a space in the bar code

 Sub getbarcodes(ByVal stringval As String, ByVal labelhold As Literal, ByVal label2 As Label)
        If stringval <> "" Then
            labelhold.Text = "<font style='FONT-WEIGHT: normal; FONT-SIZE: 40pt; FONT-FAMILY: 3 of 9 Barcode'>*" & stringval & "" & vbTab & "*</font>"
            label2.Text = stringval
        End If
    End Sub